C语言库函数---inet_pton

inet_pton函数用于将IPv4或IPv6的文本表示转换为二进制形式。根据地址簇(AF_INET或AF_INET6),它将字符串地址转化为in_addr或in6_addr结构体。函数返回值为负值表示错误,0表示格式不匹配,1表示成功。要使用此函数,需包含<arpa/inet.h>头文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

函数原型:

int inet_pton(int af,const char *src,void *dst)

参数解析:

af 地址簇

​ AF_INET:

​ src为指向字符型的地址(xxx.xxx.xxx.xxx),函数将该地址转化为in_addr的结构体,并复制在*dst中

​ AF_INET6:

​ src为指向IPV6的地址,函数将该地址转化为in6_addr结构体,并复制在*dst中

src 地址来源

dst 接收转换后的数据

​ struct sockaddr addr

​ struct sockaddr_in6 addr6

​ struct sockaddr_in addr4

返回值

负值:如果函数出错,则返回一个负值,并将EAFNOSUPPORT赋值给erron

0:af执行的地址簇和src格式不对

1:成功

需要包含的头文件

#include <arpa/inet.h>

例子

static int invalid_ipaddr (char *str
解析成C语言:“0003d30c <inet_pton>: 3d31c: 1a000028 bne 3d3c4 <inet_pton+0xb8> 3d33c: 8a000005 bhi 3d358 <inet_pton+0x4c> 3d350: 1afffff6 bne 3d330 <inet_pton+0x24> 3d354: ea000006 b 3d374 <inet_pton+0x68> 3d35c: 1a000001 bne 3d368 <inet_pton+0x5c> 3d364: ea000099 b 3d5d0 <inet_pton+0x2c4> 3d36c: 0a000003 beq 3d380 <inet_pton+0x74> 3d37c: 0afffff7 beq 3d360 <inet_pton+0x54> 3d384: cafffff5 bgt 3d360 <inet_pton+0x54> 3d3a0: 0a00008a beq 3d5d0 <inet_pton+0x2c4> 3d3a8: 1affffec bne 3d360 <inet_pton+0x54> 3d3bc: 1affffd9 bne 3d328 <inet_pton+0x1c> 3d3c0: eaffffe6 b 3d360 <inet_pton+0x54> 3d3c8: 0a000004 beq 3d3e0 <inet_pton+0xd4> 3d3dc: ea00007b b 3d5d0 <inet_pton+0x2c4> 3d3e8: 0a000003 beq 3d3fc <inet_pton+0xf0> 3d3f8: ea000011 b 3d444 <inet_pton+0x138> 3d408: 1affffd4 bne 3d360 <inet_pton+0x54> 3d40c: eafffff6 b 3d3ec <inet_pton+0xe0> 3d42c: 0a00003d beq 3d528 <inet_pton+0x21c> 3d434: 0affffc9 beq 3d360 <inet_pton+0x54> 3d45c: 1a000009 bne 3d488 <inet_pton+0x17c> 3d460: eaffffea b 3d410 <inet_pton+0x104> 3d470: 8a000009 bhi 3d49c <inet_pton+0x190> 3d484: 0a000006 beq 3d4a4 <inet_pton+0x198> 3d494: 8afffff2 bhi 3d464 <inet_pton+0x158> 3d498: eafffff6 b 3d478 <inet_pton+0x16c> 3d4a0: 0affffae beq 3d360 <inet_pton+0x54> 3d4bc: 1a000003 bne 3d4d0 <inet_pton+0x1c4> 3d4c8: baffffa4 blt 3d360 <inet_pton+0x54> 3d4cc: ea000011 b 3d518 <inet_pton+0x20c> 3d4d4: 0affffa1 beq 3d360 <inet_pton+0x54> 3d4dc: 0a00000a beq 3d50c <inet_pton+0x200> 3d4e4: 1affff9d bne 3d360 <inet_pton+0x54> 3d504: 0a000003 beq 3d518 <inet_pton+0x20c> 3d508: eaffff94 b 3d360 <inet_pton+0x54> 3d514: eaffffc8 b 3d43c <inet_pton+0x130> 3d51c: 1a000004 bne 3d534 <inet_pton+0x228> 3d524: ea000016 b 3d584 <inet_pton+0x278> 3d530: ea000001 b 3d53c <inet_pton+0x230> 3d574: aaffffe9 bge 3d520 <inet_pton+0x214> 3d580: eafffffa b 3d570 <inet_pton+0x264> 3d5a4: 1afffff6 bne 3d584 <inet_pton+0x278> 3d5b0: 0a000006 beq 3d5d0 <inet_pton+0x2c4> 3d5c0: ebffff51 bl 3d30c <inet_pton> 3d6c4: ebffff10 bl 3d30c <inet_pton>”
07-18
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值