Listen for UDP multicast packets - windows

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.

Related

UDP Multicast Windows CPP

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?

C++ Understanding boost asio multicast receiver

I have recently started trying to learn the boost multicast receiver example and what it is doing [code]. I understand basic multicast receivers/sends but I have been struggling to understand a few things:
Within the code they have a listener address and a multicast address. Is the multicast address the address on the local machine that the packet is being sent to, while the listener address is the address of the machine?
Followup to the first question - In the default code they have the listener address as 0.0.0.0 . In older network code I never explicitly came into contact with this. What is the purpose of the listen address and is there any good reference for what its uses are?
When I set the listener address to 0.0.0.0 and my multicast address to 224.0.0.10 and run a netstat I cannot find the multicast address. I would expect to see the address that I am listening on unless I am not understanding something correctly.

Same host UDP packet correlation in Go

In Go one can send UDP packets using net.Addr interface to specify the target endpoint. Some special addresses, e.g. :8080 and 0.0.0.0, sends packets using local loopback interface. When received, still on the same host, the message's net.Addr shows [::1]:8080 as source. What is the the easiest way to determine that the packet was sent and received by the same host?
Here's an example in the Go Playground. It shows 0.0.0.0:8080 (ipv4) instead of [::1]:8080.
I ended up using net.Dial("udp", addr) and eminently closing the connection. Dial also resolves hostnames, which I also needed.
Would be nice to avoid creating a socket, but Dial works for now.
:8080 is not an address, it is a port number, typically used when testing your own http websites on Windows because on Windows you cannot easily use port 80, the actual http port.
This will only use the loopback interface if you use localhost as the IP address.
The localhost address for IPv4 is 127.0.0.1 and for IPv6 it is ::1. The address 0.0.0.0 is usually used as a placeholder address to indicate, for example, listening on all IP addresses, see this question.
As mentioned in the comment, you can use net.IP.Equal to check if your peer is localhost. Just compare your address in question to 127.0.0.1 or to ::1, the net.IP.Equal function considers them equal.

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.

Resources