简体   繁体   中英

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?

I'm trying to get the HWADDR for one system that may have only IPv6 addresses active (not dual stack).

Will I be able to open a socket using AF_INET ? I'm only interested in finding the MAC address

You surely could create an IPv4 socket using the system call socket() . However binding it to an IPv6 interface using bind() would fail.

You can create an IPv4 socket. 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?

But I'm not sure SIOCGIFHWADDR will work without routes through a non-loopback interface. 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.

I fail to see the problem. You can call SIOCGIFHWADDR on both IPv4 and IPv6 sockets.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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