Showing posts with label eth0. Show all posts
Showing posts with label eth0. Show all posts

Wednesday, January 10, 2007

interface list from OS

Ignorant as I am, I, for my life, could not determine how to get the interface list and their mask, address, MTU, etc from the operating system (from a C program).

So the first thought was obvious, to use PCAP. So I did. using pcap_findalldevs, combined with pcap_lookupnet would yield me all the interface names and the network portion of the local iIP address and broadcast address. Of course I spent good amount of time to figure that out.

So I went back to google code search to find an alternative. And I saw libnet. Seemd way too much work than what I wanted to do. And using system("ifconfig -a | grep *!)$!:!@"); was really not an option.

Finally I decided, enough was enough. And I downloaded ethereal source code. I wassure I have seen interface name, address, mac address etc on ethereal. So a little grepping "grep interface *" gave me the result I was looking for, it pointed to me that it was possible to get this info from the system from an IOCTL. DUH! I didn't know that. :(

So web search on "struct ifreq" got me to this little gem . Ofcrouse, from there on it wasnt that difficult to figure it all out. Even I could do that. Oh and considering how I always get stuck at displaying the sockaddr_in from the ifreq in human format, I found this nice package that showed me how to do it.
 printf( "addr [%s]\n",
inet_ntoa( ( (struct sockaddr_in *) &ifr->ifr_addr
)->sin_addr );

And finally, I attach the source that I managed to write using the techniques from the web.


cheers!

Wednesday, December 13, 2006

eth0 has different MAC address than expected, ignoring.

So following my previous post where I got kernel 2.6.9 finally running on my desktop, I had problem with eth interface.

Error said "eth0 has different MAC address than expected, ignoring."
So google search gave me some things that I treid and failed. One thing that worked was a nice link on how to spoof your mac address.
http://whoozoo.co.uk/mac-spoof-linux.htm

In summary:
1. set bootproto=none
2. ifconfig down eth0 (if it isnt already down)
3. ifconfig eth0 hw ether 11:22:33:11:22:22 (your choosen mac address)
4. service network restart
5. now you can go back and set the bootproto to dhcp
(Although step 1 and 5 don't make sense. I dont want to go back and narrow it all down right now. Have some deadlines to meet and so needed this pc running with 2.6.9 asap. Will update later, hopefilly :))