Andrea Righi a écrit :
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 I’m 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.

tested this morning, your patch works also for us  (on debian etch)
so better than the ifconfig output
thanks

ML


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/javaone
_______________________________________________
sisuite-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sisuite-users


--
    Maurice Libes
Tel : +33 (04) 91 82 93 25 Centre d'Oceanologie de Marseille Fax : +33 (04) 91 82 93 03 UMS2196CNRS- Campus de Luminy, Case 901 F-13288 Marseille cedex 9

Veuillez noter ma nouvelle adresse ==> [EMAIL PROTECTED]

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

-------------------------------------------------------------------------
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

Reply via email to