4

With IPv4 I can bind() to a specific address to select the interface that will be used to receive the packets (and in some case, also to send, but that's not the point).

On a dual stack IPv6/IPV4 machine I have this problem: I can create a 6 socket and use it to receive 4 traffic, but if I want to bind to a specific interface, I have to choose an IP address to bind to.

If I bind to an IPv6 address, I'll filter out all the IPv4 traffic and vice versa.

How can I receive both IPv4 and IPv6 traffic from a specific interface?

garph0
  • 1,700
  • 1
  • 13
  • 16

2 Answers2

5

If you're using Linux, you should be able to use SO_BINDTODEVICE socket option to bind to an interface rather than a specific IP address. It's described in the socket man page.

Jeff
  • 1,807
  • 1
  • 15
  • 17
  • Thanks. Unfortunately this solution does not work with Winsock 2. I guess that there is no solution if the stack does not support SO_BINDTODEVICE. – garph0 Feb 25 '11 at 13:45
2

There is no standard portable interface for binding a single socket to the unspecified address and limiting the scope to the addresses on a specific interface, much less simultaneously selectively requiring the strong host model for communications with that socket. Every operating system that supports this feature does it differently.

james woodyatt
  • 2,170
  • 17
  • 17