Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 16 Aug 2000 10:48:53 -0700
From:      Wilbert de Graaf <wilbertdg@hetnet.nl>
To:        deepika kakrania <deepika_77@yahoo.com>
Cc:        freebsd-net@FreeBSD.ORG
Subject:   Re: Sending multicast packets
Message-ID:  <399AD405.2C17E9CC@hetnet.nl>
References:  <20000816095123.290.qmail@web3003.mail.yahoo.com>

next in thread | previous in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format.
--------------F9656FEC92FDF0E485BDC321
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit


Hi deepika,

> two routers which are on the same LAN have to exchange
> multicast packets. To test the multicasting
> capability, i have taken 2 sample programs. Both of
> them are joining same multicast group and therefrom i
> have considered two cases.

First of all, try to connect both host on the same LAN. This has to work
otherwise your application fails (or routing is not right on the sending
host). If you don't join correctly, tcpdump won't show you the packet
you expected since the ethernet adapter will not accept the packet (if
it can handle multicast right).

If it doesn't work, you can try these applications:
mshow.c       ; attached
UDPSend.java  ; from my IGMPv3 for FreeBSD website at
http://home.hetnet.nl/~wilbertdg/igmpv3.html

One on of them run: mshow 224.5.5.5 5010
And on the other:   java UDPSend 224.5.5.5 5010 "hi there"

> 1)One program will send multicast packets to multicast
> group and other will be receiving. I ran tcpdump on
> both the machines to see the flow of packets. The
> applications are sending and receiving packets but
> tcpdump doesn't show any packet flow between these
> two.
> It only shows igmp report and leave packets. We could
> see the proper flow of packets only once using
> tcpdump.
> After that tcpdump is not showing any packet flow.

On the system that sends you should really see the packets, unless your
default route is not right.

> 2)both programs will be sending and receiving
> packets.In this, both applications first join
> multicast group and then one application sends packet
> to this multicast group and other will read these
> packets and then will write back same packet which
> should be read by first application. But here, second
> application doesn't receive the first packet itself.
> Here also, tcpdump doesn't show any packets flowing
> between these two routers.
> 
> Could someone explain to me why there is no packet
> flow in second case(in both directions
> simultaneously)?

First focuss on the hosts themselves. If that works start to debug
routing.

- Wilbert
--------------F9656FEC92FDF0E485BDC321
Content-Type: text/plain; charset=us-ascii;
 name="mshow.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="mshow.c"


/**
 *
 * mshow - Show some multicast traffic, using a multicast filter
 *
 * Usage: mshow <group ip or name> <udp port>
 *
 **/

#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <net/if.h>
#include <netdb.h>

#define MAX_MSG			1024
#define MAX_SOURCES		100	

/*
 * int main()
 */

int main(int argc, char *argv[])
{
	struct sockaddr_in sa;
	struct hostent *addr; 
	struct ip_mreq mreq;
	/*
	struct ip_msfilter *imsfp;
	char buffer[IP_MSFILTER_SIZE(MAX_SOURCES)];
	*/
	struct in_addr ia;
	u_short port;
	int s, i, nsources, on = 1;
	char *group, msg[MAX_MSG];
	int len, sz, err;

	/* Determine options 
	 */
	/* if (argc < 4) { */
	if (argc < 2) {
		printf("Usage: mshow <group> <port> [<filtermode> <sources>]\n");
		exit(0);
	}
	/* imsfp = (struct ip_msfilter*) &buffer; */
	group = argv[1];
	printf("group = %s\n", group);
	port = (u_short) atoi(argv[2]);
	printf("port  = %u\n", port);
	if (port == 0) {
		printf("Usage: mshow <group> <port> <filtermode> <sources>\n");
		exit(0);
	}
	/*
	if (argv[3][0] == 'e')
		imsfp->imsf_fmode = MCAST_EXCLUDE;
	else	
		imsfp->imsf_fmode = MCAST_INCLUDE;
	printf("fmode = %s\n", (imsfp->imsf_fmode == MCAST_INCLUDE) ?
		"include" : "exclude");
	nsources = 0;
	for (i=4; i<argc; i++) {
		imsfp->imsf_slist[nsources].s_addr = inet_addr(argv[i]);
		if (imsfp->imsf_slist[nsources].s_addr == INADDR_NONE) {
			printf("Invalid sources\n");
			exit(0);
		}
		nsources++;
	}
	imsfp->imsf_numsrc = nsources;
	*/

	/* create socket
	 */
	if (-1 == (s = socket(AF_INET, SOCK_DGRAM, 0))) {
		perror("failed to create a socket\n");
	}

	/* determine remote
	 */
	if (-1 == (ia.s_addr = inet_addr(group))) {
		if (NULL == (addr = gethostbyname(group))) {
			perror("failed to resolve");
			return(-1);
		}
		memcpy(&ia.s_addr, addr->h_addr_list[0], addr->h_length);
	}

	printf("joining group: %s\n", inet_ntoa(ia));

	/* join the group and set sourcefilter
	 */
	setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (void*) &on, sizeof(on)); 
	memcpy(&mreq.imr_multiaddr, &ia.s_addr, sizeof(struct in_addr));
	ia.s_addr = htonl(INADDR_ANY);
	memcpy(&mreq.imr_interface, &ia.s_addr, sizeof(struct in_addr));
	if (setsockopt(s, IPPROTO_IP, IP_ADD_MEMBERSHIP, (void*) &mreq, sizeof(mreq))) {
		perror("failed to join");
	}
	/*
	imsfp->imsf_multiaddr.s_addr = mreq.imr_multiaddr.s_addr;	
	imsfp->imsf_interface.s_addr = mreq.imr_interface.s_addr;
	if (ioctl(s, SIO_SET_MULTICAST_FILTER, imsfp) != 0) {
		perror("failed to set sourcefilter\n");
		exit(0);
	}
	*/

	/* receive and print response 
	 */
	sa.sin_family = AF_INET;
	sa.sin_port = htons(port);
	sa.sin_addr.s_addr = ia.s_addr; 
	bind(s, (struct sockaddr*) &sa, sizeof(sa));

	while (1) {
		len = recvfrom(s, msg, sizeof(msg), 0, (struct sockaddr*) &sa, &sz);
		if (len > 0) {
			msg[len] = '\0';
			printf("from %s (%d bytes):\n%s\n", inet_ntoa(sa.sin_addr), len, msg);
		}
		else {
			printf("failed\n");
			break;
		}
	}

	/* bye
	 */
	close(s);
	return(0);
}


--------------F9656FEC92FDF0E485BDC321--



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-net" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?399AD405.2C17E9CC>