How to get IP address from sockaddr

前端 未结 6 1541
慢半拍i
慢半拍i 2020-12-28 14:25

I want to try and get the ip address of a client after calling accept. This is what I have so far, but I just end up getting some long number that is clearly not an ip addr

6条回答
  •  被撕碎了的回忆
    2020-12-28 15:20

    what your are getting is the raw 32 bit integer representation of the IP address. to get the familiar dot separated string, use the function:

     char * inet_ntoa(struct in_addr addr);
    

    that will convert the integer to a static string.

提交回复
热议问题