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>
index | next in thread | raw e-mail
[-- Attachment #1 --]
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 = 1;
int fd, i;
char *stream = "224.1.1.1";
char *port = "1234";
char *buffer;
buffer = malloc (1500);
if (buffer == NULL)
{
fprintf(stderr, "Cannot allocate buffer space\n");
return -1;
}
memset((char *) &address, 0, sizeof(address));
address.sin_family = AF_INET;
address.sin_port = htons(atoi(port));
fd = 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 = 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;
mreq.imr_multiaddr.s_addr = address.sin_addr.s_addr;
mreq.imr_interface.s_addr = 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 = 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
cc -o stream stream.c
I would appreciate comments/suggestions. Again, works fine under
various cpus with Linux.
Sean
[-- Attachment #2 --]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (FreeBSD)
iD8DBQBBab37yQsGN30uGE4RAgMJAJ9/mqXpd10XJ2CvrRokDdAlLKUGtwCfYu9t
oh/uCF/eB/YsHu8Q/AkU+uI=
=Bp0U
-----END PGP SIGNATURE-----
help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1097448955.50197.13.camel>
