lwip IP address handling 关于 IP 地址的 操作 API接口

 

lwip 2.0.3  IP address handling 

 

/**
* @file
* IP address API (common IPv4 and IPv6)
*/

 

1、u32_t ipaddr_addr(const char *cp);

  把一个 字符串的 IP 地址转换成  ip4_addr_t 类型的IP。

 1 /**
 2  * Ascii internet address interpretation routine.
 3  * The value returned is in network order.
 4  *
 5  * @param cp IP address in ascii representation (e.g. "127.0.0.1")
 6  * @return ip address in network order
 7  */
 8 u32_t
 9 ipaddr_addr(const char *cp)
10 {
11   ip4_addr_t val;
12 
13   if (ip4addr_aton(cp, &val)) {
14     return ip4_addr_get_u32(&val);
15   }
16   return (IPADDR_NONE);
17 }

2、char *ip4addr_ntoa(const ip4_addr_t *addr);

  把一个 ip4_addr_t 类型 的IP地址 转换 成 字符串形式!

 1 /**
 2  * Convert numeric IP address into decimal dotted ASCII representation.
 3  * returns ptr to static buffer; not reentrant!
 4  *
 5  * @param addr ip address in network order to convert
 6  * @return pointer to a global static (!) buffer that holds the ASCII
 7  *         representation of addr
 8  */
 9 char*
10 ip4addr_ntoa(const ip4_addr_t *addr)
11 {
12   static char str[IP4ADDR_STRLEN_MAX];
13   return ip4addr_ntoa_r(addr, str, IP4ADDR_STRLEN_MAX);
14 }

 

转载于:https://www.cnblogs.com/suozhang/p/8435020.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值