Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get IP address from socket In Windows

Tags:

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?

like image 830
MattR Avatar asked Jul 15 '09 01:07

MattR


1 Answers

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.

like image 120
Clay Avatar answered Oct 12 '22 12:10

Clay