For Windows there ist gethostbyname.
But for Linux I am searching for this function.
The unit inet is not on the distribution I have (knoppix) And libc also does the compiler not know.
May be there exists another way to find out the local IP adress.

Mailing lists / fpc-pascal / 2009-03
6 messages · 5 people · –
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
For Windows there ist gethostbyname.
But for Linux I am searching for this function.
The unit inet is not on the distribution I have (knoppix) And libc also does the compiler not know.
May be there exists another way to find out the local IP adress.
Rainer Stratmann wroteMay be there exists another way to find out the local IP adress.
"The" local ip address does not exist. A system can have multiple network cards, there can be vpn tunnels, NAT gateways to other networks and virtual machines, ... Which of these local addresses are you interested in?
Jonas
The IP adress of the network card(s).
Since the machine can have several NICs, you first need to decide which one. If your machine has only one, then this is easy.
There is an ioctl for querying the IP address of a given Ethernet interface, for which you need to open a socket. It is SIOCGIFADDR. See: man 2 ioctl_list
If you want some C++ code to perform this, I can send you some via private email. It's up to you to translate it to Pascal.
I would say that would be pretty easy as well,
use the NIC which has the default gateway (the one with the lowest metric)...
Ralf
For Windows there ist gethostbyname. But for Linux I am searching for this function. The…
You could always exec ifconfig, then parce the output for the interfaces, and pull the ips from there.
I do this on OSX with a simple terminal script like this: ifconfig|grep broadcast|awk '{print $2}';
This could easily be made to work on linux/bsd/fpc with very little work.
Hope this helps.