Hi,
I'm trying to send broadcast packets using real-time features. I found some 
troubles using the functions rt_dev_setsockopt and rt_dev_sendto: they both 
return negative values, so the packets can not be sent. I'm using rtnet-
0.9.10. 
This is my code:

static struct sockaddr_in local_addr;
static struct 
sockaddr_in dest_addr;

int sock, ret;
RT_TASK *lxrtnettsk;
MsgSync msg; 
/*message to send */

memset(&local_addr, 0, sizeof (struct sockaddr_in)); 

memset(&dest_addr, 0, sizeof (struct sockaddr_in));

/*local configuration */

local_addr.sin_family      = AF_INET;
local_addr.sin_port        = htons
(10000);
local_addr.sin_addr.s_addr = INADDR_ANY;

dest_addr.sin_family      = 
AF_INET;
dest_addr.sin_addr.s_addr = inet_addr("10.0.0.255"); /*network 
broadcast address */
dest_addr.sin_port        = htons(10000);

sock = 
rt_dev_socket(AF_INET, SOCK_DGRAM, 0); 
/*it returns a positive value, so it 
works correctly */

int broadcast = 1;
ret = rt_dev_setsockopt(sock, 
SOL_SOCKET, SO_BROADCAST, &broadcast, sizeof(broadcast)); 
/*it returns a 
negative value. It doesn't set the option on the socket */

lxrtnettsk = 
rt_task_init(4800, 1, 0, 0); 
/*start the real-time task */


rt_make_hard_real_time();

ret = rt_dev_bind(sock, (struct sockaddr *) 
&local_addr, sizeof(struct sockaddr_in)); 
/* It works correctly, returns 0 */


ret = rt_dev_sendto(sock,(void*) &msg, sizeof(msg), 0, (struct sockaddr *) 
&dest_addr, sizeof(struct sockaddr_in)); 
/*it returns a negative value, so it 
doesn't send anything */

rt_make_soft_real_time();
rt_dev_close(sock);

rt_task_delete(lxrtnettsk);


How can i do to fix this problem? 
Thanks for the 
help.

Ernesto

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
RTnet-users mailing list
RTnet-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rtnet-users

Reply via email to