Re: connect() returns 22

From: Casper H.S. Dik (Casper.Dik_at_Sun.COM)
Date: 10/30/03


Date: 30 Oct 2003 13:04:29 GMT

Senthilraja <senthil.raja@adcc.alcatel.be> writes:

> bzero(server_addr, sizeof(struct sockaddr_in));
> server_addr->sin_family = AF_INET;
> server_addr->sin_port = htons(80);
> server_addr->sin_addr.s_addr = 1117850705; //the IP address of
>dictionary.reference.com

You would need to use "htonl(1117850705)".

> // Connect to the server

> addrlen = sizeof (server_addr);

This is wrong; should be "sizeof *server_addr".

> returncode = connect(server_socket,
> (struct sockaddr *) &server_addr,

This is incorrect; server_addr is a struct sockaddr_in *.

Seems like you're mixing example; what people usually do is:

        struct sockaddr_in server_addr;

(no malloc) and then that code is OK.

Casper

-- 
Expressed in this posting are my opinions.  They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.