line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FusionInventory::Agent::Tools::BSD; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
13366489
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
114
|
|
4
|
3
|
|
|
3
|
|
20
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
152
|
|
5
|
3
|
|
|
3
|
|
15
|
use base 'Exporter'; |
|
3
|
|
|
|
|
74
|
|
|
3
|
|
|
|
|
410
|
|
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
779
|
use English qw(-no_match_vars); |
|
3
|
|
|
|
|
4206
|
|
|
3
|
|
|
|
|
34
|
|
8
|
|
|
|
|
|
|
|
9
|
3
|
|
|
3
|
|
3226
|
use FusionInventory::Agent::Tools; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
546
|
|
10
|
3
|
|
|
3
|
|
1345
|
use FusionInventory::Agent::Tools::Network; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
2501
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @EXPORT = qw( |
13
|
|
|
|
|
|
|
getInterfacesFromIfconfig |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub getInterfacesFromIfconfig { |
17
|
4
|
|
|
4
|
1
|
37446
|
my (%params) = ( |
18
|
|
|
|
|
|
|
command => '/sbin/ifconfig -a', |
19
|
|
|
|
|
|
|
@_ |
20
|
|
|
|
|
|
|
); |
21
|
4
|
|
|
|
|
24
|
my $handle = getFileHandle(%params); |
22
|
4
|
50
|
|
|
|
14
|
return unless $handle; |
23
|
|
|
|
|
|
|
|
24
|
4
|
|
|
|
|
7
|
my @interfaces; # global list of interfaces |
25
|
|
|
|
|
|
|
my @addresses; # per-interface list of addresses |
26
|
0
|
|
|
|
|
0
|
my $interface; # current interface |
27
|
|
|
|
|
|
|
|
28
|
4
|
|
|
|
|
18
|
my %types = ( |
29
|
|
|
|
|
|
|
Ethernet => 'ethernet', |
30
|
|
|
|
|
|
|
IEEE => 'wifi' |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
|
33
|
4
|
|
|
|
|
88
|
while (my $line = <$handle>) { |
34
|
95
|
100
|
|
|
|
1360
|
if ($line =~ /^(\S+): flags=\d+<([^>]+)> (?:metric \d+ )?mtu (\d+)/) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
36
|
17
|
100
|
|
|
|
34
|
if (@addresses) { |
37
|
7
|
|
|
|
|
12
|
push @interfaces, @addresses; |
38
|
7
|
|
|
|
|
12
|
undef @addresses; |
39
|
|
|
|
|
|
|
} else { |
40
|
10
|
100
|
|
|
|
26
|
push @interfaces, $interface if $interface; |
41
|
|
|
|
|
|
|
} |
42
|
17
|
|
|
|
|
57
|
my ($name, $flags, $mtu) = ($1, $2, $3); |
43
|
|
|
|
|
|
|
my $status = |
44
|
17
|
100
|
|
25
|
|
139
|
(any { $_ eq 'UP' } split(/,/, $flags)) ? 'Up' : 'Down'; |
|
25
|
|
|
|
|
129
|
|
45
|
|
|
|
|
|
|
|
46
|
17
|
|
|
|
|
98
|
$interface = { |
47
|
|
|
|
|
|
|
DESCRIPTION => $name, |
48
|
|
|
|
|
|
|
STATUS => $status, |
49
|
|
|
|
|
|
|
MTU => $mtu |
50
|
|
|
|
|
|
|
}; |
51
|
|
|
|
|
|
|
} elsif ($line =~ /(?:address:|ether|lladdr) ($mac_address_pattern)/) { |
52
|
11
|
|
|
|
|
33
|
$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
|
2
|
|
|
|
|
5
|
foreach my $address (@addresses) { |
60
|
2
|
|
|
|
|
6
|
$address->{WIFI_SSID} = $1; |
61
|
2
|
|
|
|
|
5
|
$address->{WIFI_VERSION} = '802.' . $2; |
62
|
2
|
|
|
|
|
6
|
$address->{WIFI_BSSID} = $3; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
} elsif ($line =~ /inet ($ip_address_pattern) (?:--> $ip_address_pattern )?netmask 0x($hex_ip_address_pattern)/) { |
65
|
13
|
|
|
|
|
28
|
my $address = $1; |
66
|
13
|
|
|
|
|
43
|
my $mask = hex2canonical($2); |
67
|
13
|
|
|
|
|
45
|
my $subnet = getSubnetAddress($address, $mask); |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
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
|
13
|
|
|
|
|
281
|
}; |
78
|
|
|
|
|
|
|
} elsif ($line =~ /inet6 ([\w:]+)\S* prefixlen (\d+)/) { |
79
|
6
|
|
|
|
|
12
|
my $address = $1; |
80
|
6
|
|
|
|
|
21
|
my $mask = getNetworkMaskIPv6($2); |
81
|
6
|
|
|
|
|
637
|
my $subnet = getSubnetAddressIPv6($address, $mask); |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
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
|
6
|
|
|
|
|
649
|
}; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
95
|
100
|
|
|
|
484
|
if ($line =~ /media: (\S+)/) { |
96
|
8
|
|
|
|
|
23
|
$interface->{TYPE} = $types{$1}; |
97
|
8
|
|
|
|
|
53
|
$_->{TYPE} = $types{$1} foreach @addresses; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
} |
100
|
4
|
|
|
|
|
103
|
close $handle; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
# last interface |
103
|
4
|
100
|
|
|
|
13
|
if (@addresses) { |
104
|
3
|
|
|
|
|
7
|
push @interfaces, @addresses; |
105
|
|
|
|
|
|
|
} else { |
106
|
1
|
50
|
|
|
|
5
|
push @interfaces, $interface if $interface; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
4
|
|
|
|
|
34
|
return @interfaces; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
1; |
113
|
|
|
|
|
|
|
__END__ |