UDP Multicast Windows CPP - windows

Hi my UDP Multicast is working but only 1 receiver is able to receive the data.
From my understanding, multicast send data via port number.
Can I have two device listening to the same port?

Related

Golang cannot send packets to stun received ip

I’m using Golang to try to send packets through UDP to an IP address and port provided by STUN. The goal is to communicate between two devices without having to open a port in the firewall, as both devices are located in a different network.
The program runs on both devices in the following manner:
Device 1 waits for device 2 to send the IP address and port found by STUN. This goes through an open port in the firewall of device 1. (Only for device 1 an open port is possible)
The problem is that device 2 does not receive any packets through the port found by STUN.
I think the problem consists of the router not knowing the connection to device 2. Device 2 is connected with the router, but the router doesn’t know what to do with the packets.
Do you have any idea how to solve this problem?
Thanks!

Listen for UDP multicast packets

My AutoIt script should receive UDP multicast packets sent to 239.255.250.250:9131. But it doesn't work and I see no option to specify a UDP multicast address for UDPBind().
UDPBind() in below code returns error 10049 (invalid address):
UDPStartup()
UDPBind("239.255.250.250", 9131)
While 1
$msg = UDPRecv($recv, 512)
If $msg <> "" Then
ConsoleWrite($msg)
EndIf
Sleep(100)
WEnd
How to listen for UDP multicast packets?
You must not bind to the multicast address. Bind is a local operation which sets the listening interface (on Windows) and port.
To receive multicast you need to:
Bind to the IP address of the interface and port you want to receiv mutlicast on. On Windows bind to the IP address on the selected interface. On Linux bind to 0.0.0.0.
Join the multicast group using the appropriate mechanisms.

Why is IP_MULTICAST_IF and IPV6_MULTICAST_IF needed?

Say for example, my machine is multi-homed and has two network interfaces:
Wireless LAN adapter WiFi : Ip: 10.20.19.140
Ethernet adapter Ethernet: Ip: 10.20.19.154
I create two UDP sockets one listening on (1) and other on (2). The i am assuming the interface is already assigned, then why do i need IP_MULTICAST_IF and IPV6_MULTICAST_IF?
The IP_MULTICAST_IF or IPV6_MULTICAST_IF settings tell your socket which interface to send its multicast packets on. It's a separate, independent setting from the interface that you bound your socket to with bind(), since bind() controls which interface(s) the socket receives multicast packets from.
(Granted, the BSD sockets API implementers could have made the assumption that a socket would always want to send packets out over the same interface it receives packets on, but that would make a number of use cases more difficult; for example, if you are using a single socket to receive multicast packets from all interfaces (via INADDR_ANY), then when sending a packet using that socket you'd still need a way to specify which multicast interface you want that packet to be sent over)

Simulating multicasting on loopback interface

I'm writing a network application in ruby which should use UDP multicasting.
My problem is that I want to run multiple instances for testing purposes on localhost, but multicasting only works if I bind the socket to the real network interface.
Is there some way to enable multicasting for the loopback interface, so that all the 127.0.0.x get the message I send?
Currently I enable multicasting with:
ip = IPAddr.new('234.56.78.9').hton + IPAddr.new('0.0.0.0').hton
socket.setsockopt(Socket::IPPROTO_IP, Socket::IP_ADD_MEMBERSHIP,ip)
#socket.bind '127.0.0.1',1234 ##does not receive multicast :(
socket.bind '0.0.0.0',1234
Also, I noticed that if I e.g. bind the socket to 127.0.0.4 and send a message, in the packet the source ip is 127.0.0.1 anyway... is there a way to set the source IP so it shows the same IP I bound the socket to?
Solaris allows you to use multicast on the loopback device. For other operating systems you can enable IP_MULTICAST_LOOP on the sender (Unix) or the receiver (Windows) for similar effect.

Send UDP broadcast on Windows 7

I have a PC with two network cards connected to different networks (multi homed network setup). I want to send UDP broadcast frames on both networks. The senders IP address of the frames must be the IP address of the adapter, that is used to send the frame. The destination address should be the LIMITED BROADCAST address.
The customer application should not run with administrative rights (UAC is not acceptible).
How can I send these UDP frames to the LIMITED BROADCAST address (255.255.255.255)?
How could I send these frames to the NETWORK BROADCAST address (x.y.z.255)?
I know how to do this with raw sockets. But raw sockets can only be used with administrative rights.
Can't you just open two normal UDP sockets and bind one to each of the interface addresses and then simply send to the broadcast addresses ?
This will, as far as I know, deal with the sending on both networks and it will ensure that the packets sent will have the correct ip address. It wont work if you bind a single socket to INADDR_ANY which, of course, WILL work if there's only a single network adapter in the machine. To create a complete solution it's probably best to iterate over the available addresses and create a socket for each, bind to each and send from each.

Resources