Get IP from sockaddr
Feb 28, 2008 at 4:31am UTC
Hello,
I am making a server accepting TCP connections. After I call accept and pass it my sockaddr_in, how can I then figure out the remote IP and put it into readable text?
Feb 28, 2008 at 12:24pm UTC
sockaddr_in contains a field named sockaddr->sin_addr.
But this comes in a network format.
1 2 3 4 5
#include <arpa/inet.h>
const char *inet_ntop(int af, const void *restrict src,
char *restrict dst, socklen_t size);
int inet_pton(int af, const char *restrict src, void *restrict dst);
So you need to convert it to string format by inet_ntop.
by that you will get ip in the string format.
Topic archived. No new replies allowed.