line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyright 1995,2002 Spider Boardman. |
2
|
|
|
|
|
|
|
# All rights reserved. |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# Automatic licensing for this software is available. This software |
5
|
|
|
|
|
|
|
# can be copied and used under the terms of the GNU Public License, |
6
|
|
|
|
|
|
|
# version 1 or (at your option) any later version, or under the |
7
|
|
|
|
|
|
|
# terms of the Artistic license. Both of these can be found with |
8
|
|
|
|
|
|
|
# the Perl distribution, which this software is intended to augment. |
9
|
|
|
|
|
|
|
# |
10
|
|
|
|
|
|
|
# THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR |
11
|
|
|
|
|
|
|
# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED |
12
|
|
|
|
|
|
|
# WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# rcsid: "@(#) $Id: UDP.dat,v 1.21 2002/03/30 10:10:55 spider Exp $" |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
package Net::UDP; |
17
|
1
|
|
|
1
|
|
1019
|
use 5.004_04; # new minimum Perl version for this package |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
43
|
|
18
|
|
|
|
|
|
|
|
19
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
86
|
|
20
|
|
|
|
|
|
|
#use Carp; |
21
|
0
|
|
|
0
|
0
|
0
|
sub carp { require Carp; goto &Carp::carp; } |
|
0
|
|
|
|
|
0
|
|
22
|
0
|
|
|
0
|
0
|
0
|
sub croak { require Carp; goto &Carp::croak; } |
|
0
|
|
|
|
|
0
|
|
23
|
1
|
|
|
1
|
|
5
|
use vars qw($VERSION @ISA *AUTOLOAD); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
95
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
BEGIN { |
26
|
1
|
|
|
1
|
|
2
|
$VERSION = '1.0'; |
27
|
1
|
|
|
|
|
74
|
eval "sub Version () { __PACKAGE__ . ' v$VERSION' }"; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
1
|
|
|
1
|
|
7
|
use AutoLoader; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
9
|
|
31
|
|
|
|
|
|
|
|
32
|
1
|
|
|
1
|
|
37
|
use Net::Inet 1.0; |
|
1
|
|
|
|
|
88
|
|
|
1
|
|
|
|
|
237
|
|
33
|
1
|
|
|
1
|
|
6
|
use Net::Gen 1.0 ':sockvals', ':families'; |
|
1
|
|
|
|
|
23
|
|
|
1
|
|
|
|
|
748
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
BEGIN { |
36
|
1
|
|
|
1
|
|
22
|
@ISA = 'Net::Inet'; |
37
|
1
|
|
|
|
|
508
|
*AUTOLOAD = \$Net::Gen::AUTOLOAD; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# Cheat on AUTOLOAD inheritance. |
41
|
|
|
|
|
|
|
sub AUTOLOAD |
42
|
|
|
|
|
|
|
{ |
43
|
|
|
|
|
|
|
#$Net::Gen::AUTOLOAD = $AUTOLOAD; |
44
|
0
|
|
|
0
|
|
0
|
goto &Net::Gen::AUTOLOAD; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# Preloaded methods go here. Autoload methods go after |
48
|
|
|
|
|
|
|
# __END__, and are processed by the autosplit program. |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# No new socket options for UDP |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# Module-specific object options |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
my @Keys = qw(unbuffered_input unbuffered_output); |
55
|
|
|
|
|
|
|
my @CodeKeys = qw(unbuffered_IO unbuffered_io); |
56
|
|
|
|
|
|
|
my %CodeKeys; |
57
|
|
|
|
|
|
|
@CodeKeys{@CodeKeys} = (\&_setbuf_unbuf) x @CodeKeys; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
my %Keys; # for only calling registration routines once |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub new : locked |
62
|
|
|
|
|
|
|
{ |
63
|
2
|
|
|
2
|
1
|
384
|
my($class,@args) = @_; |
64
|
2
|
|
|
|
|
20
|
my $self = $class->SUPER::new(@args); |
65
|
2
|
50
|
|
|
|
7
|
$class = ref $class if ref $class; |
66
|
2
|
50
|
|
|
|
6
|
if ($self) { |
67
|
2
|
100
|
|
|
|
5
|
if (%Keys) { |
68
|
1
|
|
|
|
|
17
|
$ {*$self}{Keys} = { %Keys } ; |
|
1
|
|
|
|
|
3
|
|
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
else { |
71
|
1
|
|
|
|
|
5
|
$self->register_param_keys(\@Keys); |
72
|
1
|
|
|
|
|
5
|
$self->register_param_handlers(\%CodeKeys); |
73
|
1
|
|
|
|
|
2
|
%Keys = %{ $ {*$self}{Keys} } ; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
15
|
|
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
# no new sockopts for UDP? |
76
|
|
|
|
|
|
|
# set our required parameters |
77
|
2
|
|
|
|
|
23
|
$self->setparams({type => SOCK_DGRAM, |
78
|
|
|
|
|
|
|
proto => IPPROTO_UDP, |
79
|
|
|
|
|
|
|
IPproto => 'udp', |
80
|
|
|
|
|
|
|
netgen_fakeconnect => 1, |
81
|
|
|
|
|
|
|
unbuffered_output => 0, |
82
|
|
|
|
|
|
|
unbuffered_input => 0}, -1); |
83
|
2
|
50
|
|
|
|
10
|
if ($class eq __PACKAGE__) { |
84
|
2
|
50
|
|
|
|
14
|
unless ($self->init(@args)) { |
85
|
0
|
|
|
|
|
0
|
local $!; # protect returned errno value |
86
|
0
|
|
|
|
|
0
|
undef $self; # against excess closes in perl core |
87
|
0
|
|
|
|
|
0
|
undef $self; # another statement needed for sequencing |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
} |
91
|
2
|
|
|
|
|
9
|
$self; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
#& _addrinfo($this, $sockaddr, [numeric_only]) : @list |
95
|
|
|
|
|
|
|
sub _addrinfo |
96
|
|
|
|
|
|
|
{ |
97
|
4
|
|
|
4
|
|
809
|
my($this,@args,@r) = @_; |
98
|
4
|
|
|
|
|
32
|
@r = $this->SUPER::_addrinfo(@args); |
99
|
4
|
50
|
33
|
|
|
39
|
unless(!@r or $args[1] or ref($this) or $r[2] ne $r[3]) { |
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
100
|
0
|
|
|
|
|
0
|
$this = getservbyport(htons($r[3]), 'udp'); |
101
|
0
|
0
|
|
|
|
0
|
$r[2] = $this if defined $this; |
102
|
|
|
|
|
|
|
} |
103
|
4
|
|
|
|
|
20
|
@r; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
# autoloaded methods go after the END token (& pod) below |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
# hack to ensure that autoloading in Net::Gen doesn't override these... |
109
|
|
|
|
|
|
|
# not needed currently, but keep it in mind |
110
|
|
|
|
|
|
|
#sub PRINT { goto &_UDP_PRINT; } |
111
|
|
|
|
|
|
|
#sub READLINE { goto &_UDP_READLINE; } |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
1; |
114
|
|
|
|
|
|
|
__END__ |