Brandon Rozek

Photo of Brandon Rozek

PhD Student @ RPI studying Automated Reasoning in AI and Linux Enthusiast.

Multicast Receive Script

Published on

Updated on

Warning: This post has not been modified for over 2 years. For technical posts, make sure that it is still relevant.

I use socat to debug mutlicast traffic, though the syntax for it is complicated to learn. Here is the command that I normally use to debug multicast traffic.

socat UDP4-RECVFROM:"$port",ip-add-membership="$multicast_address":,fork -

This says to:

  • Listen to UDP traffic from $port.
  • Subscribe to $multicast_address.
  • means to do it from the interface that matches the routing table for the multicast address.
  • The rest makes it print the traffic to standard out.

To make life easier I created a little script called mrecv that takes a multicast address and port and forms the socat command for me.


show_usage() {
    echo "Usage: mrecv [multicast_address] [port]"
    exit 1

contains_help_flag() {
    if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
        return 0
    return 1

if [ "$#" -ne 2 ] ||
   contains_help_flag "$1" ||
   contains_help_flag "$2"; then


socat UDP4-RECVFROM:"$port",ip-add-membership="$multicast_address":,fork -
Reply via Email Buy me a Coffee
Was this useful? Feel free to share: Hacker News Reddit Twitter

Published a response to this? :