Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 11 Aug 1995 14:09:26 -0400
From:      Garrett Wollman <wollman@halloran-eldar.lcs.mit.edu>
To:        current@freebsd.org
Subject:   Another way of finding the destination of a received UDP packet
Message-ID:  <9508111809.AA07865@halloran-eldar.lcs.mit.edu>

next in thread | raw e-mail | index | archive | help
Earlier we had a discussion on the lengths that various programs
needed to go to in order to figure out the destination address to
which a packet which was just received had been sent.  I was leafing
through someone else's copy of Stevens volume 1, and noticed a
description of the behavior documented here (taken from ip(4)):

     If the IP_RECVDSTADDR option is enabled on a SOCK_DGRAM socket, the
     recvmsg call will return the destination IP address for a UDP datagram.
     The msg_control field in the msghdr structure points to a buffer that
     contains a cmsghdr structure followed by the IP address.  The cmsghdr
     fields have the following values:

     cmsg_len = sizeof(struct in_addr)
     cmsg_level = IPPROTO_IP
     cmsg_type = IP_RECVDSTADDR

So it is possible to avoid binding a socket for every interface.
Instead, a program can create a single socket for listening, and then
create and destroy one for each message sent in reply to a previous
query.

I don't propose to actually implement this in anything myself...  It
might be useful or necessary to also provide an IP_RECVIF or some such
for certain applications which care about interfaces.

-GAWollman

--
Garrett A. Wollman   | Shashish is simple, it's discreet, it's brief. ... 
wollman@lcs.mit.edu  | Shashish is the bonding of hearts in spite of distance.
Opinions not those of| It is a bond more powerful than absence.  We like people
MIT, LCS, ANA, or NSA| who like Shashish.  - Claude McKenzie + Florent Vollant



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?9508111809.AA07865>