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: TCP.dat,v 1.25 2002/03/30 10:11:53 spider Exp $" |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
package Net::TCP; |
17
|
1
|
|
|
1
|
|
782
|
use 5.004_04; # new minimum Perl version for this package |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
41
|
|
18
|
|
|
|
|
|
|
|
19
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
86
|
|
20
|
|
|
|
|
|
|
#use Carp; |
21
|
0
|
|
|
0
|
0
|
|
sub carp { require Carp; goto &Carp::carp; } |
|
0
|
|
|
|
|
|
|
22
|
0
|
|
|
0
|
0
|
|
sub croak { require Carp; goto &Carp::croak; } |
|
0
|
|
|
|
|
|
|
23
|
1
|
|
|
1
|
|
5
|
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS *AUTOLOAD); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
129
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
BEGIN { |
26
|
1
|
|
|
1
|
|
2
|
$VERSION = '1.0'; |
27
|
1
|
|
|
|
|
71
|
eval "sub Version () { __PACKAGE__ . ' v$VERSION' }"; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
#use AutoLoader; # disable this until we have autoloadable subs again |
31
|
|
|
|
|
|
|
#use Exporter (); # we inherit what we need here from Net::Gen |
32
|
1
|
|
|
1
|
|
924
|
use Net::Inet 1.0; |
|
1
|
|
|
|
|
301
|
|
|
1
|
|
|
|
|
346
|
|
33
|
1
|
|
|
1
|
|
7
|
use Net::Gen 1.0 ':sockvals', ':families'; |
|
1
|
|
|
|
|
15
|
|
|
1
|
|
|
|
|
911
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
BEGIN { |
36
|
1
|
|
|
1
|
|
26
|
@ISA = 'Net::Inet'; |
37
|
1
|
|
|
|
|
3
|
*AUTOLOAD = \$Net::Gen::AUTOLOAD; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# Items to export into callers namespace by default |
40
|
|
|
|
|
|
|
# (move infrequently used names to @EXPORT_OK below) |
41
|
1
|
|
|
|
|
2
|
@EXPORT = qw( |
42
|
|
|
|
|
|
|
); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# Other items we are prepared to export if requested |
45
|
1
|
|
|
|
|
5
|
@EXPORT_OK = qw( |
46
|
|
|
|
|
|
|
TCPOPT_EOL |
47
|
|
|
|
|
|
|
TCPOPT_MAXSEG |
48
|
|
|
|
|
|
|
TCPOPT_NOP |
49
|
|
|
|
|
|
|
TCPOPT_WINDOW |
50
|
|
|
|
|
|
|
TCP_MAXSEG |
51
|
|
|
|
|
|
|
TCP_MAXWIN |
52
|
|
|
|
|
|
|
TCP_MAX_WINSHIFT |
53
|
|
|
|
|
|
|
TCP_MSS |
54
|
|
|
|
|
|
|
TCP_NODELAY |
55
|
|
|
|
|
|
|
TCP_RPTR2RXT |
56
|
|
|
|
|
|
|
TH_ACK |
57
|
|
|
|
|
|
|
TH_FIN |
58
|
|
|
|
|
|
|
TH_PUSH |
59
|
|
|
|
|
|
|
TH_RST |
60
|
|
|
|
|
|
|
TH_SYN |
61
|
|
|
|
|
|
|
TH_URG |
62
|
|
|
|
|
|
|
); |
63
|
|
|
|
|
|
|
|
64
|
1
|
|
|
|
|
822
|
%EXPORT_TAGS = ( |
65
|
|
|
|
|
|
|
sockopts => [qw(TCP_NODELAY TCP_MAXSEG TCP_RPTR2RXT)], |
66
|
|
|
|
|
|
|
tcpoptions => [qw(TCPOPT_EOL TCPOPT_MAXSEG TCPOPT_NOP |
67
|
|
|
|
|
|
|
TCPOPT_WINDOW)], |
68
|
|
|
|
|
|
|
protocolvalues => [qw(TCP_MAXWIN TCP_MAX_WINSHIFT TCP_MSS |
69
|
|
|
|
|
|
|
TH_ACK TH_FIN TH_PUSH TH_RST TH_SYN TH_URG)], |
70
|
|
|
|
|
|
|
ALL => [@EXPORT, @EXPORT_OK], |
71
|
|
|
|
|
|
|
); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
;# sub AUTOLOAD inherited from Net::Gen (via Net::Inet) |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
;# However, since 5.003_96 will make simple subroutines not inherit AUTOLOAD... |
77
|
|
|
|
|
|
|
sub AUTOLOAD |
78
|
|
|
|
|
|
|
{ |
79
|
|
|
|
|
|
|
#$Net::Gen::AUTOLOAD = $AUTOLOAD; |
80
|
0
|
|
|
0
|
|
|
goto &Net::Gen::AUTOLOAD; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# Preloaded methods go here. Autoload methods go after __END__, and are |
85
|
|
|
|
|
|
|
# processed by the autosplit program. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
my %sockopts; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
%sockopts = ( |
91
|
|
|
|
|
|
|
# known TCP socket options |
92
|
|
|
|
|
|
|
# simple booleans first |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
'TCP_NODELAY' => ['i'], |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
# simple integer options |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
'TCP_MAXSEG' => ['i'], |
99
|
|
|
|
|
|
|
'TCP_RPTR2RXT' => ['i'], |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# structured options |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# out of known TCP options |
104
|
|
|
|
|
|
|
); |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
__PACKAGE__->initsockopts( IPPROTO_TCP, \%sockopts ); |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
my $debug = 0; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
#& _debug($this, [$newval]) : oldval |
111
|
|
|
|
|
|
|
sub _debug : locked |
112
|
|
|
|
|
|
|
{ |
113
|
0
|
|
|
0
|
|
|
my ($this,$newval) = @_; |
114
|
0
|
0
|
|
|
|
|
return $this->debug($newval) if ref $this; |
115
|
0
|
|
|
|
|
|
my $prev = $debug; |
116
|
0
|
0
|
|
|
|
|
$debug = 0+$newval if defined $newval; |
117
|
0
|
|
|
|
|
|
$prev; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
my %Sopts; # do a full register_options only once |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub new : locked |
123
|
|
|
|
|
|
|
{ |
124
|
0
|
|
|
0
|
1
|
|
my $whoami = $_[0]->_trace(\@_,1); |
125
|
0
|
|
|
|
|
|
my($class,@args) = @_; |
126
|
0
|
|
|
|
|
|
my $self = $class->SUPER::new(@args); |
127
|
0
|
0
|
|
|
|
|
$class = ref $class if ref $class; |
128
|
0
|
0
|
0
|
|
|
|
($self || $class)->_trace(\@_,2,", self" . |
129
|
|
|
|
|
|
|
(defined $self ? "=$self" : " undefined") . |
130
|
|
|
|
|
|
|
" after sub-new"); |
131
|
0
|
0
|
|
|
|
|
if ($self) { |
132
|
|
|
|
|
|
|
;# no new keys for TCP? |
133
|
|
|
|
|
|
|
# register our socket options |
134
|
0
|
0
|
|
|
|
|
if (%Sopts) { |
135
|
0
|
|
|
|
|
|
$ {*$self}{Sockopts} = { %Sopts } ; |
|
0
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
else { |
138
|
0
|
|
|
|
|
|
$self->register_options('IPPROTO_TCP', IPPROTO_TCP(), \%sockopts); |
139
|
0
|
|
|
|
|
|
%Sopts = %{ $ {*$self}{Sockopts} } ; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
# set our expected parameters |
142
|
0
|
|
|
|
|
|
$self->setparams({IPproto => 'tcp', |
143
|
|
|
|
|
|
|
type => SOCK_STREAM, |
144
|
|
|
|
|
|
|
proto => IPPROTO_TCP},-1); |
145
|
0
|
0
|
|
|
|
|
if ($class eq __PACKAGE__) { |
146
|
0
|
0
|
|
|
|
|
unless ($self->init(@args)) { |
147
|
0
|
|
|
|
|
|
local $!; # protect returned errno value |
148
|
0
|
|
|
|
|
|
undef $self; # against excess closes in perl core |
149
|
0
|
|
|
|
|
|
undef $self; # another statement needed for sequencing |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
} |
153
|
0
|
0
|
0
|
|
|
|
($self || $class)->_trace(0,1," returning " . |
154
|
|
|
|
|
|
|
(defined $self ? "self=$self" : "undef")); |
155
|
0
|
|
|
|
|
|
$self; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
#& _addrinfo($this, $sockaddr, [numeric_only]) : @list |
159
|
|
|
|
|
|
|
sub _addrinfo |
160
|
|
|
|
|
|
|
{ |
161
|
0
|
|
|
0
|
|
|
my($this,@args,@r) = @_; |
162
|
0
|
|
|
|
|
|
@r = $this->SUPER::_addrinfo(@args); |
163
|
0
|
0
|
0
|
|
|
|
unless (!@r or $args[1] or ref($this) or $r[2] ne $r[3]) { |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
164
|
0
|
|
|
|
|
|
$this = getservbyport(htons($r[3]), 'tcp'); |
165
|
0
|
0
|
|
|
|
|
$r[2] = $this if defined $this; |
166
|
|
|
|
|
|
|
} |
167
|
0
|
|
|
|
|
|
@r; |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
1; |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
# autoloaded methods go after the END token (& pod) below |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
__END__ |