line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FusionInventory::Agent::Tools::BSD; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
10026931
|
use strict; |
|
2
|
|
|
|
|
10
|
|
|
2
|
|
|
|
|
101
|
|
4
|
2
|
|
|
2
|
|
16
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
83
|
|
5
|
2
|
|
|
2
|
|
13
|
use base 'Exporter'; |
|
2
|
|
|
|
|
39
|
|
|
2
|
|
|
|
|
229
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
8
|
use English qw(-no_match_vars); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
22
|
|
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
1448
|
use FusionInventory::Agent::Tools; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
330
|
|
10
|
2
|
|
|
2
|
|
571
|
use FusionInventory::Agent::Tools::Network; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
1265
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @EXPORT = qw( |
13
|
|
|
|
|
|
|
getInterfacesFromIfconfig |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub getInterfacesFromIfconfig { |
17
|
0
|
|
|
0
|
1
|
|
my (%params) = ( |
18
|
|
|
|
|
|
|
command => '/sbin/ifconfig -a', |
19
|
|
|
|
|
|
|
@_ |
20
|
|
|
|
|
|
|
); |
21
|
0
|
|
|
|
|
|
my $handle = getFileHandle(%params); |
22
|
0
|
0
|
|
|
|
|
return unless $handle; |
23
|
|
|
|
|
|
|
|
24
|
0
|
|
|
|
|
|
my @interfaces; # global list of interfaces |
25
|
|
|
|
|
|
|
my @addresses; # per-interface list of addresses |
26
|
0
|
|
|
|
|
|
my $interface; # current interface |
27
|
|
|
|
|
|
|
|
28
|
0
|
|
|
|
|
|
my %types = ( |
29
|
|
|
|
|
|
|
Ethernet => 'ethernet', |
30
|
|
|
|
|
|
|
IEEE => 'wifi' |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
while (my $line = <$handle>) { |
34
|
0
|
0
|
|
|
|
|
if ($line =~ /^(\S+): flags=\d+<([^>]+)> metric \d+ mtu (\d+)/) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
36
|
0
|
0
|
|
|
|
|
if (@addresses) { |
37
|
0
|
|
|
|
|
|
push @interfaces, @addresses; |
38
|
0
|
|
|
|
|
|
undef @addresses; |
39
|
|
|
|
|
|
|
} else { |
40
|
0
|
0
|
|
|
|
|
push @interfaces, $interface if $interface; |
41
|
|
|
|
|
|
|
} |
42
|
0
|
|
|
|
|
|
my ($name, $flags, $mtu) = ($1, $2, $3); |
43
|
|
|
|
|
|
|
my $status = |
44
|
0
|
0
|
|
0
|
|
|
(any { $_ eq 'UP' } split(/,/, $flags)) ? 'Up' : 'Down'; |
|
0
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
$interface = { |
47
|
|
|
|
|
|
|
DESCRIPTION => $name, |
48
|
|
|
|
|
|
|
STATUS => $status, |
49
|
|
|
|
|
|
|
MTU => $mtu |
50
|
|
|
|
|
|
|
}; |
51
|
|
|
|
|
|
|
} elsif ($line =~ /(?:address:|ether|lladdr) ($mac_address_pattern)/) { |
52
|
0
|
|
|
|
|
|
$interface->{MACADDR} = $1; |
53
|
|
|
|
|
|
|
} elsif ($line =~ / |
54
|
|
|
|
|
|
|
ssid \s (\S+) \s |
55
|
|
|
|
|
|
|
channel \s \d+ \s |
56
|
|
|
|
|
|
|
\(\d+ \s MHz \s (\S+)[^)]*\) \s |
57
|
|
|
|
|
|
|
bssid \s ($mac_address_pattern) |
58
|
|
|
|
|
|
|
/x) { |
59
|
0
|
|
|
|
|
|
foreach my $address (@addresses) { |
60
|
0
|
|
|
|
|
|
$address->{WIFI_SSID} = $1; |
61
|
0
|
|
|
|
|
|
$address->{WIFI_VERSION} = '802.' . $2; |
62
|
0
|
|
|
|
|
|
$address->{WIFI_BSSID} = $3; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
} elsif ($line =~ /inet ($ip_address_pattern) (?:--> $ip_address_pattern )?netmask 0x($hex_ip_address_pattern)/) { |
65
|
0
|
|
|
|
|
|
my $address = $1; |
66
|
0
|
|
|
|
|
|
my $mask = hex2canonical($2); |
67
|
0
|
|
|
|
|
|
my $subnet = getSubnetAddress($address, $mask); |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
push @addresses, { |
70
|
|
|
|
|
|
|
IPADDRESS => $address, |
71
|
|
|
|
|
|
|
IPMASK => $mask, |
72
|
|
|
|
|
|
|
IPSUBNET => $subnet, |
73
|
|
|
|
|
|
|
STATUS => $interface->{STATUS}, |
74
|
|
|
|
|
|
|
DESCRIPTION => $interface->{DESCRIPTION}, |
75
|
|
|
|
|
|
|
MACADDR => $interface->{MACADDR}, |
76
|
|
|
|
|
|
|
MTU => $interface->{MTU} |
77
|
|
|
|
|
|
|
}; |
78
|
|
|
|
|
|
|
} elsif ($line =~ /inet6 ([\w:]+)\S* prefixlen (\d+)/) { |
79
|
0
|
|
|
|
|
|
my $address = $1; |
80
|
0
|
|
|
|
|
|
my $mask = getNetworkMaskIPv6($2); |
81
|
0
|
|
|
|
|
|
my $subnet = getSubnetAddressIPv6($address, $mask); |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
push @addresses, { |
84
|
|
|
|
|
|
|
IPADDRESS6 => $address, |
85
|
|
|
|
|
|
|
IPMASK6 => $mask, |
86
|
|
|
|
|
|
|
IPSUBNET6 => $subnet, |
87
|
|
|
|
|
|
|
STATUS => $interface->{STATUS}, |
88
|
|
|
|
|
|
|
DESCRIPTION => $interface->{DESCRIPTION}, |
89
|
|
|
|
|
|
|
MACADDR => $interface->{MACADDR}, |
90
|
|
|
|
|
|
|
MTU => $interface->{MTU} |
91
|
|
|
|
|
|
|
}; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
0
|
0
|
|
|
|
|
if ($line =~ /media: (\S+)/) { |
96
|
0
|
|
|
|
|
|
$interface->{TYPE} = $types{$1}; |
97
|
0
|
|
|
|
|
|
$_->{TYPE} = $types{$1} foreach @addresses; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
} |
100
|
0
|
|
|
|
|
|
close $handle; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
# last interface |
103
|
0
|
0
|
|
|
|
|
if (@addresses) { |
104
|
0
|
|
|
|
|
|
push @interfaces, @addresses; |
105
|
|
|
|
|
|
|
} else { |
106
|
0
|
0
|
|
|
|
|
push @interfaces, $interface if $interface; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
return @interfaces; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
1; |
113
|
|
|
|
|
|
|
__END__ |