SNMP Manager Programmer's Guide
Programming Examples
SNMP Manager Programmer’s Guide–134249
2-105
SNMPTRAP
    name = ptr + 1;
    } /* of while */
    /* if IP address contains invalid no. of dots exit */
    if ( dots < 3)
    {
    fprintf(stderr, "Invalid IP address %s\n", valstr[i]);
    exit(0);
    }
    ipaddr = inet_addr(valstr[i]);
    if (ipaddr == INVALID_HOST_ADDR)
    {
    fprintf(stderr, "Invalid IP address %s\n", valstr[i]);
    exit(0);
    }
   }
   else
   {
    if ((host = gethostbyname(valstr[i])) == (struct hostent *)0)
    {
     fprintf(stderr, "Can not locate host %s\n", valstr[i]);
     exit(0);
    }
    ipaddr = *(u_long *)(host->h_addr);
   }
   rcode = SNMP_Bind_IP_Address(send_pkt, i,
       base_oid.num_components, base_oid.component_list,
       (OCTET_T *)&ipaddr);
   break;
   case VT_OBJECT:
   if (oidstr_to_oid(valstr[i], &val_oid) < 0)
   {
    fprintf(stderr, "Bad object identifier: %s\n", valstr[i]);
    exit(0);
   }
   rcode = SNMP_Bind_Object_ID(send_pkt, i,
       base_oid.num_components,
       base_oid.component_list,
       val_oid.num_components,
       val_oid.component_list);
   break;
Example 2-13. Contents of snmptrpc (page 9 of 10)










