none
Receiving UDP Multicast on multiple interfaces RRS feed

  • Question

  • Hello,

    I have a LAN and a Wireless LAN on my computer. I try to send and receive UDP-Multicast packets.

    Sending works well, even on all netwrok devices, after inserting this.. (which I have found many times in internet)

                        IPAddress ip = IPAddress.Parse("239.255.255.250");
                        NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
                        foreach (NetworkInterface adapter in nics)
                        {
                            IPInterfaceProperties ip_properties = adapter.GetIPProperties();
                            if (!adapter.GetIPProperties().MulticastAddresses.Any())
                                continue; // most of VPN adapters will be skipped
                            if (!adapter.SupportsMulticast)
                                continue; // multicast is meaningless for this type of connection
                            if (OperationalStatus.Up != adapter.OperationalStatus)
                                continue; // this adapter is off or not connected
                            IPv4InterfaceProperties p = adapter.GetIPProperties().GetIPv4Properties();
                            if (null == p)
                                continue; // IPv4 is not configured on this adapter
                            var ipaddress = IPAddress.HostToNetworkOrder(p.Index);
                            s.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.MulticastInterface, (int)ipaddress);
                        }

    But I have got a problem with receiving:

                var multicastgroup = System.Net.IPAddress.Parse("239.255.255.250");
    
                try
                {
                    ReceiverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
                    var hardwareToBind = new IPEndPoint(IPAddress.Any, 1900);
                    ReceiverSocket.Bind(hardwareToBind);
    
                    try
                    {
                        ReceiverSocket.SetSocketOption(SocketOptionLevel.IP,
                            SocketOptionName.AddMembership,
                                new MulticastOption(multicastgroup, IPAddress.Any));
                    }
                    catch
                    {
            
                    }
    
                    ReceiverSocket.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, _PacketReceived, this);
                }
                catch
                {
                }

    It works well, as long as I disable the Wireless LAN. As soon as I enable the Wireless LAN, nothing is received anymore. But with wireshark, I can see, that the device is receiving UDP-Packets with the correct content. Only my program isn't aware of it.

    What am I doing wrong?

    Tuesday, March 11, 2014 8:38 AM

Answers

  • You have to listen for the port on an interface before is gets to the USB card since the USB isn't forwarding the port number.   The ethernet interfaces are chained so you have to figure out the order the interfaces are insalled on the PC.  Then you have to make sure you forward the port so the USB will still receive the datagrams.

    If I remember correctly there is a "sniffer" project at www.codeproject.com that will get you started.  The listening of the SSDP-protocol is very similar to a ethernet sniffer that you want to listen but still allow the datagrams to get forward and processed by the existing code in the PC. 


    jdweng

    Monday, March 24, 2014 10:44 AM

All replies

  • The wireless LAN is a router and router often block Multicast (ICMP).  You usually have to allow ICMP to pass through the router.  Is the wireless LAN a card inside the PC or an external device?  I suspect that it is inside the PC and you are seeing the ICMP reaching the LAN interface bu tnot being forwarded through the router.


    jdweng

    Tuesday, March 11, 2014 9:22 AM
  • Thank you.

    The wireless LAN is inside the PC (it's a laptop).

    wireshark detects the UDPpackets on my LAN port.

    ... so I do not bother about receiving any UDP-Packet via wireless LAN. But I cannot receive UDP-Packets on LAN when wireless LAN is switched on. But wireshark receives the packets on my laptop on the LAN interface. So technically, my laptop is able to receive the packets on the correct interface... but not my program... why?

    ...

    Or, are you saying, that I have some internal router in my laptop which is blocking the UDP-packets?

    Tuesday, March 11, 2014 10:25 AM
  • Yes!!!  Check the options for the wireless LAN.  Start by checking the properties of the LAN card in Device Manager.

    jdweng


    The problem could also be at the wireless router to you internet provider.
    Tuesday, March 11, 2014 10:31 AM
  • What you are seing on the LAN interface may not be on the wireless interface.  What modem/router is generating the wireless signal.  Check the vendor datasheet for options.

    jdweng

    Tuesday, March 11, 2014 12:27 PM
  • Question 1)

    What exactly do I search for?

    Question 2)

    How do I program the code, that I will receive (my) UDP-packets from all interfaces (like wireshark does)?

    Tuesday, March 11, 2014 12:37 PM
  • 1) Allow Multicast to pass or ICMP.  Normally when you configure a router you don't let Muticast to pass between subnets.  You probably have the router setup that the LAN and Wirelss Lan are on two different subnets and the router will automatically block the multicast.  Mutlicast is a type of ICMP message.  The settting to allow the muticast to pass if usually very cryptic on these routers and you may need to call the 800 number and ask the vendor the question.

    Some vendors will not answer these questions unless the device is under warrenty.  So I usually tell the vendor thzt I'm interesting in buying a lot of devices and then I get the answers.  The last time I did this I couldn't get an expert on the phone and hung up on the customer rep who didn't know anything and just was reading paragraphs from the specification sheet. I finally had to get the answer by asking the Tech question using the vendor web page.

    2) You will get all the data when you make the endpoint IPAddress.Any.


    jdweng


    Tuesday, March 11, 2014 12:47 PM
  • ?

    But I see the packets on the LAN interface with wireshark - why does my program not see it?

    Could you please explain more detailed, where do you think, the packets are going to be lost?

    A device sends the packet => The router routes it => the hardware interface LAN gets it (wireshark) => ...?...  => the program doesn't receive it?

    The device is "Intel(R) 82579V Gigabit Network Connection", the vendor is Intel... I don't understand, what you want me to check.

    Tuesday, March 11, 2014 12:52 PM
  • 2) You will get all the data when you make the endpoint IPAddress.Any.


    jdweng


    I have the enpoint IPAddress.Any
    Tuesday, March 11, 2014 12:59 PM
  •  I think the router is the issue.  The webpag the below says the following :

    There could be other reasons the gateway machine is not pingable (ICMP blocked) / not giving a connection / dropping WAN packets - I spent days troubleshooting something like that thinking it was a driver issue and it turned out the user forgot he had MAC filtering enabled on the router!

    http://social.msdn.microsoft.com/Forums/vstudio/en-US/bf94d2ea-d763-45d1-9080-d8fb6afde5da/receiving-udp-multicast-on-multiple-interfaces?forum=netfxbcl


    jdweng

    Tuesday, March 11, 2014 1:05 PM
  • Also check your firewall settings.  The firewall could be blocking.


    jdweng

    Tuesday, March 11, 2014 1:07 PM
  • Question 1)

    Which router? If wireshark is able to receive the packet within my laptop, then there isn't any other hardware blocking my UDP-packets. If you are talking about any routing-thingy within Windows - Please tell me, what that could be

    Question 2)

    If everything works on LAN, with wireless LAN disabled, why should the firewall block anything on LAN as soon as wireless LAN gets enabled?


    • Edited by GreatVolk Tuesday, March 11, 2014 1:12 PM Typo
    Tuesday, March 11, 2014 1:12 PM
  • IP routing will always take the most direct path which is the interface with the largest mask.  If you have two masks 255.0.0.0 and 255.255.0.0 the route used is the 2nd.


    jdweng


    Noramally you should always have one interface with a mask of 0.0.0.0 (the default) and the other interface(s) something other than 0.0.0.0
    Tuesday, March 11, 2014 1:28 PM
  • You may want to type the command below from a cmd.exe window

    IPConfig /all


    jdweng


    Tuesday, March 11, 2014 1:38 PM
  • This kind of mask isn't the subnet mask, I think.

    Where do i find, how my ethernet devices are configured, regarding this mask?

    How can I get the UDP-packets, IPAddress.Any seems not to work?

    Tuesday, March 11, 2014 2:02 PM
  • ipconfig /all does not show me any kind of masks except the subnetmasks. No ip or mask is 0.0.0.0, when using ipconfig /all. So I don't know, what you are talking about, mentioning these masks. Is there another way of seeing these masks?

    Just to be sure, to be understand totally correct:

    I read all aother links at the "Top related threads", where you also wrote many answers. Most often, it is all about SENDING Udp-Multicast-packets. This works here in my scenario. I've got a problem in RECEIVING with IPAddress.Any, even if Wireshark proves, that my PC receives these packets in reality.

    Could there be a problem with the port 1900?


    • Edited by GreatVolk Friday, March 21, 2014 12:30 PM typo
    Friday, March 21, 2014 12:29 PM
  • A firewall could be blocking the port 1900.  I do mean the subnet masks.  Can you post the results of the ipconfig/all.  You can redirect the output to a file like below

    > ipconfig /all > c:\temp\ipconfig.txt

     Change any confidential infomation in the file.  Like you can change 192.0.0.1 to XXX.0.0.1.


    jdweng

    Friday, March 21, 2014 12:41 PM
  • Sorry, it's German...

    Windows-IP-Konfiguration

       Hostname  . . . . . . . . . . . . : PC318E
       Prim„res DNS-Suffix . . . . . . . : mycompany.int
       Knotentyp . . . . . . . . . . . . : Hybrid
       IP-Routing aktiviert  . . . . . . : Nein
       WINS-Proxy aktiviert  . . . . . . : Nein
       DNS-Suffixsuchliste . . . . . . . : mycompany.int
                                           hp.lan

    Ethernet-Adapter LAN-Verbindung 4:

       Medienstatus. . . . . . . . . . . : Medium getrennt
       Verbindungsspezifisches DNS-Suffix:
       Beschreibung. . . . . . . . . . . : TAP-Win32 Adapter V9
       Physikalische Adresse . . . . . . : 00-FF-79-24-42-E5
       DHCP aktiviert. . . . . . . . . . : Ja
       Autokonfiguration aktiviert . . . : Ja

    Ethernet-Adapter LAN-Verbindung 3:

       Verbindungsspezifisches DNS-Suffix:
       Beschreibung. . . . . . . . . . . : ASIX AX88179 USB 3.0 to Gigabit Ethernet Adapter
       Physikalische Adresse . . . . . . : 00-23-54-8C-06-48
       DHCP aktiviert. . . . . . . . . . : Nein
       Autokonfiguration aktiviert . . . : Ja
       Verbindungslokale IPv6-Adresse  . : fe80::3db0:398b:db36:1602%20(Bevorzugt)
       IPv4-Adresse  . . . . . . . . . . : 192.168.0.3(Bevorzugt)
       Subnetzmaske  . . . . . . . . . . : 255.255.255.0
       IPv4-Adresse  . . . . . . . . . . : 192.168.1.3(Bevorzugt)
       Subnetzmaske  . . . . . . . . . . : 255.255.255.0
       IPv4-Adresse  . . . . . . . . . . : 192.168.130.123(Bevorzugt)
       Subnetzmaske  . . . . . . . . . . : 255.255.255.0
       Standardgateway . . . . . . . . . :
       DHCPv6-IAID . . . . . . . . . . . : 620766036
       DHCPv6-Client-DUID. . . . . . . . : 00-01-00-01-18-63-2A-B5-E8-E0-B7-F5-1F-67
       DNS-Server  . . . . . . . . . . . : fec0:0:0:ffff::1%1
                                           fec0:0:0:ffff::2%1
                                           fec0:0:0:ffff::3%1
       NetBIOS ber TCP/IP . . . . . . . : Aktiviert

    Drahtlos-LAN-Adapter Drahtlosnetzwerkverbindung 2:

       Verbindungsspezifisches DNS-Suffix: hp.lan
       Beschreibung. . . . . . . . . . . : Intel(R) Centrino(R) Wireless-N 2230
       Physikalische Adresse . . . . . . : 84-A6-C8-AD-35-A9
       DHCP aktiviert. . . . . . . . . . : Ja
       Autokonfiguration aktiviert . . . : Ja
       Verbindungslokale IPv6-Adresse  . : fe80::81f0:a698:63f:8081%17(Bevorzugt)
       IPv4-Adresse  . . . . . . . . . . : EXT.ERN.AL.IP(Bevorzugt)
       Subnetzmaske  . . . . . . . . . . : 255.255.255.0
       Lease erhalten. . . . . . . . . . : Freitag, 21. M„rz 2014 15:03:46
       Lease l„uft ab. . . . . . . . . . : Freitag, 21. M„rz 2014 15:08:46
       Standardgateway . . . . . . . . . : ...SOMEWHERE...
       DHCP-Server . . . . . . . . . . . : ...SOMEWHERE...
       DHCPv6-IAID . . . . . . . . . . . : 512009928
       DHCPv6-Client-DUID. . . . . . . . : 00-01-00-01-18-63-2A-B5-E8-E0-B7-F5-1F-67
       DNS-Server  . . . . . . . . . . . : ...SOMEWHERE...
       NetBIOS ber TCP/IP . . . . . . . : Aktiviert

    Mobiler Breitbandadapter Mobile Breitbandverbindung 2:

       Medienstatus. . . . . . . . . . . : Medium getrennt
       Verbindungsspezifisches DNS-Suffix:
       Beschreibung. . . . . . . . . . . : Ericsson F5321gw for TOSHIBA Mobile Broadband Network Adapter #2
       Physikalische Adresse . . . . . . : 02-80-37-EC-02-00
       DHCP aktiviert. . . . . . . . . . : Nein
       Autokonfiguration aktiviert . . . : Ja

    Ethernet-Adapter LAN-Verbindung:

       Verbindungsspezifisches DNS-Suffix: mycompany.int
       Beschreibung. . . . . . . . . . . : Intel(R) 82579V Gigabit Network Connection
       Physikalische Adresse . . . . . . : E8-E0-B7-F5-1F-67
       DHCP aktiviert. . . . . . . . . . : Ja
       Autokonfiguration aktiviert . . . : Ja
       Verbindungslokale IPv6-Adresse  . : fe80::1862:7552:31a8:de13%11(Bevorzugt)

    ****** This is the Interface, I like to receive the UDP packet ****

       IPv4-Adresse  . . . . . . . . . . : XXX.XXX.34.160(Bevorzugt)
       Subnetzmaske  . . . . . . . . . . : 255.255.240.0
       Lease erhalten. . . . . . . . . . : Donnerstag, 20. M„rz 2014 10:26:28
       Lease l„uft ab. . . . . . . . . . : Donnerstag, 3. April 2014 10:26:27
       Standardgateway . . . . . . . . . : XXX.XXX.32.10
       DHCP-Server . . . . . . . . . . . : XXX.XXX.120.75
       DHCPv6-IAID . . . . . . . . . . . : 300474551
       DHCPv6-Client-DUID. . . . . . . . : 00-01-00-01-18-63-2A-B5-E8-E0-B7-F5-1F-67
       DNS-Server  . . . . . . . . . . . : XXX.XXX.120.81
                                           XXX.XXX.120.82
       Prim„rer WINS-Server. . . . . . . : XXX.XXX.120.81
       Sekund„rer WINS-Server. . . . . . : XXX.XXX.120.82
       NetBIOS ber TCP/IP . . . . . . . : Aktiviert

    Tunneladapter isatap.mycompany.int:

       Verbindungsspezifisches DNS-Suffix: mycompany.int
       Beschreibung. . . . . . . . . . . : Microsoft-ISATAP-Adapter
       Physikalische Adresse . . . . . . : 00-00-00-00-00-00-00-E0
       DHCP aktiviert. . . . . . . . . . : Nein
       Autokonfiguration aktiviert . . . : Ja
       Verbindungslokale IPv6-Adresse  . : fe80::5efe:XXX.XXX.34.160%18(Bevorzugt)
       Standardgateway . . . . . . . . . :
       DNS-Server  . . . . . . . . . . . : XXX.XXX.120.81
                                           XXX.XXX.120.82
       NetBIOS ber TCP/IP . . . . . . . : Deaktiviert

    Tunneladapter isatap.{792442E5-477C-4689-BE4D-A02FD0459D51}:

       Medienstatus. . . . . . . . . . . : Medium getrennt
       Verbindungsspezifisches DNS-Suffix:
       Beschreibung. . . . . . . . . . . : Microsoft-ISATAP-Adapter #2
       Physikalische Adresse . . . . . . : 00-00-00-00-00-00-00-E0
       DHCP aktiviert. . . . . . . . . . : Nein
       Autokonfiguration aktiviert . . . : Ja

    Tunneladapter isatap.hp.lan:

       Verbindungsspezifisches DNS-Suffix:
       Beschreibung. . . . . . . . . . . : Microsoft-ISATAP-Adapter #3
       Physikalische Adresse . . . . . . : 00-00-00-00-00-00-00-E0
       DHCP aktiviert. . . . . . . . . . : Nein
       Autokonfiguration aktiviert . . . : Ja
       Standardgateway . . . . . . . . . :
       NetBIOS ber TCP/IP . . . . . . . : Deaktiviert

    Tunneladapter isatap.{549E0507-6228-4E25-B638-7C5EFC286EBF}:

       Medienstatus. . . . . . . . . . . : Medium getrennt
       Verbindungsspezifisches DNS-Suffix:
       Beschreibung. . . . . . . . . . . : Microsoft-ISATAP-Adapter #4
       Physikalische Adresse . . . . . . : 00-00-00-00-00-00-00-E0
       DHCP aktiviert. . . . . . . . . . : Nein
       Autokonfiguration aktiviert . . . : Ja

    Tunneladapter isatap.{F31E9E6C-5543-4DC5-B264-71B80B215034}:

       Medienstatus. . . . . . . . . . . : Medium getrennt
       Verbindungsspezifisches DNS-Suffix:
       Beschreibung. . . . . . . . . . . : Microsoft-ISATAP-Adapter #5
       Physikalische Adresse . . . . . . : 00-00-00-00-00-00-00-E0
       DHCP aktiviert. . . . . . . . . . : Nein
       Autokonfiguration aktiviert . . . : Ja

    Tunneladapter Teredo Tunneling Pseudo-Interface:

       Medienstatus. . . . . . . . . . . : Medium getrennt
       Verbindungsspezifisches DNS-Suffix:
       Beschreibung. . . . . . . . . . . : Teredo Tunneling Pseudo-Interface
       Physikalische Adresse . . . . . . : 00-00-00-00-00-00-00-E0
       DHCP aktiviert. . . . . . . . . . : Nein
       Autokonfiguration aktiviert . . . : Ja

    Friday, March 21, 2014 2:15 PM
  • First execute from a cmd.exe  the following command

    > Netstat -a

    Check very carefully for port number 1900.  Make sure that the port number isn't registered by any application especially the USB Ethernet adapter.  There may be a conflict using this port number.

    If port 1900 isn't registered on any cards then try updating the driver for the wireless lan. I suspect there could be a bug in the driver.  Go to Device Manager and right click the USB wireless lan device and check for updates.  Also make sure on the USB device that a Standardgateway is configured.  I would probably make it an address within the IP address of one of the interfaces on the adapter like 192.168.0.4.

    All IP messages should be forwarded to the IP.Any socket on the computer unless the port number is registered for an ethernet card.  The USB Ethernet adapter should only block ports registered on the device and not block any other port numbers.  For some reason the USB Ethernet driver isn't forwarding port number 1900 to the other network cards.  The socket IP.Any is at the end of the chained network cards and will get all IP that is NOT registered on the other network cards.  IP.Any is a default socket.


    jdweng

    Friday, March 21, 2014 8:33 PM
  • I just noticed the port number 1900 is register on my computer.  After some research I found it is a port number used by Microsoft.  See webpage below

    http://en.wikipedia.org/wiki/Simple_Service_Discovery_Protocol

    Here is a list of well known port numbers.  Port 1900 UDP is one of these port numbers.  You should avoid using any port numbers on this list.

    http://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers


    jdweng

    Friday, March 21, 2014 9:04 PM
  • I'd like to listen to the SSDP-protocol. Is there a way to achieve this?
    • Edited by GreatVolk Monday, March 24, 2014 10:06 AM typo
    Monday, March 24, 2014 9:48 AM
  • You have to listen for the port on an interface before is gets to the USB card since the USB isn't forwarding the port number.   The ethernet interfaces are chained so you have to figure out the order the interfaces are insalled on the PC.  Then you have to make sure you forward the port so the USB will still receive the datagrams.

    If I remember correctly there is a "sniffer" project at www.codeproject.com that will get you started.  The listening of the SSDP-protocol is very similar to a ethernet sniffer that you want to listen but still allow the datagrams to get forward and processed by the existing code in the PC. 


    jdweng

    Monday, March 24, 2014 10:44 AM