Multicast Receive Script

Brandon Rozek

November 18, 2020

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":0.0.0.0,fork -

This says to:

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.

#!/bin/bash

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

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

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

multicast_address="$1"
port="$2"

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