I am trying to use UDP multicast in VxWorks without success. I have used
the sample code from WindRiver, see below, but the sendto() command fails
with errno = 0x41. Any hints?
/* includes */
#include "vxWorks.h"
#include "taskLib.h"
#include "socket.h"
#include "netinet/in.h"
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "sockLib.h"
#include "inetLib.h"
#include "ioLib.h"
#include "routeLib.h"
/* defines */
/* globals */
/* forward declarations */
STATUS mcastSend (char * mcastAddr, USHORT mcastPort, char * sendBuf,
int sendLen);
char * mcastRcv (char * ifAddr, char * mcastAddr, USHORT mcastPort,
int numRead);
/************************************************************************
* mcastSend - send a message to the multicast address
* This function sends a message to the multicast address
* The multicast group address to send, the port number, the pointer to the
* send buffer and the send buffer length are given as input parameters.
* RETURNS: OK if sucessful or ERROR
*/
STATUS mcastSend
char * mcastAddr, /* multicast address */
USHORT mcastPort, /* udp port number */
char * sendBuf, /* send Buffer */
int sendLen /* length of send buffer */
)
struct sockaddr_in sin;
struct sockaddr_in toAddr;
int toAddrLen;
int sockDesc;
char * bufPtr;
int len;
/* create a send and recv socket */
if ((sockDesc = socket (AF_INET, SOCK_DGRAM, 0)) < 0 )
printf (" cannot open send socket\n");
return (ERROR);
}
/* zero out the structures */
bzero ((char *)&sin, sizeof (sin));
bzero ((char *)&toAddr, sizeof (toAddr));
/* sin.sa_len = (u_char) sizeof(sin); */
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = INADDR_ANY;
sin.sin_port = htons(0);
if (bind(sockDesc, (struct sockaddr *)&sin, sizeof(sin)) != 0)
perror("bind");
if (sockDesc)
close (sockDesc);
return (ERROR);
}
toAddrLen = sizeof(struct sockaddr_in);
/* toAddr.sa_len = (u_char) toAddrLen; */
toAddr.sin_family = AF_INET;
/* initialize the address to the send */
toAddr.sin_addr.s_addr = inet_addr (mcastAddr);
/* initialize the port to send */
toAddr.sin_port = htons(mcastPort);
bufPtr = sendBuf; /* initialize the buffer pointer */
/* send the buffer */
while (sendLen > 0)
if ((len = sendto (sockDesc, bufPtr, sendLen, 0,
(struct sockaddr *)&toAddr, toAddrLen)) < 0 )
printf("mcastSend sendto errno:0x%x\n", errno );
break;
}
sendLen -= len;
bufPtr += len;
taskDelay (1); /* give a taskDelay */
}
if (sockDesc != ERROR)
close (sockDesc);
return (OK);
}
>
>
>I am trying to use UDP multicast in VxWorks without success. I have used
>the sample code from WindRiver, see below, but the sendto() command fails
>with errno = 0x41. Any hints?
>
<snip>
>/* sin.sa_len = (u_char) sizeof(sin); */
> sin.sin_family = AF_INET;
> sin.sin_addr.s_addr = INADDR_ANY;
> sin.sin_port = htons(0);
>
> if (bind(sockDesc, (struct sockaddr *)&sin, sizeof(sin)) != 0)
>
>
> perror("bind");
> if (sockDesc)
> close (sockDesc);
> return (ERROR);
> }
>
At this point in my initialization I configure the interface for
multicast, with somethin like :
setsockopt(send_socket,
IPPROTO_IP,
IP_MULTICAST_IF,
(char *)&sin.sin_addr.s_addr,
sizeof(sin.sin_addr.s_addr));
Then set TTL if there are any routers in that the message must
go through.
I am using 5.3.1 with the SENS and SENS upgrade patches applied.
> toAddrLen = sizeof(struct sockaddr_in);
>/* toAddr.sa_len = (u_char) toAddrLen; */
> toAddr.sin_family = AF_INET;
>
>
> /* initialize the address to the send */
> toAddr.sin_addr.s_addr = inet_addr (mcastAddr);
>
> /* initialize the port to send */
> toAddr.sin_port = htons(mcastPort);
>
> bufPtr = sendBuf; /* initialize the buffer pointer */
>
> /* send the buffer */
> while (sendLen > 0)
>
>
> if ((len = sendto (sockDesc, bufPtr, sendLen, 0,
> (struct sockaddr *)&toAddr, toAddrLen)) < 0 )
>
>
> printf("mcastSend sendto errno:0x%x\n", errno );
> break;
> }
>
> sendLen -= len;
> bufPtr += len;
>
> taskDelay (1); /* give a taskDelay */
> }
>
> if (sockDesc != ERROR)
> close (sockDesc);
>
> return (OK);
> }
>
>
>
================================================
Bob DeJoie
Kwajalein Missile Range
Republic of the Marshall Islands
email: rjde...@kmrmail.kmr.ll.mit.edu
phone: 805-355-5855 fax: 805-355-3833
Time Zone: GMT +12 hours
================================================