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

Re: Adding IPv6 to Perl

Thread Previous | Thread Next
From:
Jeff Okamoto
Date:
August 17, 2001 16:22
Subject:
Re: Adding IPv6 to Perl
Message ID:
200108172320.QAA26179@xfiles.corp.hp.com
>     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.
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.

However, doing something like:

#ifdef HAS_SOCKADDR_STORAGE
typedef struct sockaddr_storage		Socket_address;
#else
typedef struct sockaddr			Socket_address;
#endif

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.

Thanks,
Jeff

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