|
Home > Archive > Unix Programming > September 2007 > Receiving UDP Broadcasts on Solaris 9, 10
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Receiving UDP Broadcasts on Solaris 9, 10
|
|
| Jason Curl 2007-09-14, 7:22 pm |
| Hello,
On Linux and FreeBSD I can use the recvmsg() system call with messages
to retrieve the address of the local interface that received a broadcast
UDP packet, after binding locally to INADDR_ANY.
That is done with IP_PKTINFO and IP_RECVIF respectively. However, the
Solaris API doesn't provide the element msghdr.msg_control.
Is there equivalent functionality on Solaris, to get the IP address of
the interface that received the broadcast packet?
Binding to the broadcast address and receiving messages is not
desirable, as it's possible to have multiple interfaces with the same
broadcast address on a single machine.
Thanks,
Jason.
| |
| Barry Margolin 2007-09-15, 1:38 am |
| In article <46eb133c$0$7685$9b4e6d93@newsspool2.arcor-online.net>,
Jason Curl <j.m.curl@gmx.de> wrote:
> Hello,
>
> On Linux and FreeBSD I can use the recvmsg() system call with messages
> to retrieve the address of the local interface that received a broadcast
> UDP packet, after binding locally to INADDR_ANY.
>
> That is done with IP_PKTINFO and IP_RECVIF respectively. However, the
> Solaris API doesn't provide the element msghdr.msg_control.
>
> Is there equivalent functionality on Solaris, to get the IP address of
> the interface that received the broadcast packet?
>
> Binding to the broadcast address and receiving messages is not
> desirable, as it's possible to have multiple interfaces with the same
> broadcast address on a single machine.
The portable way to do things like this is to bind a different socket to
each local address. Then you know which interface it arrived on by
which socket you read it from.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
| |
| James Carlson 2007-09-17, 1:29 pm |
| Jason Curl <j.m.curl@gmx.de> writes:
> On Linux and FreeBSD I can use the recvmsg() system call with messages
> to retrieve the address of the local interface that received a
> broadcast UDP packet, after binding locally to INADDR_ANY.
>
> That is done with IP_PKTINFO and IP_RECVIF respectively. However, the
> Solaris API doesn't provide the element msghdr.msg_control.
You need to link against -lxnet library to get the ancillary data
(msg_control) interfaces. See libxnet(3LIB), standards(5), and
socket.h(3HEAD).
The short answer is to set -D_XOPEN_SOURCE=500 and link against
-lxnet.
As for IP_PKTINFO, that's present in the newer version of Solaris.
It's a relatively recent addition, though.
> Is there equivalent functionality on Solaris, to get the IP address of
> the interface that received the broadcast packet?
I don't think you want the address of the receiving interface.
Local addresses aren't necessarily unique if you have point-to-point
interfaces. Instead, an ifIndex number is better, which is what
IP_RECVIF will give you.
--
James Carlson, Solaris Networking <james.d.carlson@sun.com>
Sun Microsystems / 1 Network Drive 71.232W Vox +1 781 442 2084
MS UBUR02-212 / Burlington MA 01803-2757 42.496N Fax +1 781 442 1677
|
|
|
|
|