Receiving broadcast OSC messages on Linux
Posted: Mon Jul 04, 2022 9:35 pm
Hi, I'm currently developing an embedded device (Wireless Buzzer) that should control QLC+ (Linux in my case) via OSC messages. In QLC+, there is one OSC "Mapping" line in the Inputs/Outputs tab for each network address found (which makes sense). However, on Linux, there is currently no way to receive OSC messages that have been sent to the "global broadcast address" (255.255.255.255) or to the "network-local broadcast address" (for example 192.168.0.255).
This is because currently, QLC+ binds the input- and output sockets to the IP address (which makes sense to have the correct source address, and for broadcasting: the correct sender interface) but on Linux, this doesn't allow reception of broadcast packages (see https://stackoverflow.com/questions/543 ... -interface and https://stackoverflow.com/questions/120 ... 24#1215424). Windows seems to behave differently (didn't check, just found the info online) and I honestly don't know how macOS might react.
Online, one can find four approaches to fix this:
- SO_BINDTODEVICE. This allow reception of broadcasts when bound but only works when running as root => not a valid option
- binding to INADDR_ANY, setting IP_PKTINFO and filtering (see https://stackoverflow.com/questions/120 ... 24#1215424): Works but is quite some effort, especially since implementation will get OS-specific
- binding to INADDR_ANY and doing "manual" filtering of acceptable packages via source and destination address
- Using THREE input sockets. The first one will be bound to the "unicast" IPv4-address of the network card (as done now), the second one will be bound to the "network-local broadcast address" (to be calculated from the IPv4 address and the subnet mask) and the third will be bound to the global broadcast address. Packages incoming on any of the sockets will be handled. This behaviour could be made to be always applied automatically (only applied on affected platforms (Linux and/or macOS)) OR could be configurable by the user (checkbox "receive broadcast" in the OSC configuration dialog) (not my preferred choice since the user might not be aware of that the problem is)
Massimo, any chance that a PR implementing this will get merged? Which option would you prefer? I didn't do much coding or testing yet, wanted to get your opinion first.
Jannis
This is because currently, QLC+ binds the input- and output sockets to the IP address (which makes sense to have the correct source address, and for broadcasting: the correct sender interface) but on Linux, this doesn't allow reception of broadcast packages (see https://stackoverflow.com/questions/543 ... -interface and https://stackoverflow.com/questions/120 ... 24#1215424). Windows seems to behave differently (didn't check, just found the info online) and I honestly don't know how macOS might react.
Online, one can find four approaches to fix this:
- SO_BINDTODEVICE. This allow reception of broadcasts when bound but only works when running as root => not a valid option
- binding to INADDR_ANY, setting IP_PKTINFO and filtering (see https://stackoverflow.com/questions/120 ... 24#1215424): Works but is quite some effort, especially since implementation will get OS-specific
- binding to INADDR_ANY and doing "manual" filtering of acceptable packages via source and destination address
- Using THREE input sockets. The first one will be bound to the "unicast" IPv4-address of the network card (as done now), the second one will be bound to the "network-local broadcast address" (to be calculated from the IPv4 address and the subnet mask) and the third will be bound to the global broadcast address. Packages incoming on any of the sockets will be handled. This behaviour could be made to be always applied automatically (only applied on affected platforms (Linux and/or macOS)) OR could be configurable by the user (checkbox "receive broadcast" in the OSC configuration dialog) (not my preferred choice since the user might not be aware of that the problem is)
Massimo, any chance that a PR implementing this will get merged? Which option would you prefer? I didn't do much coding or testing yet, wanted to get your opinion first.
Jannis