Tag:
socket

Find IP address from remote end of a TCP socket

by
Ryan
on
October 31, 2008

In C or C++ it is fairly simple to find the IP address of the remote end of a TCP socket.
The following example shows how to do this using the getpeername() and inet_ntoa() system calls.

int sockfd;
int len;
char * hostip;
struct sockaddr_in sin;

len = sizeof(sin);

if (0 != getpeername(sockfd, (struct sockaddr *) &sin, &len))
[...]

Read More
No Comments
C
Copyright 2008-2010 WiredRevolution.com. All rights reserved.