how to get the local ip ?
i don't want to call the ifconfig and the parse the result.
what API's are available ?
Do you mean that you want to write a C-program?
If so study the Berkley-socket.
--
Hilsen/Regards
Michael Rasmussen
http://keyserver.veridis.com:11371/pks/lookup?op=get&search=0xE3E80917
Start with: man gethostbyname
--
remove MYSHOES to email
You will have to define "local ip" first. Any given host might
have 20 "local ip" addresses.
Generally you either know the hostname, and want the IP address
associated with that particular name, or you want the IP address
associated with a particular interface (such as eth0, ppp0,
wlan0, etc.).
>i don't want to call the ifconfig and the parse the result.
>
>what API's are available ?
What are you writing? A shell script is one thing and a C
program is another...
--
Floyd L. Davidson <http://www.apaflo.com/floyd_davidson>
Ukpeagvik (Barrow, Alaska) fl...@apaflo.com
I am programming gcc (m68k-elf-gcc) , my uclinux device has no dns support
so i wonder if gethostbyname will work.
maybe i have to get it by getting it from eth0 , but i don'nt know how.
I was used to program win32 before ,so this is all new to me .
If it was me looking for how to find the info, I'd look at the source for
ifconfig, and see where it gets the info. Or maybe faster, do an
strace ifconfig -a
and see what system calls it uses.
http://www.daimi.au.dk/~kasperd/comp.os.linux.development.faq.html#IP
--
Kasper Dupont
Note to self: Don't try to allocate
256000 pages with GFP_KERNEL on x86.
There may well be several local IP addresses.
> i don't want to call the ifconfig and the parse the result.
>
> what API's are available ?
You can do it the same way ifconfig does:
1. Create a socket for the address family you're interested in
(typically AF_INET, for IPv4 addresses)
2. Use ioctl(sock, SIOCGIFCONF, ...) to find the names of the
interfaces
3. Use ioctl(sock, SIOCGIFADDR, ...) to find the IP address for each
interface
You will probably want to filter out e.g. the loopback interface, in
which case use the SIOCGIFHWADDR ioctl to find out the hardware type
(sa_family) of the interface.
Look at the socket(2) and netdevice(7) manual pages for a full
description of these APIs.
--
Ben Hutchings
Klipstein's 4th Law of Prototyping and Production:
A fail-safe circuit will destroy others.