[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ale] IPv6 programming question



More.....

On Fri, 2007-11-02 at 10:14 +0530, Srikanth Pokkuluri wrote:
> SERVER PROGRAM 
> int main() 
> { 
> int s,consd; int ret; 
> uint16_t val=0; 
> char buff[20]; 
> struct sockaddr_in6 ser,cli;  char ipAddr[128]; 
> socklen_t   t,clilen; 
> s = socket(AF_INET6,SOCK_STREAM,IPPROTO_TCP6); 
> if ( s <0) 
> 
>     perror ("socket 6 error"); 
> else 
>     ser.sin6_port=htons(2000); 
>     ser.sin6_family=AF_INET6; 
>     ser.sin6_flowinfo=0; 
>     ser.sin6_scope_id=0; 
> 
>   //inet_pton(AF_INET6,"fe80000000000000020795fffee4801f",&(ser.sin6_addr)); 
>     inet_pton(AF_INET6,"::1",&(ser.sin6_addr)); 
>     t = sizeof(struct sockaddr_in6); 
>     ret = bind(s,(struct sockaddr*)&ser,(struct sockaddr*)t); 
>     if( ret <0) 
> listen(s,5); 
> clilen = sizeof(struct sockaddr_in6); 
> memset(buff,'\0',sizeof(buff)); 
> ipAddr[0]='\0'; 
> 
> inet_ntop(int af, const void *src, char *dst, socklen_t cnt */ 

is something missing above... there is a un-matched comment on the line
above.

> while(1) 
> { 
> printf("Server waiting :) \n\n "); 
> consd = accept(s,(struct sockaddr*)&cli,(socklen_t*)&(clilen)); 
>         if( consd <-1 ) 

accept() will return -1 not, < -1, on error, perhaps it is error'ing and
perror isn't being called?

>             perror("accept error"); 
>         else 
>         { 
>         recv(s,buff,sizeof(buff),0); 
>         printf("Received from client data =%s",buff); 
>         printf("Received from client port =%d",ntohs(cli.sin6_port)); 
>         break; 
>         } 
> } 
> close(s) 
> } 

-Jim P.