Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2009-03

Find out local IP adress

6 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Rainer Stratmann

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.

Jonas Maebe
to Rainer Stratmann
Rainer Stratmann wrote
May 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

Rainer Stratmann
to Jonas Maebe
Jonas Maebe wrote 7 lines
On 22 Mar 2009, at 20:21, Rainer Stratmann wrote: > May 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?

The IP adress of the network card(s).

Show quoted text 5 lines
Jonas _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
David W Noon
to Rainer Stratmann
Rainer Stratmann wrote 10 lines
Am Sonntag, 22. März 2009 20:24 schrieb Jonas Maebe: > On 22 Mar 2009, at 20:21, Rainer Stratmann wrote: > > May 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? 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.

Regards, Dave [RLU #314465] ======================================================================= (David W Noon) =======================================================================
Ralf A. Quint
to David W Noon
David W Noon wrote 15 lines
On Sun, 2009-03-22 at 20:36 +0100, Rainer Stratmann wrote: > Am Sonntag, 22. März 2009 20:24 schrieb Jonas Maebe: > > On 22 Mar 2009, at 20:21, Rainer Stratmann wrote: > > > May 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? > > The IP adress of the network card(s). Since the machine can have several NICs, you first need to decide which one.

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

Travis Siegel
to Rainer Stratmann: 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.

Rainer Stratmann wrote 11 lines
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. _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal