首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
您找到你想要的搜索结果了吗?
是的
没有找到

socket inet_pton

inet_pton   Linux下这2个IP地址转换函数,可以在将IP地址在“点分十进制”和“整数”之间转换   而且,inet_pton和inet_ntop这2个函数能够处理ipv4和ipv6。.../inet.h>   int inet_pton(int af, const char *src, void *dst);   这个函数转换字符串到网络地址,第一个参数af是地址族,转换后存在dst中...  inet_pton 是inet_addr的扩展,支持的多地址族有下列:   af = AF_INET   src为指向字符型的地址,即ASCII的地址的首地址(ddd.ddd.ddd.ddd格式的)...(AF_INET, IPdotdec, (void *)&s);   printf("inet_pton: 0x%x\n", s.s_addr); // 注意得到的字节序   // 反转换   inet_ntop...(AF_INET, (void *)&s, IPdotdec, 16);   printf("inet_ntop: %s\n", IPdotdec);   }

2.4K80

linux网络编程之socket(七):一个进程发起多个连接和gethostbyname等函数

ERR_EXIT("getsockname error");         /* getpeername()获取对等方的地址 */         printf("local ip=%s port=%d\n", inet_ntoa...gethostbyname(host)) == NULL)         return -1;     //  #define h_addr h_addr_list[0]     strcpy(ip, inet_ntoa...= NULL)     {         printf("%s\n", inet_ntoa(*(struct in_addr *)hp->h_addr_list[i]));         i++;...: 127.0.1.1 需要注意的是 hp->h_addr_list 是指针的指针,则hp->h_addr_list[i] 即指针,将其强制转换为struct in_addr 类型的指针,再通过  inet_ntoa...函数转换成点分十进制的字符串,即 此语句 inet_ntoa(*(struct in_addr *)hp->h_addr_list[i]);  的意思。

1.6K00

Linux系统下socket编程socket接口介绍(二)

- IP地址格式转换函数 - (1)inet_aton、inet_addr、inet_ntoa(只用IPV4的IP地址),现在用的比较少,不过大多程序里面会看到这些函数,所以还是要学习一下它的作用,老方法使用...inet_network(const char *cp); char *inet_ntoa(struct in_addr in); struct in_addr inet_makeaddr...(这个转换完后不能用于网络传输,还需要调用htons或htonl函数才能将主机字节顺序转化为网络字节顺序,这两个函数先不讲,实战遇到的话,再进行解析),具体可以看下面Linux的源文: inet_aton...The inet_ntoa() function converts the Internet host address in, given in network byte order, to a string...inet_ntop() extends the inet_ntoa(3) function to support multiple address families, inet_ntoa(3)

3.5K20
领券