#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));
本文介绍了如何使用inet_ntop函数将IPv4地址转换为点分十进制字符串格式。当处理addrinfo结构时,需要从其中提取in_addr,并通过inet_ntop将其转换为可读形式。
2556

被折叠的 条评论
为什么被折叠?



