multicasting not working - qnx 6.3

I am having problems porting multicasting code from LINUX into QNX 6.3 (forgive my posting in this group, but i’m having 15-minute page download times from openqnx.com website and couldn’t wait an hour just to navitage to another group).

I have an example program that simplifies what I’m trying to accomplish: If I can get it running in QNX, I can get the system I’m trying to port to run in it.

Here’s the example:
/////////////////////////////////////////////////////////
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <errno.h>
#include <malloc.h>
#include <sys/socket.h>
#include <resolv.h>
#include <arpa/inet.h>
#include <stdarg.h>
#include <sched.h>
#include <signal.h>
#include <sys/types.h>
#include <unistd.h>

/---------------------------------------------------------------------/
/— panic - print message and die. —/
/---------------------------------------------------------------------/
void panic (char *msg, …)
{
va_list ap;

va_start (ap, msg);
vprintf (msg, ap);
perror (“errno”);
va_end (ap);
exit(1);
}

/---------------------------------------------------------------------/
/— Receiver - listens for and collects multicast packets. —/
/---------------------------------------------------------------------/
int Receiver (int sd)
{
char buffer[1024];
struct sockaddr_in addr;
int len = sizeof (addr);

puts (“Receiver”);
do
{
if (recvfrom(sd, buffer, sizeof (buffer), 0, (struct sockaddr *) &addr,(socklen_t *) & len) > 0)
printf (“Got %s:%d “%s”\n”, inet_ntoa (addr.sin_addr),ntohs (addr.sin_port), buffer);
} while (strcmp (buffer, “bye\n”) != 0);

fprintf (stderr, “Receiver exiting\n”);
exit (0);
}

/---------------------------------------------------------------------/
/— main - creates multicast-capable socket and sends test packets—/
/---------------------------------------------------------------------/
int main (int argc, char argv[])
{
int sd;
const int on = 1;
struct ip_mreq mreq;
struct sockaddr_in addr;
char buffer[1024];
int port=21000,port2=21000;
const char
ip = “224.0.17.42”;

sd = socket (PF_INET, SOCK_DGRAM, 0);
if (sd < 0)
panic (“socket failed”);

bzero (&addr, sizeof (addr));
addr.sin_family = AF_INET;
addr.sin_port = htons (port);
addr.sin_addr.s_addr = INADDR_ANY;

if (bind (sd, (struct sockaddr *) &addr, sizeof (addr)) != 0)
panic (“bind failed”);

if (setsockopt (sd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != 0)
panic (“Can’t reuse address/ports”);

if (inet_aton (ip, &mreq.imr_multiaddr) == 0)
panic (“address (%s) bad”, ip);

mreq.imr_interface.s_addr = INADDR_ANY;
if(setsockopt (sd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof (mreq)) !=0)
panic (“Join multicast failed”);

addr.sin_port = htons (port2);
if (inet_aton (ip, &addr.sin_addr) == 0)
panic (“inet_aton failed (%s)”, ip);

if (fork ())
Receiver (sd);
else
shutdown (sd, 0); /* close the input channel */
puts (“Server starting”);
do
{
sleep (1);
strcpy (buffer, “TESTING 1 2 3”);
puts (“Sending…”);
if(sendto(sd, buffer, strlen (buffer) + 1, 0, (struct sockaddr *) &addr,sizeof (addr)) < 0)
perror (“sendto”);
} while (strcmp (buffer, “bye”) != 0);
sleep (6000);
close (sd);
return 0;
}
/////////////////////////////////////////////////////////

This program compiles and runs under LINUX. It compiles and runs in QNX and although it doesn’t create any errors, the receiver thread never gets the data sent by the sender thread. The program is basically 2 threads: One sends data, the other receives and reports what it gets.

I read something about QNX having multiple protocol stack libraries: I’m using whatever was installed by default.

Does anyone have an idea what might be wrong with the program, or perhaps the QNX environment?

Many thanks!

-e