Works here. I tested the snippet below on 2 different interfaces (eth0, eth1) and the correct ip was reported each time.
Thanks, Thomas Krause -----Ursprüngliche Nachricht----- Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Im Auftrag von Andrea Righi Gesendet: Sonntag, 20. April 2008 13:11 An: [email protected] Betreff: Re: [sisuite-users] PATCH: si_installbtimage cannot get interface address on localized debian versions Thomas Krause wrote: > The best thing (tm) IME would be to not rely on the ifconfig output at > all and find some other way to obtain the ip address of an interface, > but Im not sure how to do this. Thomas, thanks for raising this problem. If I'm not wrong the same issue has been reported other times in the list and I agree with you that ifconfig output is not portable at all due to languages issue. I've found a way to get the ip address of an interface directly using ioctl() and so fully implemented in perl. See the patch below. It's a bit tricky, but it would be independent on language settings and ifconfig output in general (so it'll work even if ifconfig will change its output). I've tested it in Ubuntu 7.10 and it seems to work. Could you test if it works also for you? Otherwise we can always fall back to your patch. Thanks, -Andrea -- Index: sbin/si_installbtimage =================================================================== --- sbin/si_installbtimage (revision 4443) +++ sbin/si_installbtimage (working copy) @@ -10,6 +10,7 @@ use File::Basename; use Getopt::Long; use SystemImager::Config; +use Socket qw/PF_INET SOCK_DGRAM inet_ntoa sockaddr_in/; use vars qw($config $VERSION); my $config_dir = "/etc/systemimager"; @@ -107,7 +108,20 @@ if (m/BT_TRACKER_PORT=([0-9]+)/) { $tracker_port = $1; } elsif (m/BT_INTERFACE=(.+)/) { - ($image_server) = (`/sbin/ifconfig $1`)[1] =~ /inet addr:(\S+)/; + # Get IP address of the specified interface. + # This is quite tricky but more portable than retrieving the IP address + # from ifconfig output (see language issue). + socket(SOCKET, PF_INET, SOCK_DGRAM, getprotobyname('ip')) + or die("ERROR: couldn't create socket!\n"); + + # use ioctl() interface with SIOCGIFADDR. + my $ifreq = pack('a32', $1); + ioctl(SOCKET, 0x8915, $ifreq) or + die("ERROR: ioctl failed: $!\n"); + + # Format the IP address from the output of ioctl(). + $image_server = inet_ntoa((sockaddr_in((unpack('a16 a16', $ifreq))[1]))[1]) or + die("ERROR: couldn't retrieve IP address from: $ifreq\n"); } } unless ($tracker_port) { ------------------------------------------------------------------------- This SF.net email is sponsored by the 2008 JavaOne(SM) Conference Don't miss this year's exciting event. There's still time to save $100. Use priority code J8TL2D2. http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javao ne _______________________________________________ sisuite-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/sisuite-users ------------------------------------------------------------------------- This SF.net email is sponsored by the 2008 JavaOne(SM) Conference Don't miss this year's exciting event. There's still time to save $100. Use priority code J8TL2D2. http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone _______________________________________________ sisuite-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/sisuite-users
