1

I'm not sure if I've just missed some documentation or not, but I'm having a hard time figuring out how to set up a launchd agent that can be triggered whenever a datagram is received within a multicast group.

What I'd like to know is what a launchd plist should look like to provide a simple datagram listener that is bound to a multicast group.

Here's what I've been trying:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>foo.bar</string>
    <key>Program</key>
    <string>/foo/bar</string>
    <key>Sockets</key>
    <dict>
        <key>Listeners</key>
        <dict>
            <key>SockType</key>
            <string>dgram</string>
            <key>SockServiceName</key>
            <string>12345</string>
            <key>SockFamily</key>
            <string>IPv4</string>
            <key>MulticastSocket</key>
            <string>224.0.0.253</string>
        </dict>
    </dict>
    <key>inetdCompatibility</key>
    <dict>
        <key>Wait</key>
        <false/>
    </dict>
</dict>
</plist>

But it just generates getaddrinfo errors ("nodename nor servname provided, or not known"). Removing the multicast group to just setup a UDP port seems to work fine, but I don't really want to have to hard code an IP address or local DNS.

Are there any good examples of how to create a multicast listening launch agent or daemon using launchd? Or am I missing some other step, or misunderstanding what data I should be entering for a multicast group?

  • What is a multicast listening launch agent? And a datagram listener? Although I have created numerous launch agents, I have never seen these terms/jargon. – CousinCocaine Jun 25 '14 at 6:33
  • 1
    You can create launch agents with a list of sockets, if they receive a message on one of these then the program is launchd with the message on standard input. Multicasting is UDP (datagrams) where a message is simply sent out to all machines in the network with no need to connect to them first, and any that choose to can respond. – Haravikk Jun 26 '14 at 7:16
  • 1
    how may i test a working launchd Multicast Socket Listener daemon means how may i invoke such a datagram? – klanomath Oct 14 '14 at 17:52
  • 1
    You can test sending of a UDP message by doing something like echo 'My message' | nc -uw 1 localhost 6000 to send the message to a service listening to port 6000 on your local machine. Not sure if nc supports sending multicast messages (I don't see an option) but it lets you test when sending directly to a single machine. – Haravikk Oct 15 '14 at 18:42
1

I set this one up using LaunchControl.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>foo/bar</string>
    <key>Program</key>
    <string>/foo/bar</string>
    <key>Sockets</key>
    <dict>
        <key>Sock1</key>
        <dict>
            <key>MulticastGroup</key>
            <string>224.0.0.253</string>
            <key>SockFamily</key>
            <string>IPv4</string>
            <key>SockProtocol</key>
            <string>UDP</string>
            <key>SockServiceName</key>
            <string>12345</string>
            <key>SockType</key>
            <string>dgram</string>
        </dict>
    </dict>
    <key>inetdCompatibility</key>
    <dict>
        <key>Wait</key>
        <true/>
    </dict>
</dict>
</plist>
  • Thanks for the response! Were you able to verify this in any way? I've given the same basic file a try, simply using cat as the program and redirecting stdout and stderr (using the appropriate plist keys) but it's not producing any output. Instead I'm getting a bunch of "no such file or directory" errors from execv(). I've tried replacing cat with a simple shell script and confirmed the correct path, but that won't work either. – Haravikk Oct 9 '14 at 11:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .