[Winpcap-users] Retireving MAC Address

Gianluca Varenni gianluca.varenni at cacetech.com
Thu Jan 5 17:09:43 GMT 2006


Hi Alessandro.

Maybe PacketGetAdapterNames is failing because the buffer is not big enough. 
Have you looked at the value returned into nameSize?

Out of curiosity, why are you still using WinPcap 3.0, and the Packet API 
(which we suggest *not* to use, because subject to change between different 
versions), instead of the pcap one?

Have a nice day
GV

----- Original Message ----- 
From: "Alessandro Baldisserri" <bujia at libero.it>
To: "WinPCap MailingList" <winpcap-users at winpcap.org>
Sent: Tuesday, January 03, 2006 6:36 AM
Subject: [Winpcap-users] Retireving MAC Address


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


_______________________________________________
Winpcap-users mailing list
Winpcap-users at winpcap.org
https://www.winpcap.org/mailman/listinfo/winpcap-users



More information about the Winpcap-users mailing list