Get IP from sockaddr

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?
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.