[ale] Re: IPv6 programming question

Chuck Huber chuck at cehuber.org
Mon Nov 5 11:14:18 EST 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

ale-request at ale.org wrote:
> Message: 1
> Date: Fri, 02 Nov 2007 13:36:48 -0400

>> int main() 
>> { 
>> int s,r; int ret; 
>> uint16_t val=0; 
>> char *buff; 
>> struct sockaddr_in6 ser; 
>>
>> s = socket(AF_INET6,SOCK_STREAM,PF_INET6); 
>> if ( s <0) 
>>
>>     perror ("socket 6 error"); 
>> else 
>>     /* ser.sin6_addr.s6_addr="fe02::1";  IN6ADDR_ANY_INIT; */ 
>>     ser.sin6_port=htons(2000); 
>>     ser.sin6_family=AF_INET6; 
>>     ser.sin6_flowinfo=0; 
>>     ser.sin6_scope_id=0; 
>>

I assume that there are braces around the else block that are not
posted.  A similar construct is in the server program.  If socket()
fails, you'll get the perror then it'll set the sin6_family and so on,
leaving the sin6_port unset.

>>
>> inet_ntop(int af, const void *src, char *dst, socklen_t cnt */ 
> 
> 	I agree with what Jim pointed out.  What's up with the line above?

>> while(1) 
>> { 
>> printf("Server waiting :) \n\n "); 
>> consd = accept(s,(struct sockaddr*)&cli,(socklen_t*)&(clilen)); 
> 
> 	Accept returns the file descriptor to the accepted socket.
> 
>>         if( consd <-1 ) 
>>             perror("accept error"); 
>>         else 
>>         { 
>>         recv(s,buff,sizeof(buff),0); 
> 
> 	You're doing a recv on the wrong socket.  You should be recv'ing on
> consd.  Socket "s" is your listening socket.

I caught the same thing.  It looks like the braces I pointed out above
have been fixed here.

> 
>>         printf("Received from client data =%s",buff); 
>>         printf("Received from client port =%d",ntohs(cli.sin6_port)); 
>>         break; 
>>         } 
>> } 

Enjoy,
    - Chuck
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHL0FFiR3HaLbYCa4RAiSwAKDeHMT4PYPOBOk+mENgqcCN44t1KwCgtmAc
GMn4adci1tG5FkXlGKxb0fU=
=hfgF
-----END PGP SIGNATURE-----



More information about the Ale mailing list