All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xenomai] RTnet -- receive broadcast frame at the local machine
@ 2016-02-29 20:24 Mariusz Janiak
  2016-02-29 20:29 ` Gilles Chanteperdrix
  0 siblings, 1 reply; 5+ messages in thread
From: Mariusz Janiak @ 2016-02-29 20:24 UTC (permalink / raw)
  To: Xenomai

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 port 
(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?

Best,
Mariusz




^ permalink raw reply	[flat|nested] 5+ messages in thread
* Re: [Xenomai] RTnet -- receive broadcast frame at the local machine
@ 2016-02-29 20:58 Mariusz Janiak
  2016-02-29 21:04 ` Gilles Chanteperdrix
  2016-02-29 21:08 ` Gilles Chanteperdrix
  0 siblings, 2 replies; 5+ messages in thread
From: Mariusz Janiak @ 2016-02-29 20:58 UTC (permalink / raw)
  To: Gilles Chanteperdrix; +Cc: Xenomai

Dnia Poniedziałek, 29 Lutego 2016 21:29 Gilles Chanteperdrix <gilles.chanteperdrix@xenomai.org> napisał(a) 
> On Mon, Feb 29, 2016 at 09:24:11PM +0100, Mariusz Janiak wrote:
> > 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 port 
> > (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.
> 
> -- 
> 					    Gilles.
> https://click-hack.org

Hi 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>
#define DEF_REC_PORT 1883

int sock;
struct sockaddr_in rec_addr;

int main()
{
  int enable = 1;
  int buffer[100];
  socklen_t len = sizeof(rec_addr);

  mlockall(MCL_CURRENT|MCL_FUTURE);

  sock = socket(AF_INET, SOCK_DGRAM, 0);
  setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &enable, sizeof(enable));

  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));

  while (1) {
    memset(buffer, 0, 100);
    recvfrom(sock, buffer, 100, 0, &rec_addr, &len);
    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>
#define DEF_SND_PORT 1883
#define DEF_SND_IP   "10.0.0.255"

int sock;
struct sockaddr_in snd_addr;
int ret, size;

int main()
{
  int enable = 1;
  struct in_addr  snd_ip;
  char buffer[] = "Hello";
  socklen_t len = sizeof(snd_addr);

  mlockall(MCL_CURRENT|MCL_FUTURE);

  inet_aton(DEF_SND_IP, &snd_ip);
  sock = socket(AF_INET, SOCK_DGRAM, 0);
  setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &enable, sizeof(enable));

  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;

  while (1) {
    ret = sendto(sock, buffer, 6, 0 , &snd_addr, len);
    sleep(1);
  }
  return 0;
}

Best,
Mariusz




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-02-29 21:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-29 20:24 [Xenomai] RTnet -- receive broadcast frame at the local machine Mariusz Janiak
2016-02-29 20:29 ` Gilles Chanteperdrix
  -- strict thread matches above, loose matches on Subject: below --
2016-02-29 20:58 Mariusz Janiak
2016-02-29 21:04 ` Gilles Chanteperdrix
2016-02-29 21:08 ` Gilles Chanteperdrix

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.