Click to See Complete Forum and Search --> : Can anyone tell me this code mean?


zeuss
December 8th, 2004, 10:46 PM
Hi all,

Can anyone describe the following codes meanings?

int server_sd;
struct sockaddr_in server_addr;
socklen_t server_addr_len;

memset(&server_addr, 0, sizeof(server_addr));
server_addr_len=sizeof(server_addr);

getsockopt(client_sd, SOL_IP, SO_ORIGINAL_DST, &server_addr, &server_addr_len);

server_sd = socket(PF_INET, SOCK_STREAM, 0);

connect(server_sd, (const struct sockaddr *)&server_addr, sizeof(server_addr));


I got a socket named client_sd. And the following codes are like above,
Does it mean:

The "server_sd" has been connected with "client_sd", and I can use "server_sd"
to send data to server as if the data sent by the client?
And this program run as a proxy?

thank you!

kuphryn
December 9th, 2004, 12:04 AM
server_sd is a socket. It is an active socket if connect() returns valid result.

Kuphryn

zeuss
December 9th, 2004, 12:30 AM
Thank you for the response.
If the server_sd is active, does it mean that if I send data via server_sd is the same as the data sent by client_sd? And the server accept a request, and sent a reply, the client who created client_sd would get the reply, not server_sd?

kuphryn
December 10th, 2004, 12:21 AM
A server does not connect to the client except for data servers such as FTP. A socket is bounded to a port on the server-side. New sockets are created for incoming connections.

Kuphryn