Subject: Re: Broadcasting to 255.255.255.255
To: None <netbsd-users@netbsd.org>
From: Takahiro Kambe <taca@back-street.net>
List: netbsd-users
Date: 07/14/2007 01:29:35
In message <46979972.8000406@cat.co.za>
on Fri, 13 Jul 2007 17:25:38 +0200,
Ian McIntosh <ianm@cat.co.za> wrote:
> Stevens Network Programming vol 1 says in section 18.2 Broadcast Addresses
> (p. 471):
>
> "Most hosts allow [sending a UDP datagram to 255.255.255.255] [...] and
> convert the address to the subnet-directed broadcast address of the
> outgoing interface. BSD/OS has [...] IP_ONESBCAST, and when set, the
> destination IP address for broadcasts is 255.255.255.255 [...]"
>
> NetBSD doesn't have this option, so how do we do it?
in_pcbconnect() in sys/netinet/in_pcb.c, there are these code gragments.
if (TAILQ_FIRST(&in_ifaddrhead) != 0) {
/*
* If the destination address is INADDR_ANY,
* use any local address (likely loopback).
* If the supplied address is INADDR_BROADCAST,
* use the broadcast address of an interface
* which supports broadcast. (loopback does not)
*/
if (in_nullhost(sin->sin_addr)) {
sin->sin_addr =
TAILQ_FIRST(&in_ifaddrhead)->ia_addr.sin_addr;
} else if (sin->sin_addr.s_addr == INADDR_BROADCAST) {
TAILQ_FOREACH(ia, &in_ifaddrhead, ia_list) {
if (ia->ia_ifp->if_flags & IFF_BROADCAST) {
sin->sin_addr =
ia->ia_broadaddr.sin_addr;
break;
}
}
}
...
I don't know when this code exists, but maybe it is after 4.3BSD and
it seems that NetBSD has this code from revision 1.1.
--
Takahiro Kambe <taca@back-street.net>