开发者

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

I am doing 开发者_StackOverflowa 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 ?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜