wick
wick

Reputation: 2224

Getting destination/if IP addres from accept()?

Say, I bind 0.0.0.0 port X, listen on it, and then accept new connection.

How can my server find destination IP address the client used to connect to?

Also, via which interface (assuming multihomed server) the SYN arrived?

Upvotes: 2

Views: 239

Answers (1)

caf
caf

Reputation: 239011

The getsockname() call on the socket returned by accept() will give you the address of the local end of the connection.

The best way to determine the interface is probably just to match up the local IP address from getsockname() against the interface addresses.

Upvotes: 2

Related Questions