I have an index for the network interface I got a packet from (i.e. 2), and need to find the name of interface, which should return "eth0"
. I'm using if_indextoname()
.
I'm not much familiar with C++ on Ubuntu, but my code drops an error:
cannot convert
char**
tochar*
for argument 2 tochar* if_indextoname(unsigned int, char*)
Can someone help me to fix it?
#include <net/if.h>
#include <iostream>
int main()
{
unsigned int ifindex = 2;
char *ifname[10];
std::cout << if_indextoname(ifindex, ifname);
std::cout << ifname << std::endl;
}