dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Selecting Network Adapter when using winsock

  1. #1
    Join Date
    Mar 2019
    Posts
    2

    Selecting Network Adapter when using winsock

    I have an application that needs to discover a device connected to a Windows PC. The application does not know the IP address of the device. That PC may have multiple Ethernet adapters (and the user can specify which adapter the device is connected to).

    This is done by sending a broadcast UDP/IP packet, to which the device replies. Typically one adapter is connected to a WAN and the other a LAN. If Windows 'uses' the LAN as the primary adapter, or the WAN adapter is disabled, all goes well. If not, the reply doesn't make it back to the application (Wireshark verifies that the device receives and replies to the request). How can I force Windows to use the LAN adapter for broadcasting the discovery request and return the reply to the application? Note that the reply is also a broadcast UDP/IP packet since the device's IP address may be different than the LAN's subnet (the whole point is to find the device, which has a 'random' IP address, and then renumber it).

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    12,977

    Re: Selecting Network Adapter when using winsock

    Not sure this will help you but you can get a list if the available network adapters and which are active using WMI (Windows Management Information). This may help you to narrow down which device you need to send the packet to.

  3. #3
    Join Date
    Mar 2019
    Posts
    2

    Re: Selecting Network Adapter when using winsock

    OK, I think I've solved the mystery, but not the problem:

    Enumerating all the adapters to get their IP address and using bind() before broadcasting the discovery request does work (as verified by Wireshark) but 2 things are happening that made me thing things weren't working:

    1) I have Symantec (really hate it, but IT forces it on me) firewall running. What I've found is that Symantec blocks the incoming broadcast response from the device if it isn't on the primary adapter! If I disable Symantec, it sort of works (see 2).

    2) The request sent on a non-primary adapter is echoed back. So the first recv() you do after the request, gets the request back (I ignored since it was an invalid response). If I check for that, throw it away and do a second recv() I get the actual response! Odd, don't need to do that on the primary adapter?

    So I can deal with 2) but for now, all I can do is tell the user to disable their firewall to get it to work with 1).

    Thanks everyone for your help with this.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)