Currently I've been getting the list of ALL mac address and ip address that acn be found on my host machine. These include the VM's network info as well. I'm using the third option in Khalid Shaikh's 3rd option in codeguru. However, it returns me the whole list of mac addresses and ip addresses seen. Is there a way where I can get the ip address used only? A sample scenario would be what IP address and mac address I'm using when I'm pinging a server. The only way I can think of is trace route but I dont know how to do it in c++. Any help will do. thanks!
Asked
Active
Viewed 789 times
1 Answers
0
Actually anyone of the returned interfaces could be the interface you can use. So, you are going to use one interface for sending to certain destination addresses and for other destination addresses you are going to use other interface.
Then you need to read the routing table to determine the interface your datagrams are actually sent from depending on the destination address.
For doing this I would go in one of the following directions:
- Obtain routes from iptables: from what it is said here there is no programatic API but you can use shell commands
Obtain route table with Routing sockets
int sockfd = socket(AF_ROUTE, SOCK_RAW, 0);
Obtain route table with Netlink sockets
Once you obtain the routing table you need to interpret the routes and find out which interface your outgoing datagrams will use for the Internet or for other IP addresses.