Yaribz has asked for the wisdom of the Perl Monks concerning the following question:
Hello, I'm trying to retrieve the full TCP_INFO socket structure on a macOS system using Perl.
I have no problem retrieving this structure on other systems (Linux, FreeBSD...) using the getsockopt function, but on these systems the structure is less than 256 bytes long.
On macOS, this structure is supposed to be 292 bytes long (296 with padding), as one can see here. When I try to retrieve this structure from Perl using getsockopt on macOS 12.0.1 (Darwin 21.1.0), I only get 256 bytes of data: the last values are missing from the structure.
Is it due to this code from Perl core, which seems to limit getsockopt results to 256 bytes ? And in this case, what can I do to retrieve the full TCP_INFO structure ?
Here is a code snippet to reproduce the problem on macOS:
Thanks !use Socket qw'PF_INET SOCK_STREAM IPPROTO_TCP inet_aton sockaddr_in'; my $TCP_INFO = ($^O eq 'darwin' ? 0x200 : eval { Socket::TCP_INFO() }) or die "This system doesn't support the TCP_INFO structure.\n"; my ($testHost,$testPort)=('perl.org',443); socket(my $sock, PF_INET, SOCK_STREAM, IPPROTO_TCP) or die "Could not create socket - $!\n"; my $iaddr=inet_aton($testHost); my $paddr=sockaddr_in($testPort,$iaddr); connect($sock,$paddr) or die "Failed to connect to $testHost:$testPort - $!\n"; my $tcpInfoData=getsockopt($sock,IPPROTO_TCP,$TCP_INFO) or die "Error while calling getsockopt - $!\n"; my $tcpInfoLength=length($tcpInfoData); if($tcpInfoLength < 256) { print "This system doesn't have a TCP_INFO structure large enough to + reproduce the problem.\n"; }elsif($tcpInfoLength == 256) { print "The TCP_INFO structure seems to be truncated to 256 bytes on +this system.\n"; }else{ print "This system doesn't seem to be affected by the problem.\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: getsockopt truncating values to 256 bytes ?
by Fletch (Bishop) on May 20, 2022 at 14:34 UTC | |
by Yaribz (Beadle) on May 20, 2022 at 15:54 UTC | |
|
Re: getsockopt truncating values to 256 bytes ?
by stevieb (Canon) on May 21, 2022 at 01:27 UTC | |
by Yaribz (Beadle) on May 21, 2022 at 12:03 UTC |