Skip to content

Commit 8e05b9b

Browse files
committed
testing/fulltests/support/myip: Fix a runtime error
Fix the runtime error "Constant subroutine main::AF_INET6 redefined" by using 'require' (evaluated at run-time) instead of 'use' (evaluated at compile-time).
1 parent 7850f5e commit 8e05b9b

File tree

1 file changed

+15
-8
lines changed
  • testing/fulltests/support

1 file changed

+15
-8
lines changed

testing/fulltests/support/myip

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,22 @@
88

99
use strict;
1010
use warnings;
11-
import IO::Socket::INET6;
11+
1212
# For older Perl versions AF_INET6 is defined in the Socket6 package. For newer
1313
# Perl versions all IPv6 functionality we need is defined in the Socket package.
14-
if (eval "use Socket6 qw(AF_INET6 inet_ntop inet_pton pack_sockaddr_in6
15-
sockaddr_in6)") {
16-
use Socket qw(AF_INET SOCK_DGRAM pack_sockaddr_in sockaddr_in);
17-
} else {
18-
use Socket qw(AF_INET AF_INET6 SOCK_DGRAM inet_ntop inet_pton
19-
pack_sockaddr_in pack_sockaddr_in6 sockaddr_in sockaddr_in6);
14+
BEGIN {
15+
# Try to load Socket6
16+
if (eval "require Socket6; Socket6->import(qw(AF_INET6 inet_ntop inet_pton pack_sockaddr_in6 sockaddr_in6)); 1") {
17+
# If loading Socket6 succeeded, only load the v4 parts from Socket.
18+
require Socket;
19+
Socket->import(qw(AF_INET SOCK_DGRAM pack_sockaddr_in sockaddr_in));
20+
} else {
21+
# If loading Socket6 failed, assume a modern Perl where Socket has
22+
# everything.
23+
require Socket;
24+
Socket->import(qw(AF_INET AF_INET6 SOCK_DGRAM inet_ntop inet_pton
25+
pack_sockaddr_in pack_sockaddr_in6 sockaddr_in sockaddr_in6));
26+
}
2027
}
2128

2229

@@ -39,7 +46,7 @@ if ($v6) {
3946
socket(my $sock2, $af, SOCK_DGRAM, 0);
4047
my $i = 1;
4148
while (1) {
42-
bind($sock2, sockaddr_in6(0, $ip6_address, $i)) && last;
49+
bind($sock2, sockaddr_in6($i, $ip6_address)) && last;
4350
$i++;
4451
}
4552
$myip = inet_ntop($af, $ip6_address);

0 commit comments

Comments
 (0)