line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# -*- mode: perl -*- |
2
|
|
|
|
|
|
|
# ============================================================================ |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Net::SNMP::Transport::IPv4::UDP; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# $Id: UDP.pm,v 4.0 2009/09/09 15:05:33 dtown Rel $ |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# Object that handles the UDP/IPv4 Transport Domain for the SNMP Engine. |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# Copyright (c) 2001-2009 David M. Town |
11
|
|
|
|
|
|
|
# All rights reserved. |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# This program is free software; you may redistribute it and/or modify it |
14
|
|
|
|
|
|
|
# under the same terms as the Perl 5 programming language system itself. |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# ============================================================================ |
17
|
|
|
|
|
|
|
|
18
|
2
|
|
|
2
|
|
11
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
76
|
|
19
|
|
|
|
|
|
|
|
20
|
2
|
|
|
2
|
|
18
|
use Net::SNMP::Transport qw( DOMAIN_UDPIPV4 ); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
139
|
|
21
|
|
|
|
|
|
|
|
22
|
2
|
|
|
2
|
|
1939
|
use IO::Socket qw( SOCK_DGRAM ); |
|
2
|
|
|
|
|
50556
|
|
|
2
|
|
|
|
|
12
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
## Version of the Net::SNMP::Transport::IPv4::UDP module |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
our $VERSION = v4.0.0; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
## Handle importing/exporting of symbols |
29
|
|
|
|
|
|
|
|
30
|
2
|
|
|
2
|
|
643
|
use base qw( Net::SNMP::Transport::IPv4 Net::SNMP::Transport ); |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
1377
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub import |
33
|
|
|
|
|
|
|
{ |
34
|
0
|
|
|
0
|
|
0
|
return Net::SNMP::Transport->export_to_level(1, @_); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
## RFC 3411 - snmpEngineMaxMessageSize::=INTEGER (484..2147483647) |
38
|
|
|
|
|
|
|
|
39
|
3
|
|
|
3
|
0
|
16
|
sub MSG_SIZE_DEFAULT_UDP4 { 1472 } # Ethernet(1500) - IPv4(20) - UDP(8) |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# [public methods] ----------------------------------------------------------- |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub new |
44
|
|
|
|
|
|
|
{ |
45
|
3
|
|
|
3
|
0
|
29
|
return shift->SUPER::_new(@_); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub send |
49
|
|
|
|
|
|
|
{ |
50
|
1
|
|
|
1
|
0
|
1137
|
my $this = shift; |
51
|
|
|
|
|
|
|
|
52
|
1
|
|
|
|
|
23
|
$this->_error_clear(); |
53
|
|
|
|
|
|
|
|
54
|
1
|
50
|
|
|
|
7
|
if (length($_[0]) > $this->{_max_msg_size}) { |
55
|
0
|
|
|
|
|
0
|
return $this->_error( |
56
|
|
|
|
|
|
|
'The message size %d exceeds the maxMsgSize %d', |
57
|
|
|
|
|
|
|
length($_[0]), $this->{_max_msg_size} |
58
|
|
|
|
|
|
|
); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
1
|
|
|
|
|
11
|
my $bytes = $this->{_socket}->send($_[0], 0, $this->{_dest_name}); |
62
|
|
|
|
|
|
|
|
63
|
1
|
50
|
|
|
|
152
|
return defined($bytes) ? $bytes : $this->_perror('Send failure'); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub recv |
67
|
|
|
|
|
|
|
{ |
68
|
1
|
|
|
1
|
0
|
243
|
my $this = shift; |
69
|
|
|
|
|
|
|
|
70
|
1
|
|
|
|
|
5
|
$this->_error_clear(); |
71
|
|
|
|
|
|
|
|
72
|
1
|
|
|
|
|
32
|
my $name = $this->{_socket}->recv($_[0], $this->_shared_max_size(), 0); |
73
|
|
|
|
|
|
|
|
74
|
1
|
50
|
|
|
|
39
|
return defined($name) ? $name : $this->_perror('Receive failure'); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub domain |
78
|
|
|
|
|
|
|
{ |
79
|
0
|
|
|
0
|
0
|
0
|
return DOMAIN_UDPIPV4; # transportDomainUdpIpv4 |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub type |
83
|
|
|
|
|
|
|
{ |
84
|
3
|
|
|
3
|
0
|
29
|
return 'UDP/IPv4'; # udpIpv4(1) |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub agent_addr |
88
|
|
|
|
|
|
|
{ |
89
|
0
|
|
|
0
|
0
|
0
|
my ($this) = @_; |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
0
|
$this->_error_clear(); |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
0
|
|
|
0
|
my $name = $this->{_socket}->sockname() || $this->{_sock_name}; |
94
|
|
|
|
|
|
|
|
95
|
0
|
0
|
|
|
|
0
|
if ($this->{_socket}->connect($this->{_dest_name})) { |
96
|
0
|
|
0
|
|
|
0
|
$name = $this->{_socket}->sockname() || $this->{_sock_name}; |
97
|
0
|
0
|
|
|
|
0
|
if (!$this->{_socket}->connect((pack('x') x length $name))) { |
98
|
0
|
|
|
|
|
0
|
$this->_perror('Failed to disconnect'); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
0
|
return $this->_address($name); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
# [private methods] ---------------------------------------------------------- |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub _protocol_name |
108
|
|
|
|
|
|
|
{ |
109
|
3
|
|
|
3
|
|
1810
|
return 'udp'; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub _protocol_type |
113
|
|
|
|
|
|
|
{ |
114
|
3
|
|
|
3
|
|
22
|
return SOCK_DGRAM; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub _msg_size_default |
118
|
|
|
|
|
|
|
{ |
119
|
3
|
|
|
3
|
|
8
|
return MSG_SIZE_DEFAULT_UDP4; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub _tdomain |
123
|
|
|
|
|
|
|
{ |
124
|
0
|
|
|
0
|
|
|
return DOMAIN_UDPIPV4; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
# ============================================================================ |
128
|
|
|
|
|
|
|
1; # [end Net::SNMP::Transport::IPv4::UDP] |
129
|
|
|
|
|
|
|
|