简体   繁体   English

当系统上只有IPv6地址可用时,AF_INET套接字?

[英]AF_INET socket when only IPv6 addresses are available on system?

Can you open AF_INET socket when only IPv6 addresses are available on system? 当系统上只有IPv6地址可用时,您可以打开AF_INET套接字吗?

I'm trying to get the HWADDR for one system that may have only IPv6 addresses active (not dual stack). 我正在尝试为一个可能只有IPv6地址处于活动状态(而不是双堆栈)的系统获取HWADDR。

Will I be able to open a socket using AF_INET ? 我可以使用AF_INET打开套接字吗? I'm only interested in finding the MAC address 我只想找到MAC地址

You surely could create an IPv4 socket using the system call socket() . 您肯定可以使用系统调用socket()创建一个IPv4套接字。 However binding it to an IPv6 interface using bind() would fail. 但是,使用bind()将其绑定到IPv6接口将失败。

You can create an IPv4 socket. 您可以创建一个IPv4套接字。 If you could not, the system would also not be able to accept an IPv4 address when you connect to a v4-able network next month, see? 如果不能,下个月连接到支持v4的网络时,系统也将无法接受IPv4地址。

But I'm not sure SIOCGIFHWADDR will work without routes through a non-loopback interface. 但是我不确定SIOCGIFHWADDR是否可以在没有通过非环回接口的路由的情况下工作。 You could try tat on your target systems, or just try both AF_INET and AF_INET6, catch the error(s) and use whatever returns a result. 您可以尝试在目标系统上运行tat,或者仅尝试同时使用AF_INET和AF_INET6,捕获错误并使用返回结果的任何方法。

I fail to see the problem. 我看不到问题。 You can call SIOCGIFHWADDR on both IPv4 and IPv6 sockets. 您可以在IPv4和IPv6套接字上调用SIOCGIFHWADDR

No matter if I use AF_INET or AF_INET6 to create the socket, the ioctl() call succeeds and gives me the HW addr of the device I ask for. 不管我使用AF_INET还是AF_INET6创建套接字, ioctl()调用都会成功,并为我提供所需设备的硬件地址。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM