pellegre / libcrafter

A high level C++ network packet sniffing and crafting library.
298 stars 88 forks source link

Please provide ability to get MAC address of interface without IP address assigned #33

Closed pavel-odintsov closed 9 years ago

pavel-odintsov commented 9 years ago

Hello!

Please give me chance to thank you for awesome library! It's very useful and reliable :)

I suggest you to add ability to get intarface's MAC address without ARP protocol directly from ifconfig.

Current implementation:

#include <crafter.h>
#include <iostream>

int main(int argc, char* argv[]) {
    Crafter::InitCrafter();

    std::cout<<"Interface's MAC: '"<<Crafter::GetMAC("eth6")<<"'"<<std::endl;    return 0;
}

Can't read MAC if interface haven't assigned IP address:

g++  getmac.cpp -I/opt/crafter/include -l/opt/crafter/lib/libcrafter.so -ocrafter_getmac
ifconfig eth6
eth6      Link encap:Ethernet  HWaddr 90:e2:ba:4a:d8:e8  
          inet6 addr: fe80::92e2:baff:fe4a:d8e8/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:5 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:398 (398.0 B)
          Memory:fa380000-fa400000 

./crafter_getmac 
Interface's MAC: ''

Btw, in my case I could not use ARP too because I'm implementing network stack on top of netmap interface and I haven't ARP. But MAC address is very important for Crafter library and will be fine if it will be implemented in library itself without external dependencies.

oliviertilmans commented 9 years ago

Hello, That feature already exists, and is called

/* Get interface hardware address */
std::string GetMyMAC(const std::string& iface = "");

(see libcrafter/crafter/Utils/CrafterUtils.h) On the contrary, GetMac takes 2 parameter, an ip address and (optionally) an interface on which to perform an ARP request.