为什么在Ubuntu 18.04.1的netinet中未定义in_addr6?

时间:2018-09-08 15:13:15

标签: c++ c linux networking ip-address

我目前正在用C建立一个跨平台的库,该库可以使用IP地址。因此,我认为我可以使用类型in_addrin_addr6来表示值,因为它们看起来很容易移植。

但是在我安装的Ubuntu 18.04.1(适用于Linux的Windows子系统)中,in_addr6中似乎没有定义<netinet/in.h>结构。

通过以下方式搜索in_addr6的标头时没有结果:

robin@ROBIN-PC:/usr/include/netinet$ grep -rnw '/usr/include/netinet' -e 'in_addr6'

如果我搜索in_addr,则会得到多个结果:

robin@ROBIN-PC:/usr/include/netinet$ grep -rnw '/usr/include/netinet' -e 'in_addr'
/usr/include/netinet/if_ether.h:90:     /* struct in_addr *ipaddr; */ \
/usr/include/netinet/igmp.h:70:  struct in_addr igmp_group;     /* group address */
/usr/include/netinet/in.h:31:struct in_addr
/usr/include/netinet/in.h:241:    struct in_addr sin_addr;              /* Internet address.  */
/usr/include/netinet/in.h:247:                     sizeof (struct in_addr)];
/usr/include/netinet/in.h:267:    struct in_addr imr_multiaddr;
/usr/include/netinet/in.h:270:    struct in_addr imr_interface;
/usr/include/netinet/in.h:276:    struct in_addr imr_multiaddr;
/usr/include/netinet/in.h:279:    struct in_addr imr_interface;
/usr/include/netinet/in.h:282:    struct in_addr imr_sourceaddr;
/usr/include/netinet/in.h:326:    struct in_addr imsf_multiaddr;
/usr/include/netinet/in.h:329:    struct in_addr imsf_interface;
/usr/include/netinet/in.h:337:    struct in_addr imsf_slist[1];
/usr/include/netinet/in.h:341:                            - sizeof (struct in_addr)                   \
/usr/include/netinet/in.h:342:                            + (numsrc) * sizeof (struct in_addr))
/usr/include/netinet/in.h:602:extern int getipv4sourcefilter (int __s, struct in_addr __interface_addr,
/usr/include/netinet/in.h:603:                          struct in_addr __group, uint32_t *__fmode,
/usr/include/netinet/in.h:604:                          uint32_t *__numsrc, struct in_addr *__slist)
/usr/include/netinet/in.h:608:extern int setipv4sourcefilter (int __s, struct in_addr __interface_addr,
/usr/include/netinet/in.h:609:                          struct in_addr __group, uint32_t __fmode,
/usr/include/netinet/in.h:611:                          const struct in_addr *__slist)
/usr/include/netinet/ip.h:128:    struct in_addr ip_src, ip_dst;        /* source and dest address */
/usr/include/netinet/ip_icmp.h:145:    struct in_addr ih_gwaddr;        /* gateway address */

这对我提出了一些问题:

  • in_addr6结构是否在另一个标题中定义? (因为grep -rnw '/usr/include/' -e 'in_addr6'不会产生任何结果,所以不会猜测)
  • 为什么在我的Ubuntu安装中未定义in_addr6结构?
  • 您何时可以期望定义in_addr6(例如:其他发行版或未将Ubuntu安装为WSL)?

1 个答案:

答案 0 :(得分:1)

结构in_addr6特定于Windows。结构 in6_addr在Windows,Linux和macOS中可用,应用于可移植库。