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

Re: Adding IPv6 to Perl

Thread Previous | Thread Next
From:
Nick Ing-Simmons
Date:
August 20, 2001 01:10
Subject:
Re: Adding IPv6 to Perl
Message ID:
20010820081022.1542.3@bactrian.ni-s.u-net.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.
>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.

One does not allocate the struct sockaddr - one allocates what one has
and then casts the pointer.  Else how does sockaddr_un work ?


>
>Thanks,
>Jeff
-- 
Nick Ing-Simmons
http://www.ni-s.u-net.com/


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