saru has asked for the wisdom of the Perl Monks concerning the following question:

Having problems to create a server (bind, listen, accept).
I'm stuck with using sockaddr_in6. Someone knows how to populate this structure in order to use it with bind() ?

Program :

use IO::Socket;
use IO::Socket::INET6;
use Socket qw(inet_ntoa);
use Socket6 ( qw(AI_PASSIVE inet_ntop inet_pton getaddrinfo sockaddr_in6 pack_sockaddr_in6 unpack_sockaddr_in6 unpack_sockaddr_in6_all pack_sockaddr_in6_all) );
my $client1 = new IO::Socket
(
Domain => AF_INET6,
Proto => 'udp'
);
my $src1 = sockaddr_in6(0,inet_pton(AF_INET6,'fed0::87'));
my $retVal1 = bind $client1,$src1;
print "Failed to bind\n" if !$retVal;

It is printing "Failed to bind".

Can anyone please help.

Regards,
Saru.

Replies are listed 'Best First'.
Re: Using sockaddr_in6 (bind)
by marto (Cardinal) on Aug 26, 2010 at 11:17 UTC
      Thankyou it worked.
Re: Using sockaddr_in6 (bind)
by roboticus (Chancellor) on Aug 26, 2010 at 10:33 UTC

    saru:

    $retVal1 is a different variable than $retVal. Perhaps correcting that will help you to the next step...

    ...roboticus

Re: Using sockaddr_in6 (bind)
by Anonymous Monk on Aug 26, 2010 at 07:35 UTC
    perldoc IO::Socket::INET6
    $sock = IO::Socket::INET6->new(PeerPort => 9999, PeerAddr => Socket6::inet_ntop(AF_IN +ET6,in6addr_broadcast), Proto => udp, LocalAddr => 'localhost', Broadcast => 1 ) or die "Can't bind : $@\n";

      I am able to create a socket but binding is failing with NULL error