xref: /openbsd-src/gnu/usr.bin/perl/dist/IO/lib/IO/Socket/INET.pm (revision 3d61058aa5c692477b6d18acfbbdb653a9930ff9)
1b39c5158Smillert# IO::Socket::INET.pm
2b39c5158Smillert#
3b39c5158Smillert# Copyright (c) 1997-8 Graham Barr <gbarr@pobox.com>. All rights reserved.
4b39c5158Smillert# This program is free software; you can redistribute it and/or
5b39c5158Smillert# modify it under the same terms as Perl itself.
6b39c5158Smillert
7b39c5158Smillertpackage IO::Socket::INET;
8b39c5158Smillert
9b39c5158Smillertuse strict;
10b39c5158Smillertuse IO::Socket;
11b39c5158Smillertuse Socket;
12b39c5158Smillertuse Carp;
13b39c5158Smillertuse Exporter;
14b39c5158Smillertuse Errno;
15b39c5158Smillert
169f11ffb7Safresh1our @ISA = qw(IO::Socket);
17*3d61058aSafresh1our $VERSION = "1.55";
18b39c5158Smillert
19b39c5158Smillertmy $EINVAL = exists(&Errno::EINVAL) ? Errno::EINVAL() : 1;
20b39c5158Smillert
21b39c5158SmillertIO::Socket::INET->register_domain( AF_INET );
22b39c5158Smillert
23b39c5158Smillertmy %socket_type = ( tcp  => SOCK_STREAM,
24b39c5158Smillert		    udp  => SOCK_DGRAM,
25b39c5158Smillert		    icmp => SOCK_RAW
26b39c5158Smillert		  );
27b39c5158Smillertmy %proto_number;
28b39c5158Smillert$proto_number{tcp}  = Socket::IPPROTO_TCP()  if defined &Socket::IPPROTO_TCP;
29b39c5158Smillert$proto_number{udp}  = Socket::IPPROTO_UDP()  if defined &Socket::IPPROTO_UDP;
30b39c5158Smillert$proto_number{icmp} = Socket::IPPROTO_ICMP() if defined &Socket::IPPROTO_ICMP;
31b39c5158Smillertmy %proto_name = reverse %proto_number;
32b39c5158Smillert
33b39c5158Smillertsub new {
34b39c5158Smillert    my $class = shift;
35b39c5158Smillert    unshift(@_, "PeerAddr") if @_ == 1;
36b39c5158Smillert    return $class->SUPER::new(@_);
37b39c5158Smillert}
38b39c5158Smillert
39b39c5158Smillertsub _cache_proto {
40b39c5158Smillert    my @proto = @_;
41b39c5158Smillert    for (map lc($_), $proto[0], split(' ', $proto[1])) {
42b39c5158Smillert	$proto_number{$_} = $proto[2];
43b39c5158Smillert    }
44b39c5158Smillert    $proto_name{$proto[2]} = $proto[0];
45b39c5158Smillert}
46b39c5158Smillert
47b39c5158Smillertsub _get_proto_number {
48b39c5158Smillert    my $name = lc(shift);
49b39c5158Smillert    return undef unless defined $name;
50b39c5158Smillert    return $proto_number{$name} if exists $proto_number{$name};
51b39c5158Smillert
526fb12b70Safresh1    my @proto = eval { getprotobyname($name) };
53b39c5158Smillert    return undef unless @proto;
54b39c5158Smillert    _cache_proto(@proto);
55b39c5158Smillert
56b39c5158Smillert    return $proto[2];
57b39c5158Smillert}
58b39c5158Smillert
59b39c5158Smillertsub _get_proto_name {
60b39c5158Smillert    my $num = shift;
61b39c5158Smillert    return undef unless defined $num;
62b39c5158Smillert    return $proto_name{$num} if exists $proto_name{$num};
63b39c5158Smillert
646fb12b70Safresh1    my @proto = eval { getprotobynumber($num) };
65b39c5158Smillert    return undef unless @proto;
66b39c5158Smillert    _cache_proto(@proto);
67b39c5158Smillert
68b39c5158Smillert    return $proto[0];
69b39c5158Smillert}
70b39c5158Smillert
71b39c5158Smillertsub _sock_info {
72b39c5158Smillert  my($addr,$port,$proto) = @_;
73b39c5158Smillert  my $origport = $port;
74b39c5158Smillert  my @serv = ();
75b39c5158Smillert
76b39c5158Smillert  $port = $1
77b39c5158Smillert	if(defined $addr && $addr =~ s,:([\w\(\)/]+)$,,);
78b39c5158Smillert
79b39c5158Smillert  if(defined $proto  && $proto =~ /\D/) {
80b39c5158Smillert    my $num = _get_proto_number($proto);
81b39c5158Smillert    unless (defined $num) {
82eac174f2Safresh1      $IO::Socket::errstr = $@ = "Bad protocol '$proto'";
83b39c5158Smillert      return;
84b39c5158Smillert    }
85b39c5158Smillert    $proto = $num;
86b39c5158Smillert  }
87b39c5158Smillert
88b39c5158Smillert  if(defined $port) {
89b39c5158Smillert    my $defport = ($port =~ s,\((\d+)\)$,,) ? $1 : undef;
90b39c5158Smillert    my $pnum = ($port =~ m,^(\d+)$,)[0];
91b39c5158Smillert
92b39c5158Smillert    @serv = getservbyname($port, _get_proto_name($proto) || "")
93b39c5158Smillert	if ($port =~ m,\D,);
94b39c5158Smillert
95b39c5158Smillert    $port = $serv[2] || $defport || $pnum;
96b39c5158Smillert    unless (defined $port) {
97eac174f2Safresh1	$IO::Socket::errstr = $@ = "Bad service '$origport'";
98b39c5158Smillert	return;
99b39c5158Smillert    }
100b39c5158Smillert
101b39c5158Smillert    $proto = _get_proto_number($serv[3]) if @serv && !$proto;
102b39c5158Smillert  }
103b39c5158Smillert
104b39c5158Smillert return ($addr || undef,
105b39c5158Smillert	 $port || undef,
106b39c5158Smillert	 $proto || undef
107b39c5158Smillert	);
108b39c5158Smillert}
109b39c5158Smillert
110b39c5158Smillertsub _error {
111b39c5158Smillert    my $sock = shift;
112b39c5158Smillert    my $err = shift;
113b39c5158Smillert    {
114b39c5158Smillert      local($!);
115b39c5158Smillert      my $title = ref($sock).": ";
116eac174f2Safresh1      $IO::Socket::errstr = $@ = join("", $_[0] =~ /^$title/ ? "" : $title, @_);
117b39c5158Smillert      $sock->close()
118b39c5158Smillert	if(defined fileno($sock));
119b39c5158Smillert    }
120b39c5158Smillert    $! = $err;
121b39c5158Smillert    return undef;
122b39c5158Smillert}
123b39c5158Smillert
124b39c5158Smillertsub _get_addr {
125b39c5158Smillert    my($sock,$addr_str, $multi) = @_;
126b39c5158Smillert    my @addr;
127b39c5158Smillert    if ($multi && $addr_str !~ /^\d+(?:\.\d+){3}$/) {
128b39c5158Smillert	(undef, undef, undef, undef, @addr) = gethostbyname($addr_str);
129b39c5158Smillert    } else {
130b39c5158Smillert	my $h = inet_aton($addr_str);
131b39c5158Smillert	push(@addr, $h) if defined $h;
132b39c5158Smillert    }
133b39c5158Smillert    @addr;
134b39c5158Smillert}
135b39c5158Smillert
136b39c5158Smillertsub configure {
137b39c5158Smillert    my($sock,$arg) = @_;
138b39c5158Smillert    my($lport,$rport,$laddr,$raddr,$proto,$type);
139b39c5158Smillert
140b39c5158Smillert
141b39c5158Smillert    $arg->{LocalAddr} = $arg->{LocalHost}
142b39c5158Smillert	if exists $arg->{LocalHost} && !exists $arg->{LocalAddr};
143b39c5158Smillert
144b39c5158Smillert    ($laddr,$lport,$proto) = _sock_info($arg->{LocalAddr},
145b39c5158Smillert					$arg->{LocalPort},
146b39c5158Smillert					$arg->{Proto})
147b39c5158Smillert			or return _error($sock, $!, $@);
148b39c5158Smillert
149b39c5158Smillert    $laddr = defined $laddr ? inet_aton($laddr)
150b39c5158Smillert			    : INADDR_ANY;
151b39c5158Smillert
152b39c5158Smillert    return _error($sock, $EINVAL, "Bad hostname '",$arg->{LocalAddr},"'")
153b39c5158Smillert	unless(defined $laddr);
154b39c5158Smillert
155b39c5158Smillert    $arg->{PeerAddr} = $arg->{PeerHost}
156b39c5158Smillert	if exists $arg->{PeerHost} && !exists $arg->{PeerAddr};
157b39c5158Smillert
158b39c5158Smillert    unless(exists $arg->{Listen}) {
159b39c5158Smillert	($raddr,$rport,$proto) = _sock_info($arg->{PeerAddr},
160b39c5158Smillert					    $arg->{PeerPort},
161b39c5158Smillert					    $proto)
162b39c5158Smillert			or return _error($sock, $!, $@);
163b39c5158Smillert    }
164b39c5158Smillert
165b39c5158Smillert    $proto ||= _get_proto_number('tcp');
166b39c5158Smillert
167b39c5158Smillert    $type = $arg->{Type} || $socket_type{lc _get_proto_name($proto)};
168b39c5158Smillert
169b39c5158Smillert    my @raddr = ();
170b39c5158Smillert
171b39c5158Smillert    if(defined $raddr) {
172b39c5158Smillert	@raddr = $sock->_get_addr($raddr, $arg->{MultiHomed});
173b39c5158Smillert	return _error($sock, $EINVAL, "Bad hostname '",$arg->{PeerAddr},"'")
174b39c5158Smillert	    unless @raddr;
175b39c5158Smillert    }
176b39c5158Smillert
177b39c5158Smillert    while(1) {
178b39c5158Smillert
179b39c5158Smillert	$sock->socket(AF_INET, $type, $proto) or
180b39c5158Smillert	    return _error($sock, $!, "$!");
181b39c5158Smillert
182b39c5158Smillert        if (defined $arg->{Blocking}) {
183b39c5158Smillert	    defined $sock->blocking($arg->{Blocking})
184b39c5158Smillert		or return _error($sock, $!, "$!");
185b39c5158Smillert	}
186b39c5158Smillert
187b39c5158Smillert	if ($arg->{Reuse} || $arg->{ReuseAddr}) {
188b39c5158Smillert	    $sock->sockopt(SO_REUSEADDR,1) or
189b39c5158Smillert		    return _error($sock, $!, "$!");
190b39c5158Smillert	}
191b39c5158Smillert
192b39c5158Smillert	if ($arg->{ReusePort}) {
193b39c5158Smillert	    $sock->sockopt(SO_REUSEPORT,1) or
194b39c5158Smillert		    return _error($sock, $!, "$!");
195b39c5158Smillert	}
196b39c5158Smillert
197b39c5158Smillert	if ($arg->{Broadcast}) {
198b39c5158Smillert		$sock->sockopt(SO_BROADCAST,1) or
199b39c5158Smillert		    return _error($sock, $!, "$!");
200b39c5158Smillert	}
201b39c5158Smillert
202b39c5158Smillert	if($lport || ($laddr ne INADDR_ANY) || exists $arg->{Listen}) {
203b39c5158Smillert	    $sock->bind($lport || 0, $laddr) or
204b39c5158Smillert		    return _error($sock, $!, "$!");
205b39c5158Smillert	}
206b39c5158Smillert
207b39c5158Smillert	if(exists $arg->{Listen}) {
208b39c5158Smillert	    $sock->listen($arg->{Listen} || 5) or
209b39c5158Smillert		return _error($sock, $!, "$!");
210b39c5158Smillert	    last;
211b39c5158Smillert	}
212b39c5158Smillert
213b39c5158Smillert 	# don't try to connect unless we're given a PeerAddr
214b39c5158Smillert 	last unless exists($arg->{PeerAddr});
215b39c5158Smillert
216b39c5158Smillert        $raddr = shift @raddr;
217b39c5158Smillert
218b39c5158Smillert	return _error($sock, $EINVAL, 'Cannot determine remote port')
219b39c5158Smillert		unless($rport || $type == SOCK_DGRAM || $type == SOCK_RAW);
220b39c5158Smillert
221b39c5158Smillert	last
222b39c5158Smillert	    unless($type == SOCK_STREAM || defined $raddr);
223b39c5158Smillert
224b39c5158Smillert	return _error($sock, $EINVAL, "Bad hostname '",$arg->{PeerAddr},"'")
225b39c5158Smillert	    unless defined $raddr;
226b39c5158Smillert
227b39c5158Smillert#        my $timeout = ${*$sock}{'io_socket_timeout'};
228b39c5158Smillert#        my $before = time() if $timeout;
229b39c5158Smillert
230b39c5158Smillert	undef $@;
231b39c5158Smillert        if ($sock->connect(pack_sockaddr_in($rport, $raddr))) {
232b39c5158Smillert#            ${*$sock}{'io_socket_timeout'} = $timeout;
233b39c5158Smillert            return $sock;
234b39c5158Smillert        }
235b39c5158Smillert
236b39c5158Smillert	return _error($sock, $!, $@ || "Timeout")
237b39c5158Smillert	    unless @raddr;
238b39c5158Smillert
239b39c5158Smillert#	if ($timeout) {
240b39c5158Smillert#	    my $new_timeout = $timeout - (time() - $before);
241b39c5158Smillert#	    return _error($sock,
242b39c5158Smillert#                         (exists(&Errno::ETIMEDOUT) ? Errno::ETIMEDOUT() : $EINVAL),
243b39c5158Smillert#                         "Timeout") if $new_timeout <= 0;
244b39c5158Smillert#	    ${*$sock}{'io_socket_timeout'} = $new_timeout;
245b39c5158Smillert#        }
246b39c5158Smillert
247b39c5158Smillert    }
248b39c5158Smillert
249b39c5158Smillert    $sock;
250b39c5158Smillert}
251b39c5158Smillert
252b39c5158Smillertsub connect {
253b39c5158Smillert    @_ == 2 || @_ == 3 or
254b39c5158Smillert       croak 'usage: $sock->connect(NAME) or $sock->connect(PORT, ADDR)';
255b39c5158Smillert    my $sock = shift;
256b39c5158Smillert    return $sock->SUPER::connect(@_ == 1 ? shift : pack_sockaddr_in(@_));
257b39c5158Smillert}
258b39c5158Smillert
259b39c5158Smillertsub bind {
260b39c5158Smillert    @_ == 2 || @_ == 3 or
261b39c5158Smillert       croak 'usage: $sock->bind(NAME) or $sock->bind(PORT, ADDR)';
262b39c5158Smillert    my $sock = shift;
263b39c5158Smillert    return $sock->SUPER::bind(@_ == 1 ? shift : pack_sockaddr_in(@_))
264b39c5158Smillert}
265b39c5158Smillert
266b39c5158Smillertsub sockaddr {
267b39c5158Smillert    @_ == 1 or croak 'usage: $sock->sockaddr()';
268b39c5158Smillert    my($sock) = @_;
269b39c5158Smillert    my $name = $sock->sockname;
270b39c5158Smillert    $name ? (sockaddr_in($name))[1] : undef;
271b39c5158Smillert}
272b39c5158Smillert
273b39c5158Smillertsub sockport {
274b39c5158Smillert    @_ == 1 or croak 'usage: $sock->sockport()';
275b39c5158Smillert    my($sock) = @_;
276b39c5158Smillert    my $name = $sock->sockname;
277b39c5158Smillert    $name ? (sockaddr_in($name))[0] : undef;
278b39c5158Smillert}
279b39c5158Smillert
280b39c5158Smillertsub sockhost {
281b39c5158Smillert    @_ == 1 or croak 'usage: $sock->sockhost()';
282b39c5158Smillert    my($sock) = @_;
283b39c5158Smillert    my $addr = $sock->sockaddr;
284b39c5158Smillert    $addr ? inet_ntoa($addr) : undef;
285b39c5158Smillert}
286b39c5158Smillert
287b39c5158Smillertsub peeraddr {
288b39c5158Smillert    @_ == 1 or croak 'usage: $sock->peeraddr()';
289b39c5158Smillert    my($sock) = @_;
290b39c5158Smillert    my $name = $sock->peername;
291b39c5158Smillert    $name ? (sockaddr_in($name))[1] : undef;
292b39c5158Smillert}
293b39c5158Smillert
294b39c5158Smillertsub peerport {
295b39c5158Smillert    @_ == 1 or croak 'usage: $sock->peerport()';
296b39c5158Smillert    my($sock) = @_;
297b39c5158Smillert    my $name = $sock->peername;
298b39c5158Smillert    $name ? (sockaddr_in($name))[0] : undef;
299b39c5158Smillert}
300b39c5158Smillert
301b39c5158Smillertsub peerhost {
302b39c5158Smillert    @_ == 1 or croak 'usage: $sock->peerhost()';
303b39c5158Smillert    my($sock) = @_;
304b39c5158Smillert    my $addr = $sock->peeraddr;
305b39c5158Smillert    $addr ? inet_ntoa($addr) : undef;
306b39c5158Smillert}
307b39c5158Smillert
308b39c5158Smillert1;
309b39c5158Smillert
310b39c5158Smillert__END__
311b39c5158Smillert
312b39c5158Smillert=head1 NAME
313b39c5158Smillert
314b39c5158SmillertIO::Socket::INET - Object interface for AF_INET domain sockets
315b39c5158Smillert
316b39c5158Smillert=head1 SYNOPSIS
317b39c5158Smillert
318b39c5158Smillert    use IO::Socket::INET;
319b39c5158Smillert
320b39c5158Smillert=head1 DESCRIPTION
321b39c5158Smillert
322b39c5158SmillertC<IO::Socket::INET> provides an object interface to creating and using sockets
323b39c5158Smillertin the AF_INET domain. It is built upon the L<IO::Socket> interface and
324b39c5158Smillertinherits all the methods defined by L<IO::Socket>.
325b39c5158Smillert
326b39c5158Smillert=head1 CONSTRUCTOR
327b39c5158Smillert
328b39c5158Smillert=over 4
329b39c5158Smillert
330b39c5158Smillert=item new ( [ARGS] )
331b39c5158Smillert
332b39c5158SmillertCreates an C<IO::Socket::INET> object, which is a reference to a
333e0680481Safresh1newly created symbol (see the L<Symbol> package). C<new>
334b39c5158Smillertoptionally takes arguments, these arguments are in key-value pairs.
335b39c5158Smillert
336b39c5158SmillertIn addition to the key-value pairs accepted by L<IO::Socket>,
337b39c5158SmillertC<IO::Socket::INET> provides.
338b39c5158Smillert
339b39c5158Smillert
340b39c5158Smillert PeerAddr    Remote host address          <hostname>[:<port>]
341b39c5158Smillert PeerHost    Synonym for PeerAddr
342b39c5158Smillert PeerPort    Remote port or service       <service>[(<no>)] | <no>
343b39c5158Smillert LocalAddr   Local host bind address      hostname[:port]
344b39c5158Smillert LocalHost   Synonym for LocalAddr
345b39c5158Smillert LocalPort   Local host bind port         <service>[(<no>)] | <no>
346b39c5158Smillert Proto       Protocol name (or number)    "tcp" | "udp" | ...
347b39c5158Smillert Type        Socket type              SOCK_STREAM | SOCK_DGRAM | ...
348b39c5158Smillert Listen      Queue size for listen
349b39c5158Smillert ReuseAddr   Set SO_REUSEADDR before binding
350898184e3Ssthen Reuse       Set SO_REUSEADDR before binding (deprecated,
351898184e3Ssthen                                              prefer ReuseAddr)
352b39c5158Smillert ReusePort   Set SO_REUSEPORT before binding
353b39c5158Smillert Broadcast   Set SO_BROADCAST before binding
354b39c5158Smillert Timeout     Timeout value for various operations
355b39c5158Smillert MultiHomed  Try all addresses for multi-homed hosts
356b39c5158Smillert Blocking    Determine if connection will be blocking mode
357b39c5158Smillert
358b39c5158SmillertIf C<Listen> is defined then a listen socket is created, else if the
359b39c5158Smillertsocket type, which is derived from the protocol, is SOCK_STREAM then
3606fb12b70Safresh1connect() is called.  If the C<Listen> argument is given, but false,
3616fb12b70Safresh1the queue size will be set to 5.
362b39c5158Smillert
363b39c5158SmillertAlthough it is not illegal, the use of C<MultiHomed> on a socket
364b39c5158Smillertwhich is in non-blocking mode is of little use. This is because the
365b39c5158Smillertfirst connect will never fail with a timeout as the connect call
366b39c5158Smillertwill not block.
367b39c5158Smillert
368b39c5158SmillertThe C<PeerAddr> can be a hostname or the IP-address on the
369b39c5158Smillert"xx.xx.xx.xx" form.  The C<PeerPort> can be a number or a symbolic
370b39c5158Smillertservice name.  The service name might be followed by a number in
371b39c5158Smillertparenthesis which is used if the service is not known by the system.
372b39c5158SmillertThe C<PeerPort> specification can also be embedded in the C<PeerAddr>
373b39c5158Smillertby preceding it with a ":".
374b39c5158Smillert
375b39c5158SmillertIf C<Proto> is not given and you specify a symbolic C<PeerPort> port,
376b39c5158Smillertthen the constructor will try to derive C<Proto> from the service
377b39c5158Smillertname.  As a last resort C<Proto> "tcp" is assumed.  The C<Type>
378b39c5158Smillertparameter will be deduced from C<Proto> if not specified.
379b39c5158Smillert
380b39c5158SmillertIf the constructor is only passed a single argument, it is assumed to
381b39c5158Smillertbe a C<PeerAddr> specification.
382b39c5158Smillert
383b39c5158SmillertIf C<Blocking> is set to 0, the connection will be in nonblocking mode.
384b39c5158SmillertIf not specified it defaults to 1 (blocking mode).
385b39c5158Smillert
386b39c5158SmillertExamples:
387b39c5158Smillert
388b39c5158Smillert   $sock = IO::Socket::INET->new(PeerAddr => 'www.perl.org',
389b39c5158Smillert                                 PeerPort => 'http(80)',
390b39c5158Smillert                                 Proto    => 'tcp');
391b39c5158Smillert
392b39c5158Smillert   $sock = IO::Socket::INET->new(PeerAddr => 'localhost:smtp(25)');
393b39c5158Smillert
394b39c5158Smillert   $sock = IO::Socket::INET->new(Listen    => 5,
395b39c5158Smillert                                 LocalAddr => 'localhost',
396b39c5158Smillert                                 LocalPort => 9000,
397b39c5158Smillert                                 Proto     => 'tcp');
398b39c5158Smillert
399b39c5158Smillert   $sock = IO::Socket::INET->new('127.0.0.1:25');
400b39c5158Smillert
401898184e3Ssthen   $sock = IO::Socket::INET->new(
402898184e3Ssthen                           PeerPort  => 9999,
403b39c5158Smillert                           PeerAddr  => inet_ntoa(INADDR_BROADCAST),
404eac174f2Safresh1                           Proto     => 'udp',
405b39c5158Smillert                           LocalAddr => 'localhost',
406b39c5158Smillert                           Broadcast => 1 )
407eac174f2Safresh1                       or die "Can't bind : $IO::Socket::errstr\n";
408b39c5158Smillert
409eac174f2Safresh1If the constructor fails it will return C<undef> and set the
410eac174f2Safresh1C<$IO::Socket::errstr> package variable to contain an error message.
411b39c5158Smillert
412eac174f2Safresh1    $sock = IO::Socket::INET->new(...)
413eac174f2Safresh1        or die "Cannot create socket - $IO::Socket::errstr\n";
414b39c5158Smillert
415eac174f2Safresh1For legacy reasons the error message is also set into the global C<$@>
416eac174f2Safresh1variable, and you may still find older code which looks here instead.
417eac174f2Safresh1
418eac174f2Safresh1    $sock = IO::Socket::INET->new(...)
419eac174f2Safresh1        or die "Cannot create socket - $@\n";
420b39c5158Smillert
421b39c5158Smillert=back
422b39c5158Smillert
423b39c5158Smillert=head2 METHODS
424b39c5158Smillert
425b39c5158Smillert=over 4
426b39c5158Smillert
427b39c5158Smillert=item sockaddr ()
428b39c5158Smillert
429b39c5158SmillertReturn the address part of the sockaddr structure for the socket
430b39c5158Smillert
431b39c5158Smillert=item sockport ()
432b39c5158Smillert
433b39c5158SmillertReturn the port number that the socket is using on the local host
434b39c5158Smillert
435b39c5158Smillert=item sockhost ()
436b39c5158Smillert
437b39c5158SmillertReturn the address part of the sockaddr structure for the socket in a
438b39c5158Smillerttext form xx.xx.xx.xx
439b39c5158Smillert
440b39c5158Smillert=item peeraddr ()
441b39c5158Smillert
442b39c5158SmillertReturn the address part of the sockaddr structure for the socket on
443b39c5158Smillertthe peer host
444b39c5158Smillert
445b39c5158Smillert=item peerport ()
446b39c5158Smillert
447b39c5158SmillertReturn the port number for the socket on the peer host.
448b39c5158Smillert
449b39c5158Smillert=item peerhost ()
450b39c5158Smillert
451b39c5158SmillertReturn the address part of the sockaddr structure for the socket on the
452b39c5158Smillertpeer host in a text form xx.xx.xx.xx
453b39c5158Smillert
454b39c5158Smillert=back
455b39c5158Smillert
456b39c5158Smillert=head1 SEE ALSO
457b39c5158Smillert
458b39c5158SmillertL<Socket>, L<IO::Socket>
459b39c5158Smillert
460b39c5158Smillert=head1 AUTHOR
461b39c5158Smillert
462b39c5158SmillertGraham Barr. Currently maintained by the Perl Porters.  Please report all
463eac174f2Safresh1bugs at L<https://github.com/Perl/perl5/issues>.
464b39c5158Smillert
465b39c5158Smillert=head1 COPYRIGHT
466b39c5158Smillert
467b39c5158SmillertCopyright (c) 1996-8 Graham Barr <gbarr@pobox.com>. All rights reserved.
468b39c5158SmillertThis program is free software; you can redistribute it and/or
469b39c5158Smillertmodify it under the same terms as Perl itself.
470b39c5158Smillert
471b39c5158Smillert=cut
472