[ECOS] Re: How to send UDP broadcast to

Stanislav Meduna stano@meduna.org
Tue Aug 11 13:32:00 GMT 2009

Jay Foster wrote:

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

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


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


  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.


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

More information about the Ecos-discuss mailing list