@@ -7,8 +7,12 @@ use warnings;
77
88our $VERSION = ' 6.05' ;
99
10- use IO::Socket qw( AF_INET INADDR_ANY INADDR_LOOPBACK inet_ntoa) ;
11- our @ISA = qw( IO::Socket::INET) ;
10+ use Socket qw(
11+ AF_INET AF_INET6 INADDR_ANY IN6ADDR_ANY INADDR_LOOPBACK IN6ADDR_LOOPBACK
12+ inet_ntop sockaddr_family
13+ ) ;
14+ use IO::Socket::IP;
15+ our @ISA = qw( IO::Socket::IP) ;
1216
1317our $PROTO = " HTTP/1.1" ;
1418
@@ -38,15 +42,27 @@ sub url {
3842 my $self = shift ;
3943 my $url = $self -> _default_scheme . " ://" ;
4044 my $addr = $self -> sockaddr;
41- if (!$addr || $addr eq INADDR_ANY) {
45+ if (!$addr || $addr eq INADDR_ANY || $addr eq IN6ADDR_ANY ) {
4246 require Sys::Hostname;
4347 $url .= lc Sys::Hostname::hostname();
4448 }
4549 elsif ($addr eq INADDR_LOOPBACK) {
46- $url .= inet_ntoa($addr );
50+ $url .= inet_ntop(AF_INET, $addr );
51+ }
52+ elsif ($addr eq IN6ADDR_LOOPBACK) {
53+ $url .= ' [' . inet_ntop(AF_INET6, $addr ) . ' ]' ;
4754 }
4855 else {
49- $url .= gethostbyaddr ($addr , AF_INET) || inet_ntoa($addr );
56+ my $host = $addr -> sockhostname;
57+ if (!defined $host ) {
58+ if (sockaddr_family($addr ) eq AF_INET6) {
59+ $host = ' [' . inet_ntop(AF_INET6, $addr ) . ' ]' ;
60+ }
61+ else {
62+ $host = inet_ntop(AF_INET6, $addr );
63+ }
64+ }
65+ $url .= $host ;
5066 }
5167 my $port = $self -> sockport;
5268 $url .= " :$port " if $port != $self -> _default_port;
@@ -72,8 +88,8 @@ package # hide from PAUSE
7288use strict;
7389use warnings;
7490
75- use IO::Socket ();
76- our @ISA = qw( IO::Socket::INET ) ;
91+ use IO::Socket::IP ();
92+ our @ISA = qw( IO::Socket::IP ) ;
7793our $DEBUG ;
7894*DEBUG = \$HTTP::Daemon::DEBUG ;
7995
@@ -613,12 +629,12 @@ __END__
613629
614630Instances of the C<HTTP::Daemon > class are HTTP/1.1 servers that
615631listen on a socket for incoming requests. The C<HTTP::Daemon > is a
616- subclass of C<IO::Socket::INET > , so you can perform socket operations
632+ subclass of C<IO::Socket::IP > , so you can perform socket operations
617633directly on it too.
618634
619635The accept() method will return when a connection from a client is
620636available. The returned value will be an C<HTTP::Daemon::ClientConn >
621- object which is another C<IO::Socket::INET > subclass. Calling the
637+ object which is another C<IO::Socket::IP > subclass. Calling the
622638get_request() method on this object will read data from the client and
623639return an C<HTTP::Request > object. The ClientConn object also provide
624640methods to send back various responses.
@@ -629,7 +645,7 @@ desirable. Also note that the user is responsible for generating
629645responses that conform to the HTTP/1.1 protocol.
630646
631647The following methods of C<HTTP::Daemon > are new (or enhanced) relative
632- to the C<IO::Socket::INET > base class:
648+ to the C<IO::Socket::IP > base class:
633649
634650=over 4
635651
@@ -638,7 +654,7 @@ to the C<IO::Socket::INET> base class:
638654=item $d = HTTP::Daemon->new( %opts )
639655
640656The constructor method takes the same arguments as the
641- C<IO::Socket::INET > constructor, but unlike its base class it can also
657+ C<IO::Socket::IP > constructor, but unlike its base class it can also
642658be called without any arguments. The daemon will then set up a listen
643659queue of 5 connections and allocate some random port number.
644660
@@ -650,7 +666,7 @@ HTTP port will be constructed like this:
650666 LocalPort => 80,
651667 );
652668
653- See L<IO::Socket::INET > for a description of other arguments that can
669+ See L<IO::Socket::IP > for a description of other arguments that can
654670be used configure the daemon during construction.
655671
656672=item $c = $d->accept
@@ -667,7 +683,7 @@ class a subclass of C<HTTP::Daemon::ClientConn>.
667683
668684The accept method will return C<undef > if timeouts have been enabled
669685and no connection is made within the given time. The timeout() method
670- is described in L<IO::Socket> .
686+ is described in L<IO::Socket::IP > .
671687
672688In list context both the client object and the peer address will be
673689returned; see the description of the accept method L<IO::Socket> for
@@ -689,7 +705,7 @@ replaced with the version number of this module.
689705
690706=back
691707
692- The C<HTTP::Daemon::ClientConn > is a C<IO::Socket::INET >
708+ The C<HTTP::Daemon::ClientConn > is a C<IO::Socket::IP >
693709subclass. Instances of this class are returned by the accept() method
694710of C<HTTP::Daemon > . The following methods are provided:
695711
@@ -863,6 +879,6 @@ Return a reference to the corresponding C<HTTP::Daemon> object.
863879
864880RFC 2616
865881
866- L<IO::Socket::INET > , L<IO::Socket>
882+ L<IO::Socket::IP > , L<IO::Socket>
867883
868884=cut
0 commit comments