RTnet -- receive broadcast frame at the local machine
Dnia Wtorek, 1 Marca 2016 07:57 Gilles Chanteperdrix <[email protected]> napisał(a)
Quoted 8 lines · Mariusz Janiak
Quoted 7 lines
Dnia Poniedziałek, 29 Lutego 2016 22:08 Gilles Chanteperdrix <[email protected]> napisał(a)
Quoted 6 lines · Mariusz Janiak
Quoted 5 lines
Dnia Poniedziałek, 29 Lutego 2016 21:29 Gilles Chanteperdrix <[email protected]> napisał(a)
Quoted 4 lines · Mariusz Janiak
Quoted 3 lines
Dear Xenomai users,
Since RTnet has been integrated with Xenomai I address this question to you. The question is, how to receive a broadcast frame at the local machine without using the localhost? The issue is following, we have two process with separate rtsockets at the single machine (of course we have different machines in the network but this is not a case). One process send a broadcast UDP frame to the specified UDP port -- we have one rteth device on the machine. The second process listen on
that
Quoted 157 lines
Quoted 147 lines
port
Quoted 125 lines
Quoted 35 lines
Quoted 14 lines
Quoted 6 lines
(receivefrom) and does not receive the broadcast frame sent by first process. I have found the following thread on the RTnet mailing list
https://sourceforge.net/p/rtnet/mailman/message/6787561/
Could you please point me the place which should be hacked to duplicate outgoing packets if there are multiple matching routes?
I ma not sure I understand what you are looking for, but to receive on a host the frames sent by that host, you need to enable and load the loopback module. When you do that, no hack should be needed.
Signature · 2 lines
Gilles. https://click-hack.orgHi Gilles,
I am pretty sure that loopback module has been loaded, this is standard RTnet configuration that has not been changed by me. Beside that, there is rtlo (127.0.0.1) device which is created when RT_LOOPBACK="yes" in rtnet.conf.
Below you will find simple testcase. Compile this using Xenomai posix skin.
1)
receiver.c
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <rtnet.h>
#defineDEF_REC_PORT1883int sock;
structsockaddr_inrec_addr;Quoted 7 lines
int
main()
{
int enable = 1;
int buffer[100];
socklen_tlen =sizeof(rec_addr);mlockall(MCL_CURRENT|MCL_FUTURE);1->
Quoted 2 lines
sock = socket(AF_INET, SOCK_DGRAM, 0);2->
Quoted 1 line
setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &enable, sizeof(enable));3->
Quoted 7 lines
memset(&rec_addr, 0, sizeof(struct sockaddr_in)); rec_addr.sin_family = AF_INET; rec_addr.sin_port = htons(DEF_REC_PORT); rec_addr.sin_addr.s_addr = INADDR_ANY; bind(sock, (struct sockaddr *) &rec_addr, sizeof(struct sockaddr_in));4->
Quoted 4 lines
while (1) { memset(buffer, 0, 100); recvfrom(sock, buffer, 100, 0, &rec_addr, &len);5->
Quoted 23 lines
printf("%s\n", buffer);}
close(sock);
return 0;
}2.
sender.c
#include <unistd.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <rtnet.h>
#include <rtnet_config.h>
#defineDEF_SND_PORT1883
#defineDEF_SND_IP"10.0.0.255"int sock;
structsockaddr_insnd_addr;
int ret, size;Quoted 8 lines
int
main()
{
int enable = 1;
structin_addrsnd_ip;
char buffer[] = "Hello";
socklen_tlen =sizeof(snd_addr);mlockall(MCL_CURRENT|MCL_FUTURE);6->
Quoted 2 lines
inet_aton(DEF_SND_IP, &snd_ip);7->
Quoted 1 line
sock = socket(AF_INET, SOCK_DGRAM, 0);8->
Quoted 2 lines
setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &enable, sizeof(enable));9->
Quoted 6 lines
memset(&snd_addr, 0, sizeof(struct sockaddr_in)); snd_addr.sin_family = AF_INET; snd_addr.sin_port = htons(DEF_SND_PORT); snd_addr.sin_addr = snd_ip;Quoted 11 lines
Quoted 2 lines
while (1) { ret = sendto(sock, buffer, 6, 0 , &snd_addr, len);10->
So, that is 10 function calls without checking the return value. Please check the function return values.
Signature · 2 lines
Gilles. https://click-hack.orgYou are right the test case has not been perfect. The answer to the first question, sending to unicast cause that receiver get frames. Regarding the return values of the syscalls when broadcast
1 -> 0
2 -> 896
3 -> -1
4 -> 0Five is not printed because of waiting on recvfrom
Quoted 9 lines
6 -> 0
7 -> 1
8 -> 897
9 -> -1
10 -> -1
10 -> -1
10 -> -1
10 -> -1
10 -> -1
Quoted 7 lines
So, finally, the problem is that
SO_BROADCASTis not implemented for RTnet sockets, and that RTnet sendto does not work for a broadcast address?Signature · 2 lines
Gilles. https://click-hack.org
It does work, but when you receive on remote host, and it doesn't when receive on the same host. According to this post on the RTnet forum
https://sourceforge.net/p/rtnet/mailman/message/26686897/
the RT-UDP sockets have SO_BROADCAST automatically enabled.
Mariusz
Quoted 175 lines · Mariusz Janiak
Dnia Wtorek, 1 Marca 2016 07:57 Gilles Chanteperdrix <[email protected]> napisa³(a)
Quoted 8 lines · Mariusz Janiak
Quoted 7 lines
Dnia Poniedzia³ek, 29 Lutego 2016 22:08 Gilles Chanteperdrix <[email protected]> napisa³(a)
Quoted 6 lines · Mariusz Janiak
Quoted 5 lines
Dnia Poniedzia³ek, 29 Lutego 2016 21:29 Gilles Chanteperdrix <[email protected]> napisa³(a)
Quoted 4 lines · Mariusz Janiak
Quoted 3 lines
Dear Xenomai users,
Since RTnet has been integrated with Xenomai I address this question to you. The question is, how to receive a broadcast frame at the local machine without using the localhost? The issue is following, we have two process with separate rtsockets at the single machine (of course we have different machines in the network but this is not a case). One process send a broadcast UDP frame to the specified UDP port -- we have one rteth device on the machine. The second process listen on
that
Quoted 157 lines
Quoted 147 lines
port
Quoted 125 lines
Quoted 35 lines
Quoted 14 lines
Quoted 6 lines
(receivefrom) and does not receive the broadcast frame sent by first process. I have found the following thread on the RTnet mailing list
https://sourceforge.net/p/rtnet/mailman/message/6787561/
Could you please point me the place which should be hacked to duplicate outgoing packets if there are multiple matching routes?
I ma not sure I understand what you are looking for, but to receive on a host the frames sent by that host, you need to enable and load the loopback module. When you do that, no hack should be needed.
Signature · 2 lines
Gilles. https://click-hack.orgHi Gilles,
I am pretty sure that loopback module has been loaded, this is standard RTnet configuration that has not been changed by me. Beside that, there is rtlo (127.0.0.1) device which is created when RT_LOOPBACK="yes" in rtnet.conf.
Below you will find simple testcase. Compile this using Xenomai posix skin.
1)
receiver.c
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <rtnet.h>
#defineDEF_REC_PORT1883int sock;
structsockaddr_inrec_addr;Quoted 7 lines
int
main()
{
int enable = 1;
int buffer[100];
socklen_tlen =sizeof(rec_addr);mlockall(MCL_CURRENT|MCL_FUTURE);1->
Quoted 2 lines
sock = socket(AF_INET, SOCK_DGRAM, 0);2->
Quoted 1 line
setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &enable, sizeof(enable));3->
Quoted 7 lines
memset(&rec_addr, 0, sizeof(struct sockaddr_in)); rec_addr.sin_family = AF_INET; rec_addr.sin_port = htons(DEF_REC_PORT); rec_addr.sin_addr.s_addr = INADDR_ANY; bind(sock, (struct sockaddr *) &rec_addr, sizeof(struct sockaddr_in));4->
Quoted 4 lines
while (1) { memset(buffer, 0, 100); recvfrom(sock, buffer, 100, 0, &rec_addr, &len);5->
Quoted 23 lines
printf("%s\n", buffer);}
close(sock);
return 0;
}2.
sender.c
#include <unistd.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <rtnet.h>
#include <rtnet_config.h>
#defineDEF_SND_PORT1883
#defineDEF_SND_IP"10.0.0.255"int sock;
structsockaddr_insnd_addr;
int ret, size;Quoted 8 lines
int
main()
{
int enable = 1;
structin_addrsnd_ip;
char buffer[] = "Hello";
socklen_tlen =sizeof(snd_addr);mlockall(MCL_CURRENT|MCL_FUTURE);6->
Quoted 2 lines
inet_aton(DEF_SND_IP, &snd_ip);7->
Quoted 1 line
sock = socket(AF_INET, SOCK_DGRAM, 0);8->
Quoted 2 lines
setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &enable, sizeof(enable));9->
Quoted 6 lines
memset(&snd_addr, 0, sizeof(struct sockaddr_in)); snd_addr.sin_family = AF_INET; snd_addr.sin_port = htons(DEF_SND_PORT); snd_addr.sin_addr = snd_ip;Quoted 11 lines
Quoted 2 lines
while (1) { ret = sendto(sock, buffer, 6, 0 , &snd_addr, len);10->
So, that is 10 function calls without checking the return value. Please check the function return values.
Signature · 2 lines
Gilles. https://click-hack.orgYou are right the test case has not been perfect. The answer to the first question, sending to unicast cause that receiver get frames. Regarding the return values of the syscalls when broadcast
1 -> 0
2 -> 896
3 -> -1
4 -> 0Five is not printed because of waiting on recvfrom
Quoted 9 lines
6 -> 0
7 -> 1
8 -> 897
9 -> -1
10 -> -1
10 -> -1
10 -> -1
10 -> -1
10 -> -1Quoted 7 lines
So, finally, the problem is that
SO_BROADCASTis not implemented for RTnet sockets, and that RTnet sendto does not work for a broadcast address?Signature · 2 lines
Gilles. https://click-hack.org
Quoted 7 lines
It does work, but when you receive on remote host, and it doesn't when receive on the same host. According to this post on the RTnet forum
https://sourceforge.net/p/rtnet/mailman/message/26686897/
the RT-UDP sockets have
SO_BROADCASTautomatically enabled.From what I understand from this post, it is not easy to fix, as it
requires duplicating packets. So, patch welcome.
The thing that I do not understand though, is that according to what you said, "sendto" fails, what is the value of errno when it fails. Maybe you do not know it, because you do not seem to be used to checking for errors, but when a unix call fails, it returns -1 and sets errno, the interesting information is errno.
Signature · 2 lines
Gilles. https://click-hack.org