From: Daniel Berger Date: 2007-07-19T07:16:02+09:00 Subject: Re: Listing all IP addresses on an multihomed system On Jul 18, 2:10 pm, s...@signature.invalid (Douglas Wells) wrote: > In article <1184772029.010310.165...@j4g2000prf.googlegroups.com>, > Daniel Berger writes: > > > I'm wondering if there's a way to list all IP addresses on a > > multihomed system using Ruby's Socket API. I actually want this for > > the sys-host library (athttp://www.rubyforge.org/projects/sysutils). > > It's C, but I figure I can reverse engineer the Ruby code back to C. > > > [ extraneous program based on gethostbyname elided] > > > But, at least one user has reported that he has eth0 configured with a > > LAN IP and eth1 that has 5 attached IP addresses. The above code > > doesn't pick them up. > > As your user has reported, your C-based program does not do what > you desire. gethostbyname (and its friends) can only deal with > DNS-based information. Information about multi-hosting is not > stored in the DNS. In fact, it is actually system dependent and is > only stored in the local kernel's network tables. > > Most UNIX and Linux systems provide a mechanism to access this > information via some variant of the ioctl(2) call with command > SIOCGIFCONF. BSDi and FreeBSD have a set of subroutines (originally > based on the ioctl) called getifaddrs. MS Windows WinSock2 uses > the command SIO_GET_INTERFACE_LIST with the WSAIoctl procedure. > You will need to look in the documentation for your system (and > probably do a net search for programming examples) to see how it > works. Indeed, there's an example in Stevens' "Unix Network Programming, Vol. 1" staring at me now. :) Many thanks for the lead. I should be ok from here (I hope). I'll see if I can come up with a pure Ruby solution and post it here eventually. Regards, Dan