Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.98k stars 559 forks source link

[doc] Incorrect example for IO::Socket::bind #21138

Open djerius opened 1 year ago

djerius commented 1 year ago

Where

IO::Socket

Description

The example code for the bind method shows incorrect usage of the Socket::pack_sockaddr_in function:

use Socket qw(pack_sockaddr_in);
my $port = 3000;
my $ip_address = '0.0.0.0';
my $packed_addr = pack_sockaddr_in($port, $ip_address);
$sock->bind($packed_addr);

This code resuls in:

Bad arg length for Socket::pack_sockaddr_in, length is 7, should be 4 at reply input line 1.

The $ip_address argument to pack_sockaddr_in must be, according to the docs,

an opaque string (as returned by inet_aton(), or a v-string)

So, either one of these will work

my $ip_address = v0.0.0.0;
my $ip_address = Socket::inet_aton('0.0.0.0');
rwp0 commented 1 year ago

I think you need to raise a ticket here https://rt.cpan.org/Public/Dist/Display.html?Name=Socket for @leonerd to notice.

djerius commented 1 year ago

The docs for IO::Socket say to raise issues here:

AUTHOR Graham Barr. atmark() by Lincoln Stein. Currently maintained by the Perl 5 Porters. Please report all bugs at https://github.com/Perl/perl5/issues.

leonerd commented 1 year ago

Socket is maintained by me. IO::Socket is part of the IO dist, maintained by P5P IO::Socket::IP is maintained by me.

It's highly confusing and awkward, but that is the state of things.

djerius commented 1 year ago

Socket is maintained by me. IO::Socket is part of the IO dist, maintained by P5P IO::Socket::IP is maintained by me.

It's highly confusing and awkward, but that is the state of things.

Confusing, to be sure; the issue is in IO::Socket, so lucky you, it looks like you're off the hook.

rwp0 commented 1 year ago

@djerius

Ah sorry, you're right, but then you can just edit the line on GH and submit a PR:

The IO distribution version (on all modules and in metadata) should probably be updated as well because the tarball hashes will differ.