0

Question background:

My MFC CAsyncSocket-based socket code has worked fine in the lab for a long time, until it didn't (see how to determine socket interface type). It's design was based on the Microsoft Docs sample code which sequentially walks through a linked-list of socket interfaces keyed on socket family (like, AF_INET, AF_INET6, etc). With Remy Lebeau's answer to my question, I am now able to list the details of any interface my users might encounter. But as Remy points out there are MANY MANY interfaces out there. "Out there" is quite broad for me since my architecture is that of a dApp (aka, no servers), meaning I won't know my user's precise interface environment in advance. That leaves me with an interface selection design problem.

My question:

How do I select an interface when I don't know the interface environment of virtually all my potential users? There are potential indicators like an interface's Description or Friendly Name I could use to narrow down my selection resolving code. There is an interface structure member called IfType defined in ipifcons.h which contains 281 types. I could perhaps choose a subset from these. There is also a GetBestInterface function, but I don't know if that would work all the time or what its intention is.

I am looking for some guidance on this issue.

rtischer8277
  • 496
  • 6
  • 27
  • 2
    Why are you even bothering with selecting an interface at all? If you are not going to let your users select an interface for your code to use, then let the socket handle it for you. If you are writing a server, you should bind your listening socket to `0.0.0.0` so it listens on all available interfaces. And if you are writing a client, you shouldn't be binding the socket at all, let `connect()` choose the best interface available based on how your OS's routing tables are configured. So, what are you REALLY trying to solve here? – Remy Lebeau Sep 02 '19 at 06:32
  • My app is node-based, each one of which listens on a specific end point (server), one for each node. These nodes can also connect (client) to one or more specific end points. There are many such hybrid nodes on any particular computer running my software. These end points are to be `Ipv6` `SLAAC` generated so it is possible to have different IP addresses that listen using the same port number. For `Ipv4` addresses, binding on `0.0.0.0` is okay since the port number is the key. Not so for `Ipv6` where it is the network address that is the differentiator key. Must be unique port numbers then. – rtischer8277 Sep 02 '19 at 13:27

0 Answers0