MattR
MattR

Reputation: 279

How do I get IP address from socket In Windows

I have the DWORD socket in windows. I need to know if it is a connection that goes out to the internet or if it is a local connection, to some form of localhost. Is there a good way to get the address that the socket is connected to in windows from just the socket? Or is there a better way to tell if the connection is local or not?

Upvotes: 5

Views: 10841

Answers (1)

Clay
Clay

Reputation: 1157

You probably want to call getpeername(). Using it is pretty basic, you pass a sockaddr pointer and a length and it fills in the data for you.

As far as determining if the connection is local, getaddrinfo() can give you a list of all available local addresses. You would compare the result of getpeername() to the local address list.

Upvotes: 5

Related Questions