Subject: Re: More sockets and link-local multicast questions
To: Andrew White <awhite@arc.corp.mot.com>
From: Nick Amato <naamato@nexthop.com>
List: tech-net
Date: 10/10/2001 22:19:07
On Thu, Oct 11, 2001 at 11:40:22AM +1000, Andrew White wrote:
> I'm seeing some "features" in my programs using sockets and link-local
> multicast, and would like some assistance.  The symptoms are identical on
> NetBSD 1.5 and FreeBSD (i386), and almost identical on Darwin 1.3.7 (under
> IPv4 only), so I expect the errors are my own.
> 
> 
> The aim:
> 
> Pick a link-local multicast address (say 224.0.0.127) and port (say 9001). 
> Listen on that address and port on each interface, and receive messages from
> that interface.  Most important, associate the received message with the
> interface without using the source address / routing table.
> 
> My current technique is:
> 
> Create one socket per interface (say 2: en0 and en1).
> Bind (with REUSEPORT) each socket to 224.0.0.127.9001.
> Socket sock_en0 joins mcast group 224.0.0.127 on en0.  sock_en1 does the
> same on en1.
> 
> Problem: packets received on either en0 or en1 are delivered to both
> sockets.
> 
> What is the correct way to do this?

Shouldn't you be using:

	setsockopt(sock, IPPROTO_IP, IP_ADD_MEMBERSHIP,
	    &mreq, sizeof(mreq));

after using bind(2) to attach to port 9001?

Nick Amato