Monta Vista 2.1: retrive MAC and IP address

Oct 17, 2003 1 Replies

Hello Everyone


I am working on Monta Vista 2.1 and writing a application in C code that needs the IP and MAC address of the embedded system. I cannot hardcode this since each system where my application will run might/will have different MAC and IP address.



So my question is if there is anyway for me to in a fast and easy way retrive the MAC and IP from a 2.4.17 Linux kernel and store the result in a string/variable for usage in my C program?



Any hints and tips are welcome.



Regards Andreas


Hi Andreas,

I haven't explicitly played with the Monta Vista system before, but for the standard linux kernel, you should be able to do an ioctl() to retrieve both.

the ioctrl for the mac address is struct ifreq ifr ioctl(name, SIOCGIFHWADDR, &ifr) and for the IP ioctl(name, SIOCGIFADDR, &ifr) then look in the ifr structure.

should set you in the right direction.

regards

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Damion de Soto - Software Engineer email: damion@snapgear.com SnapGear --- ph: +61 7 3435 2809 | Custom Embedded Solutions fax: +61 7 3891 3630 | and Security Appliances web: http://www.snapgear.com~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --- Free Embedded Linux Distro at http://www.snapgear.org ---

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required