This can be achieved by using the getpeername and getsockname .
This snapshot does exactly what I need:
bool checkForLocalConnection(SOCKET Sock) { sockaddr_in RemAddr, LocAddr; int Len = sizeof(RemAddr); getpeername(Sock, (sockaddr *)&RemAddr, &Len); getsockname(Sock, (sockaddr *)&LocAddr, &Len); return (RemAddr.sin_addr.S_un.S_addr == LocAddr.sin_addr.S_un.S_addr); }
The finiteness of the result is always the same, so you do not even need to convert it to the original entiance.
Why it works and why it is necessary:
If you connect to localhost or 127.0.0.1 , getpeername will always getpeername address 127.0.0.1 (obviously converted to unsigned long). This means that you can just check htonl(2130706433); and do it with (Entianna Confirmation). However, if you enter the actual address ... or any other local address that your network adapter may have, getpeername will return that address instead of 127.0.0.1.
getsockname will return the local interface to which this socket is connected, which means that it will select the correct interface and tell you its address, which will be equal only if you are connected from the local machine.
Hope this helps someone since I had to search forever to find this little information. It should work for most common cases. (There are some exceptions)
Exclusion List:
Network cards with multiple addresses. They are located on the same machine, but not on the same network adapter, or are connected to a different IP address. You cannot do this.
Call the local host on a different IP address than 127.0.0.1. getsockname will always return 127.0.0.1, no matter what call you call 127.xxx. As a βdefenderβ against this, you can check the peer address for the first octet specifically for 127.
Thank you very much for your help with the harpers.