Linux -Blue forest free software | Return to home page | Site Map | Search WWW | Contact Us |
Your current position : Homepage > Free Software > Technological exchanges >Application Programming


    

Blue Forest http://www.lslnet.com at 10:18 on June 6, 2006


Socket Programming, ME ! !

Members prawn :
Encountered a strange brother, please enlighten us. As follows :

Struct sockaddr_in servaddr;

TheSock = socket (AF_INET, SOCK_STREAM,0);
Servaddr.sin_family = AF_INET;
Servaddr.sin_port = htons (FPort);
Servaddr.sin_addr.s_addr = inet_addr (FIP.c_str ());

Int nRet;
If ((nRet = connect (TheSock, (struct sockaddr*) &servaddr, sizeof (servaddr))) "0)
   
The code should not have any problem, but when the translation system being given as follows :
Conversion from `sockaddr * 'to non-scalar type `__CONST_SOCKADDR_ARG' requested.
  
My translation environment RedHat7.3, please help out! Em16 : :

Socket Programming, ME ! !

FIP.c_str () return you what type of Sardinia? First printed!
Know it is suggested that similar mistakes do not match!

Socket Programming, ME ! !

-->

This problem and FIP.c_str () What this is a basic C + +, c if this procedure is used to write (of course, the assumption of no use stl. . . ), So call :
Connect (TheSock, (struct sockaddr*) &servaddr, sizeof (servaddr)) is not the problem, connect the man page to see this function is as follows :
Int connect (int sockfd, const struct sockaddr *serv_addr, socklen_t addrlen);

Sockaddr* const struct in C + + which is not allowed to be forced into the struct sockaddr*.

In fact, whether or C + + c is the best way should be :
Socklen_t addrlen = sizeof (*servaddr);
Connect (TheSock, (const struct sockaddr*) &servaddr, addrlen)



 Privacy Policy  Copyright © 1999-2000 LSLNET.COM. All rights reserved. Blue Forest website owners. E-mail : Webmaster@lslnet.com