4 require 'sys/ioctl.ph';
9 socket(my $socket, AF_INET, SOCK_DGRAM, 0) or die "socket: $!";
12 my $ifreqpack = 'a16a16';
13 my $buf = pack($ifreqpack, '', '') x $max_addrs;
14 my $ifconf = pack('iP', length($buf), $buf);
16 # This does the actual work
17 ioctl($socket, SIOCGIFCONF(), $ifconf) or die "ioctl: $!";
19 my $len = unpack('iP', $ifconf);
20 substr($buf, $len) = '';
22 %interfaces = unpack("($ifreqpack)*", $buf);
24 unless (keys(%interfaces) < $max_addrs) {
25 # Buffer was too small
31 for my $addr (values %interfaces) {
32 $addr = inet_ntoa((sockaddr_in($addr))[1]);
36 print Dumper \%interfaces;