Click to See Complete Forum and Search --> : Socket Connection problems


lagdawg
02-23-2004, 10:12 PM
I am writing a client server program in c and am having trouble getting the client to connect to the server.

My error occurs in the server when attempting to accept a connection from a client.

server: accept: Invalid argument

//* server.c *//


socklen_t socklen;
if((new_s = accept(soc, (SA *) &clnt_addr, &socklen)) < 0) {
perror("server: accept");
close(soc);
exit(1);
}


//* client.c *//


soc = socket(AF_INET, SOCK_STREAM, 0)) < 0);
connect(soc, (SA *) &sin, sizeof(sin)) < 0);


Can anyone shed some light on this problem?

bwkaz
02-23-2004, 11:16 PM
You need to initialize socklen.

You can probably just set it equal to sizeof(clnt_addr). That is, assuming you've typedef'ed SA to sockaddr_t?

From the accept(2) manpage:

The addrlen argument is a value-result parameter: it should initially contain the size of the structure pointed to by addr; on return it will contain the actual length (in bytes) of the address returned.

lagdawg
02-23-2004, 11:28 PM
That was it, thanks alot.
Sometimes it just takes an extra set of eyes looking at something.