SNMP Manager Programmer's Guide

Programming Examples
SNMP Manager Programmer’s Guide–134249
2-98
SNMPTRAP
char usage[] = "Usage: %s [-l] [-n] [-c community] [-e enterprise] "
"[-a managerhost] [-g generictrap] [-s specifictrap] [-t timestamp]"
" [-p port] host [name [type] value] ...\n";
int
main (int argc, char ** argv)
{
SNMP_PKT_T *send_pkt;
EBUFFER_T ebuff;
int rcode, sd;
struct sockaddr_in dest, from;
int szfrom, i, oidcnt, longform = 0;
struct hostent *host;
u_long host_addr, ipaddr;
int dest_port = SNMP_TRAP_PORT; <--2
struct namerec *p;
char opt, *whoami, *hostname, *community="public";
char *oidstr[MAXOIDS], *typestr[MAXOIDS], *valstr[MAXOIDS];
int mibtype = 0;
int asn1type = 0;
char *entstr = 0, *agentstr, *genstr="0", localhost[80];
int generic = 0, specific = 0;
unsigned int timestamp = 0;
int nStatus;
int dots; /* to keep track of dots in IP address */
int byte; /* to hold the octet of IP address */
char *name;
char *ptr;
char id[20]; /* to hold part of IP address */
agentstr = localhost; <--3
gethostname(agentstr, sizeof(localhost));
whoami= *argv++;
argc--;
while ((argc != 0) && (**argv == '-'))
{
opt = *(*argv + 1);
argv++,argc--;
if (argc == 0) /* reject incomplete command */
break;
switch (opt) <--4
Example 2-13. Contents of snmptrpc (page 2 of 10)