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: How to send UDP broadcast to 255.255.255.255?


On 2009-06-15, Sergei Gavrikov <sergei.gavrikov@gmail.com> wrote:
> Grant Edwards wrote:
>> I've been asked by one of my internal customers how to send a
>> UDP broadcast packet to IP address 255.255.255.255.
>> 
>> I tried setting the SO_BROADCAST option on the socket and then
>> using sendto() with a destination address of 255.255.255.255,
>> but it sends to the subnet broadcast address (in my case
>> 10.255.255.255) not to the global broadcast address of
>> 255.255.255.255 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 255.255.255.255
still produces a packet that's addressed to 10.255.255.255.

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
255.255.255.255 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
                               visi.com            Burbank!


-- 
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]