lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Tue, Jul 22, 2014 at 12:01:00PM -0400, Sean Conner wrote:
> It was thus said that the Great William Ahern once stated:
> > On Tue, Jul 22, 2014 at 01:52:13AM -0400, Sean Conner wrote:
> > > 
> > > [1]	The first instance is to enumerate all the network interfaces under
> > > 	Linux:
> > > 
> > > 	https://github.com/spc476/lua-conmanorg/blob/56f11f8c0b5bc35e2cfbf5c003d447a362325b2c/src/net.c#L358
> > 
> > Kinda off-topic, but I noticed your source code comment says that getifaddrs
> > is "Linux-only". getifaddrs was original to BSDi. Linux adopted it. It's
> > supported by not only all the modern BSDs, but also Solaris 11 and even QNX.
> > It should be trivial to emulate on other systems, like AIX.
> 
>   It's marked "Linux only" because of the three systems I have easy access
> to, Linux, Solaris (5.10, so is that Solaris 10?) and Mac OS-X, it's only
> Linux that I found the actual function.
> 

FWIW, I've added getifaddrs bindings to my Lua Unix module.

http://25thandclement.com/~william/projects/lunix.html

There's an ifconfig lookalike program in examples/getifaddrs.lua.

I did extensive research, including downloading the original KAME IPv6
network project to understand the relevant ioctls.

The unix module now supports getifaddrs on all supported platforms,
including Linux, Solaris, OS X, OpenBSD, NetBSD, FreeBSD, and AIX.

Most platforms include a native version already. But I've included embedded
implementations for Solaris 10 and AIX, which lack a native getifaddrs. And
I tested my emulated versions (I wrote four different implementations: two
KAME-based which work on most BSDs, one for Solaris, one for AIX) on all
platforms to check for bugs.

I don't have a copy of Solaris 10, so I had to test the emulated version on
Solaris 11. Bug reports appreciated.

Output of the example script:

$ uname -a
AIX aix7 1 7 000ACFDE4C00
$ lua ./getifaddrs.lua
en0: flags=1577601123<UP,BROADCAST,NOTRAILERS,RUNNING,SIMPLEX,16384,MULTICAST>
        inet 192.168.10.80 broadcast 192.168.10.255
en0: flags=1577601123<UP,BROADCAST,NOTRAILERS,RUNNING,SIMPLEX,16384,MULTICAST>
        inet6 2001:470:dce3::80 prefixlen 64
en0: flags=1577601123<UP,BROADCAST,NOTRAILERS,RUNNING,SIMPLEX,16384,MULTICAST>
        inet6 fe80::209:6bff:fe2e:b12a prefixlen 64
sit0: flags=135266369<UP,RUNNING>
        inet6 ::192.168.10.80 prefixlen 96
lo0: flags=235407435<UP,BROADCAST,LOOPBACK,RUNNING,SIMPLEX,MULTICAST>
        inet 127.0.0.1 broadcast 127.255.255.255
lo0: flags=235407435<UP,BROADCAST,LOOPBACK,RUNNING,SIMPLEX,MULTICAST>
        inet6 ::1 prefixlen 128