SNMP Manager Programmer's Guide
Programming Examples
SNMP Manager Programmer’s Guide–134249
2-78
SNMPSET
name = valstr[i];
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(stdout, "Invalid IP address %s\n", valstr[i]);
fprintf(stdout, "while binding the VT_IPADDRESS\n");
exit(0);
}
name = ptr + 1;
} /* of while */
/* if IP address contains invalid no. of dots exit */
if ( dots < 3)
{
fprintf(stdout, "Invalid IP address %s\n", valstr[i]);
fprintf(stdout, "while binding the VT_IPADDRESS\n");
exit(0);
}
ipaddr = inet_addr(valstr[i]);
if (ipaddr == INVALID_HOST_ADDR)
{
fprintf(stdout, "Invalid IP address %s\n", valstr[i]);
fprintf(stdout, "while binding the VT_IPADDRESS\n");
exit(0);
}
} else
{
if ((host3 = gethostbyname(valstr[i])) == (struct hostent *) 0)
{
fprintf(stdout, "Can not locate host %s\n", valstr[i]);
fprintf(stdout, "while binding the VT_IPADDRESS\n");
exit(0);
}
ipaddr = *(u_long *)(host3->h_addr);
}
Example 2-9. Contents of snmpsetc (page 7 of 9)