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