From: see@... (Douglas Wells) Date: 2007-07-19T05:10:02+09:00 Subject: Re: Listing all IP addresses on an multihomed system In article <1184772029.010310.165980@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 (at http://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. > Is there a pure Ruby solution? Is it just a matter of > Socket.getaddrinfo(Socket.gethostname, 80)? Or, does anyone happen to > know the C solution? I'm fairly certain that this could be done in ruby via IO.ioctl and pack/unpack on UNIX/Linux, but I'm also fairly certain that this would be a real PITA. I don't have any familiarity with the Win32-specific solutions. > Dan Good luck, - dmw Notes: - DNS = Domain Name System - The ioctl commands evolve over time and over various systems. The ones I note there may well be deprecated, obsolete, and/or non-existent on your system. -- . Douglas Wells . Connection Technologies . . Internet: -sp9804- -at - contek.com- .