+
+
+#ifdef _WIN32
+typedef BOOL(WINAPI * pSnmpExtensionInit) (
+ IN DWORD dwTimeZeroReference,
+ OUT HANDLE * hPollForTrapEvent,
+ OUT AsnObjectIdentifier * supportedView);
+
+typedef BOOL(WINAPI * pSnmpExtensionTrap) (
+ OUT AsnObjectIdentifier * enterprise,
+ OUT AsnInteger * genericTrap,
+ OUT AsnInteger * specificTrap,
+ OUT AsnTimeticks * timeStamp,
+ OUT RFC1157VarBindList * variableBindings);
+
+typedef BOOL(WINAPI * pSnmpExtensionQuery) (
+ IN BYTE requestType,
+ IN OUT RFC1157VarBindList * variableBindings,
+ OUT AsnInteger * errorStatus,
+ OUT AsnInteger * errorIndex);
+
+typedef BOOL(WINAPI * pSnmpExtensionInitEx) (
+ OUT AsnObjectIdentifier * supportedView);
+#endif //_WIN32
+
+
+long GetMacAddrSys ( unsigned char *addr)
+{
+#ifdef _WIN32
+ WSADATA WinsockData;
+ if (WSAStartup(MAKEWORD(2, 0), &WinsockData) != 0)
+ {
+ std::cerr << "This program requires Winsock 2.x!" << std::endl;
+ return -1;
+ }
+
+ HANDLE PollForTrapEvent;
+ AsnObjectIdentifier SupportedView;
+ UINT OID_ifEntryType[] = { 1, 3, 6, 1, 2, 1, 2, 2, 1, 3 };
+ UINT OID_ifEntryNum[] = { 1, 3, 6, 1, 2, 1, 2, 1 };
+ UINT OID_ipMACEntAddr[] = { 1, 3, 6, 1, 2, 1, 2, 2, 1, 6 };
+ AsnObjectIdentifier MIB_ifMACEntAddr = {
+ sizeof(OID_ipMACEntAddr) / sizeof(UINT), OID_ipMACEntAddr };
+ AsnObjectIdentifier MIB_ifEntryType = {
+ sizeof(OID_ifEntryType) / sizeof(UINT), OID_ifEntryType };
+ AsnObjectIdentifier MIB_ifEntryNum = {
+ sizeof(OID_ifEntryNum) / sizeof(UINT), OID_ifEntryNum };
+ RFC1157VarBindList varBindList;
+ RFC1157VarBind varBind[2];
+ AsnInteger errorStatus;
+ AsnInteger errorIndex;
+ AsnObjectIdentifier MIB_NULL = { 0, 0 };
+ int ret;
+ int dtmp;
+ int i = 0, j = 0;
+ BOOL found = FALSE;
+
+ // Load the SNMP dll and get the addresses of the functions necessary
+ HINSTANCE m_hInst = LoadLibrary("inetmib1.dll");
+ if (m_hInst < (HINSTANCE) HINSTANCE_ERROR)
+ {
+ m_hInst = NULL;
+ return -1;
+ }
+ pSnmpExtensionInit m_Init =
+ (pSnmpExtensionInit) GetProcAddress(m_hInst, "SnmpExtensionInit");
+ pSnmpExtensionInitEx m_InitEx =
+ (pSnmpExtensionInitEx) GetProcAddress(m_hInst, "SnmpExtensionInitEx");
+ pSnmpExtensionQuery m_Query =
+ (pSnmpExtensionQuery) GetProcAddress(m_hInst, "SnmpExtensionQuery");
+ pSnmpExtensionTrap m_Trap =
+ (pSnmpExtensionTrap) GetProcAddress(m_hInst, "SnmpExtensionTrap");
+ m_Init(GetTickCount(), &PollForTrapEvent, &SupportedView);
+
+ /* Initialize the variable list to be retrieved by m_Query */
+ varBindList.list = varBind;
+ varBind[0].name = MIB_NULL;
+ varBind[1].name = MIB_NULL;
+
+ // 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;