You either need to run a dhcp client on your device(like dhclient or udhcpcd) or implement your own DHCP client in your software.
You either need to run a dhcp client on your device(like dhclient or udhcpcd) or implement your own DHCP client in your software.
You're going to have to explain what you mean by "get IP address".
Again, what do you mean by "get IP address"?
The following function will "get IP address":
char *foo(void) { return "129.168.32.98"; }
Unless you you can tell us what IP address you want to get, that's as good a solution as any.
-- Grant Edwards grant.b.edwards Yow! The entire CHINESE at WOMEN'S VOLLEYBALL TEAM all
Hi Miloserdin.
There are a few options to get your address. You can use popen("ifconfig eth0"...) and parse the output. Or you can use an SIOCGIFADDR ioctl on a socket (google SIOCGIFADDR for the details).
Steve
You can try to set up a socket and use getsockname() - I've done that with Python, so I guess the C code can use the same principle.
I'm interesting how to get IP address from C application. I've used gethostname() and gethostbyname() in my application. I've edited /etc/hosts file to add board's hostname and IP address. My board is connected to server which using DHCP. If I remove added lines from /etc/hosts gethostbyname() function returns error. How can I get IP address from my application without using /etc/hosts editing?
-- Best regards, Miloserdin Oleg
ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.