X-Git-Url: http://lab.mitty.jp/git/?a=blobdiff_plain;f=.bin%2Fget_ip_from_ioctl.pl;fp=.bin%2Fget_ip_from_ioctl.pl;h=0000000000000000000000000000000000000000;hb=8333ea00a9fe608c90c20af12ea0c51548f66f4e;hp=151b506845c34a37453b5481d6e0a22fc5079986;hpb=920ad9e17feea13643c407944f9452b03bd45b6e;p=lab.git diff --git a/.bin/get_ip_from_ioctl.pl b/.bin/get_ip_from_ioctl.pl deleted file mode 100755 index 151b506..0000000 --- a/.bin/get_ip_from_ioctl.pl +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/perl -use strict; -use warnings; -require 'sys/ioctl.ph'; -use Socket; - -my %interfaces; -my $max_addrs = 30; -socket(my $socket, AF_INET, SOCK_DGRAM, 0) or die "socket: $!"; - -{ - my $ifreqpack = 'a16a16'; - my $buf = pack($ifreqpack, '', '') x $max_addrs; - my $ifconf = pack('iP', length($buf), $buf); - - # This does the actual work - ioctl($socket, SIOCGIFCONF(), $ifconf) or die "ioctl: $!"; - - my $len = unpack('iP', $ifconf); - substr($buf, $len) = ''; - - %interfaces = unpack("($ifreqpack)*", $buf); - - unless (keys(%interfaces) < $max_addrs) { - # Buffer was too small - $max_addrs += 10; - redo; - } -} - -for my $addr (values %interfaces) { - $addr = inet_ntoa((sockaddr_in($addr))[1]); -} - -use Data::Dumper; -print Dumper \%interfaces;