How to determine IP used by client connecting to INADDR_ANY listener socket in C -


I have a network server application that has been written in C, the listener is forced through INADDR_ANY so that it Even the IP could accept the connection through the address of the host on which it was installed.

I need to know which server of the IP addresses the customer used when setting up their connection - in fact, I have to know whether they were through the loopback address 127.0.0.1 Or not?

> The sample of the partial code is as follows (I can post the whole thing if it helps):

  Structure Structure sockaddr_in serverAddress; ServerAddress.sin_family = AF_INET; ServerAddress.sin_addr.s_addr = INADDR_ANY; ServerAddress.sin_port = htons (port); Bind (listener, (Structured Soceder *) and server address, size (server address)); Listen (listener, CONNECTION_BACKLOG); Socket socketed; Static Structure sockaddr_in Client Attendant; ... socketfd = Acceptable (Listener, (Straight SOCADAR *) and Client Address, and Length);  

The solution to my specific problem (thanks to zildjohn01) requires this for anyone, so it is shown below:

  int isLocalConnection (int Socket) {struct Sockaddr_in sa; Int sa_len = sizeof (bit); If (Walkcam (Socket, and SA, and SA_LAN) == -1) {Return 0; } // Local access means 127.x.x.x range returns (sa.sin_addr.s_addr & amp; 0xff) in an IP == 127; }  

You can use the function.

The WalkCam () function gets locally bound names of the specified socket


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -