develooper Front page | perl.perl5.porters | Postings from August 2001

Re: Adding IPv6 to Perl

Thread Previous | Thread Next
Gisle Aas
August 17, 2001 17:18
Re: Adding IPv6 to Perl
Message ID:
Jeff Okamoto <> writes:

> >     addr = SvPV(addrsv, len);
> >     TAINT_PROPER("connect");
> >     if (PerlSock_connect(PerlIO_fileno(IoIFP(io)), (struct sockaddr *)addr, len) >= 0)
> >     else
> > 
> > There is nothing here that knows about 'struct in_addr' for IPv4.  You
> > just pack the correct thing into the 'addrsv' argument and the right
> > stuff is eventually passed down to the OS-level connect().  This means
> > that there is no need to replace perl's connect() function for IPv6.
> Unfortunately, a sockaddr is not large enough to handle an IPv6 structure.

It does not matter for pp_connect or pp_bind.  It does matter for
things like pp_accept that provide a buffer for accept(2) to fill in
and currently use 'struct sockaddr' for that.

> On my system, I see:
> 	Size of struct sockaddr_in is 16 bytes
> 	Size of struct sockaddr_un is 94 bytes
> 	Size of struct sockaddr_in6 is 28 bytes
> 	Size of struct sockaddr is 16 bytes
> 	Size of struct sockaddr_storage is 256 bytes
> The sockaddr_storage structure is new to IPv6, and is supposed to be
> "large enough to accomodate all supported protocol-specific address
> structures".  Unfortunately, this is is only declared on nodes that
> have IPv6.

Do you know the rationale for not simply extending 'struct sockaddr'
instead of introducing 'struct sockaddr_storage'?  What kind of code
would break if 'struct sockaddr' grew?

> However, doing something like:
> typedef struct sockaddr_storage		Socket_address;
> #else
> typedef struct sockaddr			Socket_address;
> #endif

How about simply making this:

   #define sockaddr_storage sockaddr

and then use 'struct sockaddr_storage' where perl allocates sockadd
storage like in pp_accept.

> and using sizeof(Socket_address) instead of sizeof(struct sockaddr)
> may be sufficient to not have to replicate these functions in a module.
> That removes a big chunk from Socket6.

Sounds good.


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About