Barun
Barun

Reputation: 1915

C++ how can I get the destination ip from a SOCKET pointer

I am doing a firewall project where I am using LSP(Layered Service Provider) for URL filtering. I want to know how can I get the destination IP from LSP ?

Upvotes: 0

Views: 551

Answers (2)

Simone
Simone

Reputation: 11797

See the getpeername() function.

You will receive the peer's data inside a SOCKADDR structure. You may need to call inet_ntoa() to translate it into an ASCII string in Internet standard dotted-decimal format.

Upvotes: 2

André Caron
André Caron

Reputation: 45239

I'm not sure if there even is a function to extract the IP address from an existing socket. Normally, you need to remember the address you passed to WSAConnect() or extracted from WSAAccept(). Check out the full winsock function reference to see if there is any extra function that might extract it from a connected socket.

Of course, if you haven't done so already, you might need to re-structure your application to pass the IP address along with the SOCKET handle.

Upvotes: 1

Related Questions