[Nottingham] Easy linux network multicast?

Charles Samuels charles at kde.org
Tue May 16 16:27:50 BST 2006


Cam wrote, on Tuesday 2006 May 16 2:40 pm:
> Martin
>
> > So how can you easily multicast a few GBytes of binary data to multiple
> > machines on a LAN?
>
> I can't think of an easy way that's a true multicast. You could look at
> videolan for streaming but your few Gb might have to be an MPEG file.
>
> You could possibly multicast out a file using netcat -u, and receive it
> with netcat -l, but you'd have to
>
> 1. start and stop manually
> 2. verify integrity afterwards using rsync or similar

For true multicast, there's a few things you need to know about:
- you need to set up a specific route on the "multicast network"
- it needs to be UDP (duh!) 
- you need to account for dropped/out of order packets
- you send to the multicast address, not the recipients' address or a 
broadcast address
- it may be easier to broadcast and not multicast
- you need to "subscribe" as such:

	if (IN6_IS_ADDR_MULTICAST(addr6->sin6_addr.s6_addr))
	{ // ipv6
		struct ipv6_mreq mreq;
		mreq.ipv6mr_interface = 0;
		std::memcpy(&mreq.ipv6mr_multiaddr, &addr6->sin6_addr, sizeof(in6_addr));

		setsockopt(mFd, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, &mreq, sizeof(mreq));
	}

	if(IN_MULTICAST(ntohl(addr4->sin_addr.s_addr)))
	{ // ipv4
		struct ip_mreq mreq;
		mreq.imr_multiaddr.s_addr = addr4->sin_addr.s_addr;
		mreq.imr_interface.s_addr = htonl(INADDR_ANY);

		setsockopt(mFd,IPPROTO_IP,IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq));
	}

(the client you are using needs to support multicast directly)

Unless you're serious about performance, go with TCP.
Unless you have a reason to use multicast, use broadcast
You'll probably need to write code to use multicast or broadcast unless you 
can find something on the 'net.

good luck!



More information about the Nottingham mailing list