+ // Copy in the OID to find the number of entries in the
+ // Inteface table
+ varBindList.len = 1; // Only retrieving one item
+ SNMP_oidcpy(&varBind[0].name, &MIB_ifEntryNum);
+ ret = m_Query(ASN_RFC1157_GETNEXTREQUEST, &varBindList, &errorStatus,
+ &errorIndex);
+// printf("# of adapters in this system : %i\n",
+// varBind[0].value.asnValue.number); varBindList.len = 2;
+
+ // Copy in the OID of ifType, the type of interface
+ SNMP_oidcpy(&varBind[0].name, &MIB_ifEntryType);
+
+ // Copy in the OID of ifPhysAddress, the address
+ SNMP_oidcpy(&varBind[1].name, &MIB_ifMACEntAddr);
+
+ do
+ {
+ // Submit the query. Responses will be loaded into varBindList.
+ // We can expect this call to succeed a # of times corresponding
+ // to the # of adapters reported to be in the system
+ ret = m_Query(ASN_RFC1157_GETNEXTREQUEST, &varBindList, &errorStatus,
+ &errorIndex);
+ if (!ret)
+ {
+ ret = 1;
+ }
+ else
+ {
+ // Confirm that the proper type has been returned
+ ret = SNMP_oidncmp(&varBind[0].name, &MIB_ifEntryType,
+ MIB_ifEntryType.idLength);
+ }
+ if (!ret)
+ {
+ j++;
+ dtmp = varBind[0].value.asnValue.number;
+ printf("Interface #%i type : %i\n", j, dtmp);
+
+ // Type 6 describes ethernet interfaces
+ if (dtmp == 6)
+ {
+ // Confirm that we have an address here
+ ret = SNMP_oidncmp(&varBind[1].name, &MIB_ifMACEntAddr,
+ MIB_ifMACEntAddr.idLength);
+ if ( !ret && varBind[1].value.asnValue.address.stream != NULL )
+ {
+ if ( (varBind[1].value.asnValue.address.stream[0] == 0x44)
+ && (varBind[1].value.asnValue.address.stream[1] == 0x45)
+ && (varBind[1].value.asnValue.address.stream[2] == 0x53)
+ && (varBind[1].value.asnValue.address.stream[3] == 0x54)
+ && (varBind[1].value.asnValue.address.stream[4] == 0x00) )
+ {
+ // Ignore all dial-up networking adapters
+ printf("Interface #%i is a DUN adapter\n", j);
+ continue;
+ }
+ if ( (varBind[1].value.asnValue.address.stream[0] == 0x00)
+ && (varBind[1].value.asnValue.address.stream[1] == 0x00)
+ && (varBind[1].value.asnValue.address.stream[2] == 0x00)
+ && (varBind[1].value.asnValue.address.stream[3] == 0x00)
+ && (varBind[1].value.asnValue.address.stream[4] == 0x00)
+ && (varBind[1].value.asnValue.address.stream[5] == 0x00) )
+ {
+ // Ignore NULL addresses returned by other network
+ // interfaces
+ printf("Interface #%i is a NULL address\n", j);
+ continue;
+ }
+ memcpy( addr, varBind[1].value.asnValue.address.stream, 6);
+ }
+ }
+ }
+ } while (!ret);
+
+ // Free the bindings
+ SNMP_FreeVarBind(&varBind[0]);
+ SNMP_FreeVarBind(&varBind[1]);
+ return 0;
+#endif //Win32 version
+
+
+// implementation for POSIX system
+#ifdef __sun
+ //The POSIX version is broken anyway on Solaris, plus would require full
+ //root power
+ int i;
+ struct arpreq parpreq;
+ struct sockaddr_in sa, *psa;
+ struct in_addr inaddr;
+ struct hostent *phost;
+ char hostname[MAXHOSTNAMELEN];
+ unsigned char *ptr;
+ char **paddrs;
+ int sock, status=0;
+
+ gethostname(hostname, MAXHOSTNAMELEN);
+ phost = gethostbyname(hostname);
+ paddrs = phost->h_addr_list;
+
+ //memcpy(&inaddr.s_addr, *paddrs, sizeof(inaddr.s_addr));
+ sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
+
+ if(sock == -1)
+ {
+ perror("sock");
+ return -1;
+ }
+ memset(&parpreq, 0, sizeof(struct arpreq));
+ psa = (struct sockaddr_in *) &parpreq.arp_pa;
+ memset(psa, 0, sizeof(struct sockaddr_in));
+ psa->sin_family = AF_INET;
+ memcpy(&psa->sin_addr, *paddrs, sizeof(struct in_addr));