SNMP Manager Programmer's Guide
Programming Examples
SNMP Manager Programmer’s Guide–134249
2-100
SNMPTRAP
hostname = *argv++; argc--;
for (i = 0; argc > 0; i++) <--5
{
if (i == MAXOIDS)
{
fprintf(stderr, "Exceeded %d object identifiers\n", MAXOIDS);
exit(0);
}
if ((longform && argc < 3) || argc < 2)
{
fprintf(stderr, usage, whoami);
exit(0);
}
oidstr[i] = *argv++; argc--;
if (longform)
{
typestr[i] = *argv++; argc--;
}
valstr[i] = *argv++; argc--;
} /* for loop */
oidcnt = i;
dest.sin_family = AF_INET; <--6
dest.sin_port = htons(dest_port);
if (isdigit(*hostname))
{
/*
* error checking of IP address value
* and error checking on inet_addr()
*/
name = hostname;
dots = 0;
while ((ptr = strchr(name, '.')) != NULL)
{
dots++; /* keep track of no. of dots */
memset(id, NULL, 20);
strncpy(id, name, ptr - name);
byte = atoi(id);
if ( byte < 0 || byte > 255)
{
fprintf(stderr, "Invalid target host identifier %s\n", hostname);
exit(0);
}
Example 2-13. Contents of snmptrpc (page 4 of 10)