[Winpcap-users] How to get local MAC address ?

MARMONIER Cédric cmarmonier at ifotec.com
Mon Sep 12 06:59:50 PDT 2011

Thanks but there is a probleme.
GetAdaptersAddresses() don't give me the same adapter list that pcap_findalldevs()

If I have :
IP_ADAPTER_INFO *adapter_Iphlpapi = NULL;
pcap_if_t *adapter_WinPCAP = NULL;
adapter_Iphlpapi = getMyAdapter(); // use the GetAdaptersAddresses function to select an adapter

=> How can I do to set the good adapter in the adapter_WinPCAP variable ?

Is there a method which can operate with Windows Xp (and Windows 7 if possible) and Linux ?

-----Message d'origine-----
De : winpcap-users-bounces at winpcap.org [mailto:winpcap-users-bounces at winpcap.org] De la part de Wentao Shang
Envoyé : lundi 12 septembre 2011 11:27
À : winpcap-users at winpcap.org
Objet : Re: [Winpcap-users] How to get local MAC address ?

David is correct.

GetAdaptersInfo is obsolete since Windows XP and people should use
GetAdaptersAddresses now.

The field 'PhysicalAddress' and 'PhysicalAddressLength' in the
'IP_ADAPTER_ADDRESSES' struct correspond to the MAC address of the
device. The 'PhysicalAddressLength' value should equal to 6 for
Ethernet adapters.

See http://msdn.microsoft.com/en-us/library/aa366058(v=VS.85).aspx for
more info.:)



2011/9/12 "Fish" (David B. Trout) <fish at infidels.org>:
> Mark Pizzolato wrote:
>> Fish wrote:
>> >
>> > http://msdn.microsoft.com/en-us/library/aa365915(v=vs.85).aspx
>> >
>> That reference shows how to determine IP addresses not MAC addresses.
> Incorrect.
> It shows how to retrieve a linked list of 'IP_ADAPTER_ADDRESSES' structures,
> one field of which happens to be the hardware address. It most certainly is
> not ONLY for determining protocol addresses.
> The old "GetAdaptersInfo" API is what you previously had to use, which
> returned 'IP_ADAPTER_INFO' structures. But it only returned information for
> adapters which has an IPv4 IP address associated with them, and not any with
> IPv6 addresses assigned.:
> http://msdn.microsoft.com/en-us/library/aa365917(VS.85).aspx
> http://msdn.microsoft.com/en-us/library/aa366062(v=VS.85).aspx
> The "GetAdaptersAddresses" API was designed to replace the "GetAdaptersInfo"
> API. It returns MUCH MORE information than GetAdaptersInfo ever did, and it
> does so for ALL adapters, *regardless* of whether or not an IPv4 and/or IPv6
> protocol address is assigned to it.
> You're wrong.
> The "GetAdaptersAddresses" API most certainly *is* the correct API to use
> and is the correct answer.
> --
> "Fish"(David B. Trout)
> fish at softdevlabs.com
> _______________________________________________
> Winpcap-users mailing list
> Winpcap-users at winpcap.org
> https://www.winpcap.org/mailman/listinfo/winpcap-users

Wentao Shang

Master Candidate and Research Assistant at CERNET Center & EE
Department, Tsinghua University,

Email: wentaoshang at gmail.com, mundou at qq.com,

Mobile: +86-13466605118, +86-18952150939,
Winpcap-users mailing list
Winpcap-users at winpcap.org

More information about the Winpcap-users mailing list