Sometimes it might be beneficial to redistribute unicast UDP traffic to multiple other clients. I tried to accomplish this using iptables but it doesn’t seem to be able to resend the packets to the local broadcast address.
This program provides a solution to this problem. It listens on a specified UDP port on all local addresses and resends those packets to the local broadcast address. To avoid creating a loop the incoming and outgoing ports must be different. The application can also ensure that only packets coming from a specified source are being retransmitted. While the latter doesn’t provide any real security since it is trivial to spoof the source IP address, it does provide some immunity from other applications.
The source code for the application (uc2bc) is included in the gzipped archive below. Just compile with “gcc -o uc2bc uc2bc.c”. A sample init script is also included. This would go in the /etc/init.d folder.
Thanks to Andreas who got me (re)started with socket programming on *NIX.