Multicast Sockets - Programming Tips


Here are a few tips on working with multicast sockets and UNIX (FreeBSD).

  1. Sending socket. In general, there's nothing special you need to do on the sending end. The key is simply to send to a multicast IP (group) address. Tips:

  2. Receiving socket. Receiving is nearly the same, but with one additional system call: setsockopt().

  3. Other multicast socket options. A list of additional options is below.

            IP_MULTICAST_IF    /* u_char; set/get IP multicast i/f  */
            IP_MULTICAST_TTL   /* u_char; set/get IP multicast ttl */
            IP_MULTICAST_LOOP  /* u_char; set/get IP multicast loopback */
            IP_ADD_MEMBERSHIP  /* ip_mreq; add an IP group membership */
            IP_DROP_MEMBERSHIP /* ip_mreq; drop an IP group membership */
    

    Use IP_ADD_MEMBERSHIP and IP_DROP_MEMBERSHIP to switch multicast groups "listened" for by the recieving socket. Use IP_MULTICAST_LOOP if you would like the sender to also receive a copy of what is sent to the group. I don't believe IP_MULTICAST_IF or IP_MULTICAST_TTL will be of interest for what we're doing.

  4. Further reading.


D. Ott 9/29/99