Skip to content

Commit 7056b35

Browse files
committed
Fix sockaddr_family() calls.
As @skaji pointed out, these calls should be on the sockname, not the address. Also, I altered the remaining tests to use IO::Socket::IP rather than IO::Socket so that the prerequisites list would be a bit more concise.
1 parent 4b333e9 commit 7056b35

4 files changed

Lines changed: 9 additions & 5 deletions

File tree

lib/HTTP/Daemon.pm

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,15 @@ sub url {
5555
else {
5656
my $host = $self->sockhostname;
5757
if (!defined $host) {
58-
if (sockaddr_family($addr) eq AF_INET6) {
58+
my $family = sockaddr_family($self->sockname);
59+
if ($family && $family == AF_INET6) {
5960
$host = '[' . inet_ntop(AF_INET6, $addr) . ']';
6061
}
62+
elsif ($family && $family == AF_INET) {
63+
$host = inet_ntop(AF_INET, $addr);
64+
}
6165
else {
62-
$host = inet_ntop(AF_INET6, $addr);
66+
die "Unknown family";
6367
}
6468
}
6569
$url .= $host;

t/local/http.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ unless (-f "CAN_TALK_TO_OURSELF") {
1212

1313
$| = 1; # autoflush
1414

15-
require IO::Socket; # make sure this work before we try to make a HTTP::Daemon
15+
require IO::Socket::IP; # make sure this work before we try to make a HTTP::Daemon
1616

1717
# First we make ourself a daemon in another process
1818
my $D = shift || '';

t/robot/ua-get.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ unless (-f "CAN_TALK_TO_OURSELF") {
1111
}
1212

1313
$| = 1; # autoflush
14-
require IO::Socket; # make sure this work before we try to make a HTTP::Daemon
14+
require IO::Socket::IP; # make sure this work before we try to make a HTTP::Daemon
1515

1616
# First we make ourself a daemon in another process
1717
my $D = shift || '';

t/robot/ua.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ unless (-f "CAN_TALK_TO_OURSELF") {
1111
}
1212

1313
$| = 1; # autoflush
14-
require IO::Socket; # make sure this work before we try to make a HTTP::Daemon
14+
require IO::Socket::IP; # make sure this work before we try to make a HTTP::Daemon
1515

1616
# First we make ourself a daemon in another process
1717
my $D = shift || '';

0 commit comments

Comments
 (0)