1 #include <net-snmp/net-snmp-config.h>
15 #include <sys/types.h>
19 #include <netinet/in.h>
23 #include <net-snmp/config_api.h>
24 #include <net-snmp/output_api.h>
25 #include <net-snmp/mib_api.h>
26 #include <net-snmp/utilities.h>
30 oid trap[MAX_OID_LEN];
32 struct traphandle *next;
35 struct traphandle *traphandlers = 0;
36 struct traphandle *defaulthandler = 0;
39 * handles parsing .conf lines of:
46 snmptrapd_get_traphandler(oid * name, size_t namelen)
48 struct traphandle **ttmp;
49 DEBUGMSGTL(("snmptrapd:traphandler", "looking for trap handler for "));
50 DEBUGMSGOID(("snmptrapd:traphandler", name, namelen));
51 DEBUGMSG(("snmptrapd:traphandler", "...\n"));
52 for (ttmp = &traphandlers;
54 && snmp_oid_compare((*ttmp)->trap, (*ttmp)->traplen, name,
55 namelen); ttmp = &((*ttmp)->next));
58 DEBUGMSGTL(("snmptrapd:traphandler",
59 " None found, Using the default handler.\n"));
60 return defaulthandler->exec;
62 DEBUGMSGTL(("snmptrapd:traphandler", " Didn't find one.\n"));
65 DEBUGMSGTL(("snmptrapd:traphandler", " Found it!\n"));
70 snmptrapd_traphandle(const char *token, char *line)
72 struct traphandle **ttmp;
78 * find the current one, if it exists
80 if (strncmp(line, "default", 7) == 0) {
81 ttmp = &defaulthandler;
84 for (ttmp = &traphandlers; *ttmp != NULL; ttmp = &((*ttmp)->next));
89 * it doesn't, so allocate a new one.
91 *ttmp = (struct traphandle *) malloc(sizeof(struct traphandle));
93 config_perror("malloc failed");
96 memset(*ttmp, 0, sizeof(struct traphandle));
101 cptr = copy_nword(line, buf, sizeof(buf));
103 (*ttmp)->traplen = MAX_OID_LEN;
104 if (!read_objid(buf, (*ttmp)->trap, &((*ttmp)->traplen))) {
105 char buf1[STRINGMAX];
106 snprintf(buf1, sizeof(buf1),
107 "Bad trap OID in traphandle directive: %s", buf);
108 buf1[ sizeof(buf1)-1 ] = 0;
114 (*ttmp)->exec = strdup(cptr);
115 DEBUGMSGTL(("read_config:traphandler", "registered handler for: "));
117 DEBUGMSG(("read_config:traphandler", "default"));
119 DEBUGMSGOID(("read_config:traphandler", (*ttmp)->trap,
122 DEBUGMSG(("read_config:traphandler", "\n"));