
Hello, How to get the MAC address of an ethernet interface, using the boost C++ library? Thanks, Jean

Hello Jean, You could do this using a standard ioctl call to your ethernet driver from the user space, AFAIK you perhaps do not need boost to get the mac address. Cheers /Ramesh On Fri, Aug 22, 2008 at 9:48 AM, Jean-Sebastien Stoezel < js.stoezel@gmail.com> wrote:
Hello,
How to get the MAC address of an ethernet interface, using the boost C++ library?
Thanks, Jean _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Hi, Thanks for your quick answer. I am running Windows XP so I am not sure I have access to ioctl... I would like to provide a solution that is OS independent, this is why I would like to use Boost... Does boost provide an interface to get the MAC address? Thanks, Jean On 8/22/08, Ramesh <rramesh1@gmail.com> wrote:
Hello Jean,
You could do this using a standard ioctl call to your ethernet driver from the user space, AFAIK you perhaps do not need boost to get the mac address.
Cheers /Ramesh
On Fri, Aug 22, 2008 at 9:48 AM, Jean-Sebastien Stoezel <js.stoezel@gmail.com> wrote:
Hello,
How to get the MAC address of an ethernet interface, using the boost C++ library?
Thanks, Jean _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

I doubt if boost has one such generic API, you can try ACE, but I doubt that too - best way is to have your own. Just that you might have to search a bit of NDIS & MSDN documentation. Cheers /R On Fri, Aug 22, 2008 at 10:01 AM, Jean-Sebastien Stoezel < js.stoezel@gmail.com> wrote:
Hi,
Thanks for your quick answer. I am running Windows XP so I am not sure I have access to ioctl... I would like to provide a solution that is OS independent, this is why I would like to use Boost... Does boost provide an interface to get the MAC address?
Thanks, Jean
On 8/22/08, Ramesh <rramesh1@gmail.com> wrote:
Hello Jean,
You could do this using a standard ioctl call to your ethernet driver from the user space, AFAIK you perhaps do not need boost to get the mac address.
Cheers /Ramesh
On Fri, Aug 22, 2008 at 9:48 AM, Jean-Sebastien Stoezel <js.stoezel@gmail.com> wrote:
Hello,
How to get the MAC address of an ethernet interface, using the boost C++ library?
Thanks, Jean _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Jean-Sebastien Stoezel schrieb:
Hello,
How to get the MAC address of an ethernet interface, using the boost C++ library?
Well it's not implemented in boost. I can show you an example how to get it on linux and windows (I had to get it for a library I am working on). However that's just the rough way, I'm not in need to get it for a specific interface, but with this you'll find the needed info faster ;) Linux: #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <net/if.h> #include <netpacket/packet.h> #include <ifaddrs.h> ifaddrs * ifap = 0; if(getifaddrs(&ifap) == 0) { ifaddrs * iter = ifap; while(iter) { sockaddr_ll * sal = reinterpret_cast<sockaddr_ll*>(iter->ifa_addr); if(sal->sll_family == AF_PACKET) { // get the mac bytes // copy(sal->sll_addr, // sal->sll_addr+sal->sll_hallen, // buffer); } iter = iter->ifa_next; } freeifaddrs(ifap); } Windows: #include <winsock2.h> #include <iphlpapi.h> std::vector<boost::uint8_t> buf; DWORD bufLen = 0; GetAdaptersAddresses(0, 0, 0, 0, &bufLen); if(bufLen) { buf.resize(bufLen, 0); IP_ADAPTER_ADDRESSES * ptr = reinterpret_cast<IP_ADAPTER_ADDRESSES*>(&buf[0]); DWORD err = GetAdaptersAddresses(0, 0, 0, ptr, &bufLen); if(err == NO_ERROR) { while(ptr) { if(ptr->PhysicalAddressLength) { // get the mac bytes // copy(ptr->PhysicalAddress, // ptr->PhysicalAddress+ptr->PhysicalAddressLength, // buffer); } ptr = ptr->Next; } } } Regards, Vinzenz
participants (3)
-
Jean-Sebastien Stoezel
-
Ramesh
-
Vinzenz Feenstra