From: Jay Foster <jay@systech.com>
To: 'Grant Edwards' <grante@visi.com>, ecos-discuss@sources.redhat.com
Subject: RE: [ECOS] Re: How to send UDP broadcast to 255.255.255.255?
Date: Tue, 16 Jun 2009 16:14:00 -0000 [thread overview]
Message-ID: <E8269B3B134D0449B017B595BDBEAB840627D4@mail.systech.com> (raw)
You can try the following patch that someone added to my local source. It
adds a CDL option (CYGOPT_NET_INET_FORCE_DIRECTED_BROADCAST) to modify this
behavior (the default being the same behavior you have now). Sorry it isn't
in "patch" format, but it is straight forward. What is not shown here is
configuring this option to '0' in your applications .ecm or template file.
int
in_pcbladdr(inp, nam, plocal_sin)
register struct inpcb *inp;
struct sockaddr *nam;
struct sockaddr_in **plocal_sin;
{
struct in_ifaddr *ia;
register struct sockaddr_in *sin = (struct sockaddr_in *)nam;
if (nam->sa_len != sizeof (*sin))
return (EINVAL);
if (sin->sin_family != AF_INET)
return (EAFNOSUPPORT);
if (sin->sin_port == 0)
return (EADDRNOTAVAIL);
if (!TAILQ_EMPTY(&in_ifaddrhead)) {
/*
* If the destination address is INADDR_ANY,
* use the primary local address.
* If the supplied address is INADDR_BROADCAST,
* and the primary interface supports broadcast,
* choose the broadcast address for that interface.
*/
#define satosin(sa) ((struct sockaddr_in *)(sa))
#define sintosa(sin) ((struct sockaddr *)(sin))
#define ifatoia(ifa) ((struct in_ifaddr *)(ifa))
if (sin->sin_addr.s_addr == INADDR_ANY)
sin->sin_addr =
IA_SIN(TAILQ_FIRST(&in_ifaddrhead))->sin_addr;
#ifdef CYGOPT_NET_INET_FORCE_DIRECTED_BROADCAST
else if (sin->sin_addr.s_addr == (u_long)INADDR_BROADCAST &&
(TAILQ_FIRST(&in_ifaddrhead)->ia_ifp->if_flags &
IFF_BROADCAST))
sin->sin_addr =
satosin(&TAILQ_FIRST(&in_ifaddrhead)->ia_broadaddr)->sin_addr;
#endif
}
if (inp->inp_laddr.s_addr == INADDR_ANY) {
register struct route *ro;
From net.cdl:
cdl_component CYGPKG_NET_INET {
display "INET support"
active_if CYGPKG_NET_STACK_INET
flavor bool
no_define
default_value 1
description "
This option enables support for INET (IP) network processing."
define INET
compile \
inet_addr.c \
inet_ntoa.c \
inet_ntop.c \
inet_pton.c \
bootp_support.c \
dhcp_support.c \
dhcp_prot.c \
network_support.c \
getproto.c \
getserv.c
compile getaddrinfo.c \
ifaddrs.c
cdl_option CYGOPT_NET_INET_FORCE_DIRECTED_BROADCAST {
display "Convert limited broadcast addresses into directed
broadcasts"
flavor bool
default_value 1
description "
De-facto IP stack implementations often convert
INADDR_BROADCAST
destination addresses into a more specific directed
broadcast
address according to the address configuration of the
primary
network interface. Over time, this behavior has been
criticized
for various reasons. The primary reason is that it becomes
impossible to send UDP packets to 255.255.255.255 once the
primary network (broadcast) interface is configured with
address
information."
}
Jay
-----Original Message-----
From: Grant Edwards [mailto:grante@visi.com]
Sent: Tuesday, June 16, 2009 7:23 AM
To: ecos-discuss@sources.redhat.com
Subject: [ECOS] Re: How to send UDP broadcast to 255.255.255.255?
On 2009-06-16, Andrew Lunn <andrew@lunn.ch> wrote:
> On Mon, Jun 15, 2009 at 05:41:54PM +0000, 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.
>
> Hi Grant
>
> If you have a debugger handy, try putting a break point here:
I don't have one handy, but it certainly looks like the right
spot.
> src/sys/netinet/in_pcb.c
> int
> in_pcbladdr(inp, nam, plocal_sin)
> register struct inpcb *inp;
> struct sockaddr *nam;
> struct sockaddr_in **plocal_sin;
> {
> struct in_ifaddr *ia;
> register struct sockaddr_in *sin = (struct sockaddr_in *)nam;
>
> if (nam->sa_len != sizeof (*sin))
> return (EINVAL);
> if (sin->sin_family != AF_INET)
> return (EAFNOSUPPORT);
> if (sin->sin_port == 0)
> return (EADDRNOTAVAIL);
> if (!TAILQ_EMPTY(&in_ifaddrhead)) {
> /*
> * If the destination address is INADDR_ANY,
> * use the primary local address.
> * If the supplied address is INADDR_BROADCAST,
> * and the primary interface supports broadcast,
> * choose the broadcast address for that interface.
> */
> #define satosin(sa) ((struct sockaddr_in *)(sa))
> #define sintosa(sin) ((struct sockaddr *)(sin))
> #define ifatoia(ifa) ((struct in_ifaddr *)(ifa))
> if (sin->sin_addr.s_addr == INADDR_ANY)
> sin->sin_addr =
IA_SIN(TAILQ_FIRST(&in_ifaddrhead))->sin_addr;
> else if (sin->sin_addr.s_addr == (u_long)INADDR_BROADCAST
&&
> (TAILQ_FIRST(&in_ifaddrhead)->ia_ifp->if_flags &
IFF_BROADCAST))
> sin->sin_addr =
satosin(&TAILQ_FIRST(&in_ifaddrhead)->ia_broadaddr)->sin_addr;
>
> Unfortunately, if this is the place the address is being changed, i
> don't see an obvious way around this.
I've been doing some experiments on a FreeBSD 6.1 system, and
it won't allow applications to send a 255.255.255.255 broadcast
either. In fact, it _requires_ you to specify the interface's
broadcast address as a destination before in order to broadcast
a packet. FreeBSD 6.1 won't "convert" 255.255.255.255 into the
interface broadcast address the way that eCos does.
Still, the Linux implementation seems to be a lot more useful.
You can specify either 255.255.255.255 or the interface's
broadcast address as the destination, and the packet is
broadcast to that destination address.
I found complaints dating back many years regarding FreeBSD's
lack of ability to send broadcast UDP packets to
255.255.255.255. It seems you have to use the raw socket
interface to do that.
--
Grant Edwards grante Yow! Pardon me, but do
you
at know what it means to be
visi.com TRULY ONE with your
BOOTH!
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss
next reply other threads:[~2009-06-16 16:14 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-06-16 16:14 Jay Foster [this message]
2009-06-16 19:01 ` Grant Edwards
2009-06-16 19:56 ` Gary Thomas
2009-06-16 20:26 ` Grant Edwards
-- strict thread matches above, loose matches on Subject: below --
2009-08-11 13:32 Stanislav Meduna
2009-08-12 5:02 ` Mandeep Sandhu
2009-08-12 13:19 ` Mandeep Sandhu
2009-08-13 5:54 ` Mandeep Sandhu
2009-08-12 13:25 ` Stanislav Meduna
2009-06-15 17:42 [ECOS] " Grant Edwards
2009-06-15 20:36 ` Sergei Gavrikov
2009-06-15 22:14 ` [ECOS] " Grant Edwards
2009-06-16 6:44 ` [ECOS] " Andrew Lunn
2009-06-16 14:23 ` [ECOS] " Grant Edwards
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=E8269B3B134D0449B017B595BDBEAB840627D4@mail.systech.com \
--to=jay@systech.com \
--cc=ecos-discuss@sources.redhat.com \
--cc=grante@visi.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).