Multicast Sockets - More Programming Tips

Date: Tue, 16 Nov 1999 13:13:29 -0500 (EST)
From: David Ott 
To: COMP 249 -- Anand Srinivasan ,
     Sanjoy Baruah , Alex Blate ,
     Steven Boles , Wei Chao Chen ,
     Deepak Bandyopadhyay , Felix Hernandez ,
     Kevin Jeffay , Abdelkarim Mardini ,
     David Ott , Praveen Patnala ,
     Ramkumar Parameswaran , Ruigang Yang ,
     Vibhor Jain , Zhiwei Xiao 
Subject: more notes on multicast sockets

A couple more notes on multicast sockets for HW5:

1. A host who has subscribed to a multicast group is by default in
loopback mode (ie. it also receives any packets that it sends to the
multicast group).  To turn this off, you can use setsockopt with the
IP_MULTICAST_LOOP macro.  See man setsockopt for details on how to turn
off options.  See /usr/include/netinet/in.h for the IP_MULTICAST_LOOP

2. To make nee167 listen for multicast packets on the right network
interface, you will need to specify the interface in your setsockopt
ADD_MEMBERSHIP call.  Do this by assigning the second field in the mreq
struct (see /usr/include/netinet/in.h) which looks like this:
 * Argument structure for IP_ADD_MEMBERSHIP and IP_DROP_MEMBERSHIP.
struct ip_mreq {
        struct  in_addr imr_multiaddr; /*IP multicast address of group */
        struct  in_addr imr_interface; /*local IP address of interface */

nee167 has two network interfaces:    nee     (dept net)   nee167  (comp 249 net)

You'll want to use the latter.  Ruiyang gives an examples of how to make
this assignment as follows:

Date: Tue, 16 Nov 1999 01:07:54 -0500 (EST)
From: Ruigang Yang 
Subject: NIC setup

here is the code to change the NIC
    struct hostent * group2;

    group2 = gethostbyname("nee167");

    if (group2 == 0) 
      perror("can't get NIC IP:");

    bcopy((void*)group2->h_addr, (void*)&ia, group2->h_length); 
    bcopy(&ia,  &mreq.imr_interface.s_addr, sizeof(struct in_addr));

Good luck. -d

D. Ott 11/15/99