[ale] Thanks a lot for ur clarification.

Srikanth Pokkuluri Srikanth.Pokkuluri at lntinfotech.com
Sun Nov 4 23:36:51 EST 2007


I have forgotten the basics that i have to read on connected socket in the 
server 


'Thanks and Regards,
P.V.S Srikanth
L&T Infotech.
Project Leader.
Employee No: 279753


Larsen & Toubro Infotech Ltd.
www.Lntinfotech.com

This Document is classified as: 

L&T Infotech Proprietary   L&T Infotech Confidential   L&T Infotech 
Internal Use Only   L&T Infotech General Business 

This Email may contain confidential or privileged information for the 
intended recipient (s) If you are not the intended recipient, please do 
not use or disseminate the information, notify the sender and delete it 
from your system. 



"Michael H. Warfield" <mhw at wittsend.com> 
Sent by: ale-bounces at ale.org
11/02/2007 11:06 PM
Please respond to
mhw at wittsend.com; Please respond to
Atlanta Linux Enthusiasts <ale at ale.org>


To
Atlanta Linux Enthusiasts <ale at ale.org>
cc

Subject
Re: [ale] IPv6 programming question






On Fri, 2007-11-02 at 10:14 +0530, Srikanth Pokkuluri wrote:
> 
> 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 */ 

                 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.

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

> Thanks in advance 

                 Mike
-- 
Michael H. Warfield (AI4NB) | (770) 985-6132 |  mhw at WittsEnd.com
   /\/\|=mhw=|\/\/          | (678) 463-0932 |  
http://www.wittsend.com/mhw/
   NIC whois: MHW9          | An optimist believes we live in the best of 
all
 PGP Key: 0xDF1DD471        | possible worlds.  A pessimist is sure of it!


______________________________________________________________________
_______________________________________________
Ale mailing list
Ale at ale.org
http://www.ale.org/mailman/listinfo/ale


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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/octet-stream
Size: 316 bytes
Desc: not available




More information about the Ale mailing list