#include <arpa/inet.h>
const char *inet_ntop(int af, const void *src,
char *dst, socklen_t size);
使用ipv4地址时,man中如是说
(src需指向一个in_addr结构体)
AF_INET
src points to a struct in_addr (in network byte order) which is
converted to an IPv4 network address in the dotted-decimal for‐
mat, "ddd.ddd.ddd.ddd". The buffer dst must be at least
INET_ADDRSTRLEN bytes long.
要从一个addrinfo p中获取in_addr,使用的方法是
struct sockaddr_in * ipv4 = (struct sockaddr_in *) p->addr;
void * addr = &(ipv4->sin_addr);
inet_ntop(p->ai_family,addr,s,sizeof(s));