sockets - How can server determine whether client is local or remote? -


i'm trying create server able determine whether each accepted connection local or remote.

server this:

  1. call socket() create tcp srvsock
  2. bind() srvsock inaddr_any|server_port
  3. listen() on svrsock
  4. accept() connection on svrsock

local client this:

  1. call socket() create clisock
  2. connect() clisock 127.0.0.1|server_port

remote client this:

  1. call socket() create clisock
  2. connect() clisock server_public_ip|server_port

when accept() returns, how can server determine whether client local or remote?

the server can use getpeername() address of connected client. or use address accept() outputs. either way, if address among addresses returned getifaddrs() (or equivalent function, depending on platform) client local; otherwise, remote.


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -