Question

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

Was it helpful?

Solution 2

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top