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

Re: Adding IPv6 to Perl

Thread Previous | Thread Next
From:
Gisle Aas
Date:
August 17, 2001 17:18
Subject:
Re: Adding IPv6 to Perl
Message ID:
lrbsleb4td.fsf@caliper.ActiveState.com
Jeff Okamoto <okamoto@xfiles.corp.hp.com> writes:

> >     addr = SvPV(addrsv, len);
> >     TAINT_PROPER("connect");
> >     if (PerlSock_connect(PerlIO_fileno(IoIFP(io)), (struct sockaddr *)addr, len) >= 0)
> > 	RETPUSHYES;
> >     else
> > 	RETPUSHUNDEF;
> > 
> > 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:
> 
> #ifdef HAS_SOCKADDR_STORAGE
> typedef struct sockaddr_storage		Socket_address;
> #else
> typedef struct sockaddr			Socket_address;
> #endif

How about simply making this:

#ifndef HAS_SOCKADDR_STORAGE
   #define sockaddr_storage sockaddr
#endif

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.

Regards,
Gisle

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About