Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 10 Oct 2004 15:55:56 -0700
From:      Sean McNeil <sean@mcneil.com>
To:        freebsd-current@freebsd.org
Subject:   help with multicast read (broken?)
Message-ID:  <1097448955.50197.13.camel@server>

next in thread | raw e-mail | index | archive | help

--=-6boT8RKXpl6Isv2o7zB4
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable

I just installed 5.3-B7 on an i386 machine.  All went well, but I cannot
get it to read data from a multicast address.  I wrote a program that
works just fine on both x86 and ppc linux platforms.  It does the
following:

    struct sockaddr_in address;
    int reuse_addr =3D 1;
    int fd, i;
    char *stream =3D "224.1.1.1";
    char *port =3D "1234";
    char *buffer;

    buffer =3D malloc (1500);
    if (buffer =3D=3D NULL)
    {
	fprintf(stderr, "Cannot allocate buffer space\n");
	return -1;
    }

    memset((char *) &address, 0, sizeof(address));
    address.sin_family =3D AF_INET;
    address.sin_port =3D htons(atoi(port));

    fd =3D socket(PF_INET, SOCK_DGRAM, 0);
    if (fd < 0) {
	fprintf(stderr, "Cannot open socket for stream %s\n", stream);
	return -1;
    }

    setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &reuse_addr,
sizeof(reuse_addr));

    address.sin_addr.s_addr =3D inet_addr(stream);

    if (bind(fd, (struct sockaddr *) &address, sizeof(address)) < 0) {
	fprintf(stderr, "Cannot bind to stream %s\n", stream);
	close(fd);
	return -1;
    }

    if (IN_MULTICAST(address.sin_addr.s_addr)) {

	struct ip_mreq mreq;=20

	mreq.imr_multiaddr.s_addr =3D address.sin_addr.s_addr;
	mreq.imr_interface.s_addr =3D htonl(INADDR_ANY);

	if (setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP,
		       &mreq, sizeof(mreq)) < 0) {
	    fprintf(stderr, "Cannot join multicast for %s\n", stream);
	    close(fd);
	    return -1;
	}
    }

    i =3D recvfrom(fd, buffer, 1500, 0, NULL, NULL);


recvfrom never returns.  I've looked at my program with sockstat and it
has 224.1.1.1:1234 open for foreign address *:*.  Anyone see a problem
here?

I've placed my complete program at

www.mcneil.com/~sean/freebsd/stream.c

you can compile simply as=20

cc -o stream stream.c

I would appreciate comments/suggestions.  Again, works fine under
various cpus with Linux.

Sean


--=-6boT8RKXpl6Isv2o7zB4
Content-Type: application/pgp-signature; name=signature.asc
Content-Description: This is a digitally signed message part

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (FreeBSD)

iD8DBQBBab37yQsGN30uGE4RAgMJAJ9/mqXpd10XJ2CvrRokDdAlLKUGtwCfYu9t
oh/uCF/eB/YsHu8Q/AkU+uI=
=Bp0U
-----END PGP SIGNATURE-----

--=-6boT8RKXpl6Isv2o7zB4--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1097448955.50197.13.camel>