Subject: | Interface detection regular expression is flawed |
A few systems that I've worked on have multiple aliased interfaces
(eth0:0, eth0:1, etc.) Some of these have double digit numbers after
the colons, such as eth0:13.
The regular expression (line 143 in HostIP.pm) will still find eth0:13,
but since it only captures the first number after the colon, it will
overwrite the entry in the hash previously stored for eth0:1. This
happens successively for each entry that matches, so that if someone had
the following interfaces: eth0:0 to eth0:19, the only ones that will
show up are eth0:0 to eth0:9, with eth0:1 being overwritten in the end
by eth0:19.
The original regular expression is: /(^\w+(?:\d)?(?:\:\d)?)/.
A simple modification: /(^\w+(?:\d)?(?:\:\d+)?)/ seems to fix this problem.
Attached is a sample output before and after the change in my local copy
of the module.
Subject: | Sys_HostIP Sample Output.txt |
Code used to test this:
#!/usr/bin/perl
use strict;
use Data::Dumper;
use Sys::HostIP;
my $interfaces = Sys::HostIP->interfaces;
print Dumper \$interfaces;
Output before regular expression change:
$VAR1 = \{
'bond0:2' => '192.168.1.224',
'lo' => '127.0.0.1',
'bond0:5' => '192.168.1.100',
'bond0:3' => '192.168.1.33',
'bond0' => '192.168.1.30',
'eth1' => '192.168.1.30',
'bond0:1' => '192.168.1.219',
'eth0' => '192.168.1.30'
};
Output after regular expression change:
$VAR1 = \{
'bond0:19' => '192.168.1.219',
'bond0:2' => '192.168.1.32',
'bond0' => '192.168.1.30',
'eth0' => '192.168.1.30',
'bond0:14' => '192.168.1.214',
'lo' => '127.0.0.1',
'bond0:23' => '192.168.1.223',
'bond0:17' => '192.168.1.217',
'bond0:5' => '192.168.1.100',
'bond0:11' => '192.168.1.211',
'bond0:24' => '192.168.1.224',
'bond0:12' => '192.168.1.212',
'bond0:10' => '192.168.1.210',
'bond0:13' => '192.168.1.213',
'bond0:16' => '192.168.1.216',
'bond0:22' => '192.168.1.222',
'bond0:3' => '192.168.1.33',
'bond0:15' => '192.168.1.215',
'bond0:21' => '192.168.1.221',
'bond0:18' => '192.168.1.218',
'bond0:20' => '192.168.1.220',
'eth1' => '192.168.1.30',
'bond0:1' => '192.168.1.31'
};