[fpc-pascal] RE: Get Local IP using glib (eth0,eth1)

Marco van de Voort marcov at stack.nl
Fri Oct 6 16:33:35 CEST 2006


> > Better, but still Linux only. For a good solution,
> > a resolver unit that accesses libc should be
> > written that is portable (unlike the libc unit)
> 
> If I understood correctly, the OP had two questions:
> 
> 1. Retrieve a list of interface names on a *linux* system.
> 2. Return the IP address for a given *linux* interface name.

I don't understand that last one. _WHY_ would you want to enumerate and then
still use hardcoded "eth0" What if eth0 is my internal and eth1 my external
interface? The only meaning of the name is order of detection.
 
> And the only "good" solution is a portable resolver unit?
> 
> How will you resolve "eth0" on Win32 or BSD ?

Usually you enumerate the interfaces list, till you find the interface with
the "default" (ANY) route, so you have the default gateway, regardless of
name. That is usually the interface you interested in.

IOW names say nothing, routes and masks do.



More information about the fpc-pascal mailing list