[ale] IPv6 programming question

Srikanth Pokkuluri Srikanth.Pokkuluri at lntinfotech.com
Fri Nov 2 00:46:18 EDT 2007


Hi All,
I have written client server program on linux using ipv6 programming ... 
(stream sockets)

But when  i am sending data ...The data is not been received at server 
.... please correct where the error is thanks 

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;
    inet_pton(AF_INET6,"::1"/*IN6ADDR_LOOPBACK_INIT*/,&(ser.sin6_addr));
buff = (char *) malloc (20* sizeof(char));
strcpy(buff,"srikanth");
ret = connect(s,(struct sockaddr*)&ser,sizeof(struct sockaddr_in6));
if( ret <0)
perror ( " coonect error ");
else
r = send(s,buff,20,0);
if ( r <= 0)
perror ("send error");
close(s);



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 */


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

Thanks in advance 




______________________________________________________________________
-------------- next part --------------
An HTML attachment was scrubbed...




More information about the Ale mailing list