ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/lib/AnyEvent/Socket.pm
(Generate patch)

Comparing AnyEvent/lib/AnyEvent/Socket.pm (file contents):
Revision 1.11 by root, Fri May 23 20:09:56 2008 UTC vs.
Revision 1.14 by root, Fri May 23 23:37:13 2008 UTC

35 35
36BEGIN { 36BEGIN {
37 *socket_inet_aton = \&Socket::inet_aton; # take a copy, in case Coro::LWP overrides it 37 *socket_inet_aton = \&Socket::inet_aton; # take a copy, in case Coro::LWP overrides it
38} 38}
39 39
40our @EXPORT = qw(inet_aton tcp_server tcp_connect); 40our @EXPORT = qw(parse_ipv4 parse_ipv6 parse_ip format_ip inet_aton tcp_server tcp_connect);
41 41
42our $VERSION = '1.0'; 42our $VERSION = '1.0';
43 43
44=item $ipn = parse_ipv4 $dotted_quad 44=item $ipn = parse_ipv4 $dotted_quad
45 45
67 + ($_[0] << 24) 67 + ($_[0] << 24)
68 + ($_[1] << 16) 68 + ($_[1] << 16)
69 + ($_[2] << 8); 69 + ($_[2] << 8);
70} 70}
71 71
72=item $ipn = parse_ipv4 $dotted_quad 72=item $ipn = parse_ipv6 $textual_ipv6_address
73 73
74Tries to parse the given IPv6 address and return it in 74Tries to parse the given IPv6 address and return it in
75octet form (or undef when it isn't in a parsable format). 75octet form (or undef when it isn't in a parsable format).
76 76
77Should support all forms specified by RFC 2373 (and additionally all IPv4 77Should support all forms specified by RFC 2373 (and additionally all IPv4
78formst supported by parse_ipv4). 78forms supported by parse_ipv4).
79
80This function works similarly to C<inet_pton AF_INET6, ...>.
79 81
80=cut 82=cut
81 83
82sub parse_ipv6($) { 84sub parse_ipv6($) {
83 # quick test to avoid longer processing 85 # quick test to avoid longer processing
91 } 93 }
92 94
93 my @h = split /:/, $h; 95 my @h = split /:/, $h;
94 my @t = split /:/, $t; 96 my @t = split /:/, $t;
95 97
96 # check four ipv4 tail 98 # check for ipv4 tail
97 if (@t && $t[-1]=~ /\./) { 99 if (@t && $t[-1]=~ /\./) {
98 return undef if $n > 6; 100 return undef if $n > 6;
99 101
100 my $ipn = parse_ipv4 pop @t 102 my $ipn = parse_ipv4 pop @t
101 or return undef; 103 or return undef;
128 130
129=item $text = format_ip $ipn 131=item $text = format_ip $ipn
130 132
131Takes either an IPv4 address (4 octets) or and IPv6 address (16 octets) 133Takes either an IPv4 address (4 octets) or and IPv6 address (16 octets)
132and converts it into textual form. 134and converts it into textual form.
135
136This function works similarly to C<inet_ntop AF_INET || AF_INET6, ...>,
137except it automatically detects the address type.
133 138
134=cut 139=cut
135 140
136sub format_ip; 141sub format_ip;
137sub format_ip($) { 142sub format_ip($) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines