diff options
-rw-r--r-- | pp_sys.c | 2 | ||||
-rw-r--r-- | t/io/socket.t | 26 |
2 files changed, 27 insertions, 1 deletions
@@ -2723,7 +2723,7 @@ PP(pp_ssockopt) const char *buf; int aint; SvGETMAGIC(sv); - if (SvPOKp(sv)) { + if (SvPOK(sv)) { /* sv is originally a string */ STRLEN l; buf = SvPVbyte_nomg(sv, l); len = l; diff --git a/t/io/socket.t b/t/io/socket.t index 6eb44fa91d..049e282703 100644 --- a/t/io/socket.t +++ b/t/io/socket.t @@ -309,6 +309,32 @@ SKIP: "check SO_REUSEADDR set correctly"); } +# GH #18642 - test whether setsockopt works with a numeric OPTVAL which also +# has a cached stringified value +SKIP: { + defined(my $IPPROTO_IP = eval { Socket::IPPROTO_IP() }) + or skip 'no IPPROTO_IP', 4; + defined(my $IP_TTL = eval { Socket::IP_TTL() }) + or skip 'no IP_TTL', 4; + + my $sock; + socket($sock, PF_INET, SOCK_STREAM, $tcp) or BAIL_OUT "socket: $!"; + + my $ttl = 7; + my $integer_only_ttl = 0 + $ttl; + ok(setsockopt($sock, $IPPROTO_IP, $IP_TTL, $integer_only_ttl), + 'setsockopt with an integer-only OPTVAL'); + my $set_ttl = getsockopt($sock, $IPPROTO_IP, $IP_TTL); + is(unpack('i', $set_ttl // ''), $ttl, 'TTL set to desired value'); + + my $also_string_ttl = $ttl; + my $string = "$also_string_ttl"; + ok(setsockopt($sock, $IPPROTO_IP, $IP_TTL, $also_string_ttl), + 'setsockopt with an integer OPTVAL with stringified value'); + $set_ttl = getsockopt($sock, $IPPROTO_IP, $IP_TTL); + is(unpack('i', $set_ttl // ''), $ttl, 'TTL set to desired value'); +} + done_testing(); my @child_tests; |