This is the mail archive of the ecos-discuss@sourceware.org mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Re: How to send UDP broadcast to 255.255.255.255?


Jay Foster wrote:

> You can try the following patch that someone added
> to my local source.  It adds a CDL option
> (CYGOPT_NET_INET_FORCE_DIRECTED_BROADCAST

I also stumbled upon the problem mentioned in the
older post and I'd like to confirm that the
patch from

  http://www.mail-archive.com/ecos-discuss@ecos.sourceware.org/msg09992.html

seems to really help. Using this and setting the default
route to my interface (code borrowed from the ppp)

static int setDefaultRoute(u_int32_t g, int cmd)
{
  static int rtm_seq;
  int routes;
  struct {
    struct rt_msghdr	hdr;
    struct sockaddr_in	dst;
    struct sockaddr_in	gway;
    struct sockaddr_in	mask;
  } rtmsg;

  if ((routes = socket(PF_ROUTE, SOCK_RAW, AF_INET)) < 0) {

    diag_printf("Couldn't %s default route: socket: %d\n",
      cmd=='s'? "add": "delete",errno);
    return 0;
  }

  memset(&rtmsg, 0, sizeof(rtmsg));
  rtmsg.hdr.rtm_type = cmd == 's'? RTM_ADD: RTM_DELETE;
  rtmsg.hdr.rtm_flags = RTF_UP | RTF_GATEWAY | RTF_STATIC;
  rtmsg.hdr.rtm_version = RTM_VERSION;
  rtmsg.hdr.rtm_seq = ++rtm_seq;
  rtmsg.hdr.rtm_addrs = RTA_DST | RTA_GATEWAY | RTA_NETMASK;
  rtmsg.dst.sin_len = sizeof(rtmsg.dst);
  rtmsg.dst.sin_family = AF_INET;
  rtmsg.gway.sin_len = sizeof(rtmsg.gway);
  rtmsg.gway.sin_family = AF_INET;
  rtmsg.gway.sin_addr.s_addr = g;
  rtmsg.mask.sin_len = sizeof(rtmsg.dst);
  rtmsg.mask.sin_family = AF_INET;

  rtmsg.hdr.rtm_msglen = sizeof(rtmsg);
  if (write(routes, &rtmsg, sizeof(rtmsg)) < 0) {
    diag_printf("Couldn't %s default route: %d\n",
      cmd=='s'? "add": "delete",errno);
    close(routes);
    return 0;
  }

  close(routes);

  return 1;
}


I am able to send the broadcasts as I intended.

I'd vote for the inclusion of the option in the main tree.

Thanks
-- 
                                Stano

-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]