I'm trying to write a multicast client in C to run on RHL 8. The goal
is to connect to a microsoft media server on a small lan. I've tried to
write a simple test program, but it never sees any packets. We have a
windows system that is receiving the stream, so it is present on the
network.
The test program takes the port & ip address of the multicast server
from the command line (code is below)
It doesn't work. Any ideas? (ifconfig shows MULTICAST, do I need to do
anything else to enable it?) I also tried a version with connect &
read; same results - they just sit waiting for packets)
if (!inet_aton(argv[1], &name.sin_addr))
{
printf("Invalid host address\n");
return(-1);
}
/* ------------------ */
/* init output socket */
/* ------------------ */
sock = socket(PF_INET, SOCK_DGRAM, 0);
if (sock < 0)
{
printf("Socket open failure\n");
return;
}
name.sin_family = PF_INET;
name.sin_port = htons(port);
i=SO_REUSEADDR;
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &i, sizeof(i)))
{
perror("Could not create socket options: setsockopt()");
return 0;
}
if (bind(sock, (struct sockaddr *)&name, sizeof(name)))
{
perror("binding datagram socket");
return(-1);
}
printf("Waiting for data...\n");
for ( ; 1 ; )
{
i = sizeof(name);
if ((n = recvfrom(sock, &sockbuf[0], sizeof(sockbuf), 0,
(struct sockaddr *)&name, &i)) < 0)
perror("recvfrom() failed. ");
printf("read %i bytes\n", n);
}
close(sock);
}
|