This is the mail archive of the 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: How to send UDP broadcast to

On 2009-06-15, Sergei Gavrikov <> wrote:
> Grant Edwards wrote:
>> I've been asked by one of my internal customers how to send a
>> UDP broadcast packet to IP address
>> I tried setting the SO_BROADCAST option on the socket and then
>> using sendto() with a destination address of,
>> but it sends to the subnet broadcast address (in my case
>> not to the global broadcast address of
>> that I specified in the sendto() call.
> [snip]
>>   if ((bytesSent = sendto(socket_fd, send_buf, packetSize, 0, (struct sockaddr *)&encoder_addr, sizeof encoder_addr)) == -1)
> Hi,
> I noticed one thing only. What's about sendto's flags? they talk about
> `MSG_DONTROUTE' sendto flag for your needs:
> packages/net/tcpip/current/doc/sendto.html
> perhaps, that's it.

I just tried it, and it doesn't change the behavior of
broadcasts. Specifying a destination address of
still produces a packet that's addressed to

The description of MSG_DONTROUTE is

       Bypasses the usual routing table lookup and sends the
       packet directly to the interface described by the
       destination address. This is usually used only by
       diagnostic or routing programs.

In my case, the destination doesn't describe a particular
interface.  One might presume a broadcast sent to would be sent out on all interfaces.
Google did find me a posting to a BSD mailing list that seemed
to claim that the option IP_ONESBCAST would do what I wanted to
do. I looked at the ip(4) man page on a FreeBSD 6.1 system, and
the description of IP_ONESBCAST didn't agree with what the
mailing list posting said.  I tested it on FreeBSD 6.1, and it
doesn't do anything relevent.  eCos doesn't have the
IP_ONESBCAST option anyway....

Grant Edwards                   grante             Yow! I own seven-eighths of
                                  at               all the artists in downtown

Before posting, please read the FAQ:
and search the list archive:

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