Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi all, in an attempt to exercis 1

Status
Not open for further replies.

JaybOt

Programmer
Apr 18, 2001
101
GB
Hi all,

in an attempt to exercise my socket programming/class writing skills, i have come accros a small problem in the class i am delevoping - it just a simple socket/server class under Unix (BSD).

my class is nothing to fancy and is derived from an old socket server/client program that i have basically split into parts, and each 'part' then becomes a class method. e.g. mySoc.establish, mySoc.Bind, mySoc.getConnection. I have a few class instance variable used to keep track of various info about the client/server socket.

the problem arrises in the server class, in my accecpt method. The server class is designed to accept multiple connections (5 max). Now, im trying to retrieve some client info from the socket once it has been accepted, only ,when i compile the server application i get the following error:

SocketClass.h:169: passing `int *' as argument 3 of `accept(int, sockaddr *, socklen_t *)' changes signedness

my class method is as follows :
[Red]
int SocketServerClass::getConnection(int s)
{
int t; /* new socket for connection */
int sin_size;
struct sockaddr_in client; /* client's address */

sin_size = sizeof(struct sockaddr_in);
if ((t = accept(s, (struct sockaddr *)&client, &sin_size))==-1){ /* accept connection if there is one */
return(-1);
}
printf("You got a connection from %s\n",inet_ntoa(client.sin_addr) ); /* prints client's IP */

return(t);
}[/Red]

Firstly, i have no idea what signedness means, or why argument 3 of accept changes it!! I have checked the code, and other socket code i found on the net - the use of socket accept is exactly the same, except when supporting a single connection, in which case [Blue]t = accept(s, (struct sockaddr *)&client, &sin_size)[/Blue] is used. I can also run the original console application without any probs.

Does anyone know what this error means, or why i might be getting it? By the way, the original socket code in the console app was [Blue]if ((t = accept(s,NULL,NULL)) < 0)[/Blue], but of course, this does not use sockaddr_in and so no socket info is provided, however, it does accept multiple sockets as expected.

Any explanation would be good at this stage, cos i think i'm going mad!

Thanks in advance, regards,

j@Yb0t[afro]

&quot;Always know what you say, but don't always say what you know!&quot;
 
The function is looking for a value of type socklen_t for the third parameter, which I'm guessing is a typedef for an unsigned int. You're passing it a signed int, which is why it's complaining. Change your sin_size variable to be of type socklen_t and the error should go away.

I've noticed that C++ compilers tend to be more picky about that kind of thing than C compilers.

Dennis
 
Thnks Clairvoyant1332 - you certainly do poses some kind of physic abillity!!!

I had toyed with the idea of a signed/unsigned int but was not sure which struct to use to declare it.

Thanks again m8, u r a Star!

Jaybot[afro]

&quot;Always know what you say, but don't always say what you know!&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top