Does anyone know the full procedure to configuring the TCP/IP mutlicast
operation on QNX 4.25
-Tom Fitzgerald
Hi. I’m doing a lot of multicast in my current project. Here are the
steps we took (at least, those that I can remember):
- Upgraded to TCP/IP 5.
- Made sure the necessary Net.* drivers had the -M argument.
- Decided which block of multicast IP addresses we’d be using (in our
case, 224.x.x.x and 225.x.x.x), then set up routing information (where
necessary). Note that multicast is routable; 224.0.0.0 and 225.0.0.0
entries need to be added to the routing tables. We also decided on port
numbers to use. - Started coding. On the sending side, the code is roughly as follows
(all error checking removed for clarity); it seems pretty much identical
to what you did in your previous post:
// Create a UDP socket.
sendSockfd = socket(AF_INET, SOCK_DGRAM, 0);
// Turn off automatic loopback of multicast transmissions.
flag = 0;
setsockopt(sendSockfd, IPPROTO_IP, IP_MULTICAST_LOOP, &flag,
sizeof(flag));
// Set up the destination address.
memset(&cliAddr, 0, sizeof(cliAddr));
cliAddr.sin_family = AF_INET; // Use the INET
protocol.
cliAddr.sin_addr.s_addr = inet_addr(“224.0.0.1”); // The address we’re
sending to, arbitrary.
cliAddr.sin_port = htons(1234); // Port number we’re
using, arbitrary.
// Send the data.
sendto(sendSockfd, data, sizeOfData, 0, (sstruct sockaddr *)cliAddr,
sizeof(struct sockaddr_in));
On the receiving end:
// Create the receiving socket.
recvSockfd = socket(AF_INET, SOCK_DGRAM, 0);
// Set up the socket information.
memset(&stsAddr, 0, sizeof(stsAddr));
stsAddr.sin_family = AF_INET; // Use the INET protocol.
stsAddr.sin_addr.s_addr = htonl(INADDR_ANY); // Receive from any
address.
stsAddr.sin_port = htons(1234); // Same port number.
// Bind the information to the socket.
bind(recvSockfd, (struct sockaddr *)&stsAddr, sizeof(stsAddr));
//***** IMPORTANT
// Set up the socket to receive multicast.
mreq.imr_multiaddr.s_addr = inet_addr(shm->configData.stsMAddr);
mreq.imr_interface.s_addr = INADDR_ANY;
setsockopt(recvSockfd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq,
sizeof(mreq));
// Receive data.
length = sizeof(sockaddr);
bytesReceived = recvfrom(recvSockfd, (void *)&data, sizeof(data), 0,
(struct sockaddr *)&cliAddr, &length);
This has worked fine for us. We relied heavily on Stevens’s UNIX
Network Programming book for the coding end, and largely did the
configuration on a trial-and-error basis.
Josh Hamacher
FAAC Incorporated
Tom Fitzgerald wrote:
Does anyone know the full procedure to configuring the TCP/IP mutlicast
operation on QNX 4.25-Tom Fitzgerald
Josh,
In reference to the following…
- Decided which block of multicast IP addresses we’d be using (in our
case, 224.x.x.x and 225.x.x.x), then set up routing information (where
necessary).
… where is it necessary ot set-up the routing information?
-Tom Fitzgerald
Josh Hamacher <hamacher@faac.com> wrote in message
news:3ADC315E.D1ADA2C6@faac.com…
Hi. I’m doing a lot of multicast in my current project. Here are the
steps we took (at least, those that I can remember):
- Upgraded to TCP/IP 5.
- Made sure the necessary Net.* drivers had the -M argument.
- Decided which block of multicast IP addresses we’d be using (in our
case, 224.x.x.x and 225.x.x.x), then set up routing information (where
necessary). Note that multicast is routable; 224.0.0.0 and 225.0.0.0
entries need to be added to the routing tables. We also decided on port
numbers to use.- Started coding. On the sending side, the code is roughly as follows
(all error checking removed for clarity); it seems pretty much identical
to what you did in your previous post:// Create a UDP socket.
sendSockfd = socket(AF_INET, SOCK_DGRAM, 0);// Turn off automatic loopback of multicast transmissions.
flag = 0;
setsockopt(sendSockfd, IPPROTO_IP, IP_MULTICAST_LOOP, &flag,
sizeof(flag));// Set up the destination address.
memset(&cliAddr, 0, sizeof(cliAddr));
cliAddr.sin_family = AF_INET; // Use the INET
protocol.
cliAddr.sin_addr.s_addr = inet_addr(“224.0.0.1”); // The address we’re
sending to, arbitrary.
cliAddr.sin_port = htons(1234); // Port number we’re
using, arbitrary.// Send the data.
sendto(sendSockfd, data, sizeOfData, 0, (sstruct sockaddr *)cliAddr,
sizeof(struct sockaddr_in));
On the receiving end:// Create the receiving socket.
recvSockfd = socket(AF_INET, SOCK_DGRAM, 0);// Set up the socket information.
memset(&stsAddr, 0, sizeof(stsAddr));
stsAddr.sin_family = AF_INET; // Use the INET protocol.
stsAddr.sin_addr.s_addr = htonl(INADDR_ANY); // Receive from any
address.
stsAddr.sin_port = htons(1234); // Same port number.// Bind the information to the socket.
bind(recvSockfd, (struct sockaddr *)&stsAddr, sizeof(stsAddr));file://***** IMPORTANT
// Set up the socket to receive multicast.
mreq.imr_multiaddr.s_addr = inet_addr(shm->configData.stsMAddr);
mreq.imr_interface.s_addr = INADDR_ANY;
setsockopt(recvSockfd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq,
sizeof(mreq));// Receive data.
length = sizeof(sockaddr);
bytesReceived = recvfrom(recvSockfd, (void *)&data, sizeof(data), 0,
(struct sockaddr *)&cliAddr, &length);
This has worked fine for us. We relied heavily on Stevens’s UNIX
Network Programming book for the coding end, and largely did the
configuration on a trial-and-error basis.Josh Hamacher
FAAC Incorporated
Tom Fitzgerald wrote:Does anyone know the full procedure to configuring the TCP/IP mutlicast
operation on QNX 4.25-Tom
Fitzgerald
You can display the current routing information with ‘netstat -nr’. To
change routing, use ‘/usr/ucb/route add [routable address block]
[gateway address]’. Our multicast systems are all set up on a single
network (connected via a single hub) with IP addresses 192.168.4.1,
192.168.4.2, etc. So each system on the network has a command
‘/usr/ucb/route add 224.0.0.0 192.168.4.1’ in its sysinit, with the each
machine using its own IP address.
Josh Hamacher
FAAC Incorporated