[Winpcap-users] Retireving MAC Address

Alessandro Baldisserri bujia at libero.it
Tue Jan 3 14:36:49 GMT 2006


Hi!

I'm using winpcap version 3.0.0.18
I want to retrieve MAC Address from my net adapter. I use this code:

    PPACKET_OID_DATA pOidData;
    LPADAPTER lpAdapter=NULL;
    CHAR *pStr;
    CHAR *adName = new CHAR[1024];
    PTSTR adNameptstr = (PTSTR)adName; 
    ULONG nameSize = 1024;
    BOOLEAN res;
    pStr = new CHAR[sizeof(PACKET_OID_DATA)+128];
    ZeroMemory(pStr, sizeof(PACKET_OID_DATA)+128);
    pOidData = (PPACKET_OID_DATA) pStr;
    pOidData->Oid = OID_802_3_CURRENT_ADDRESS;
    pOidData->Length = 6;
	res = PacketGetAdapterNames(adNameptstr,&nameSize);
	if (res==0) {
// -----------------> MY ERROR IS THIS!!!!
		printf("ERROR in PacketGetAdapterNames\n");
		goto ip;
	}
	lpAdapter = PacketOpenAdapter(adNameptstr);
	if (lpAdapter==NULL) {
		printf("ERROR in PacketOpenAdapter\n");
		goto ip;
	}
    res = PacketRequest(lpAdapter, FALSE, pOidData);
	if (res==0) {
		printf("ERROR in PacketRequest\n");
		goto ip;
	}
	// In pOidData->Data[0...5] è contenuto il MAC ADDRESS
	sprintf(host_mac_address,"%02X:%02X:%02X:%02X:%02X:%02X",
		pOidData->Data[0],
		pOidData->Data[1],
		pOidData->Data[2],
		pOidData->Data[3],
		pOidData->Data[4],
		pOidData->Data[5]);


With this code I have an error in PacketGetAdapterName.
Is this code wrong?
Anyone can help me?
Thanks in advance!
Alex




More information about the Winpcap-users mailing list