From owner-freebsd-current Fri Aug 11 11:09:51 1995 Return-Path: current-owner Received: (from majordom@localhost) by freefall.FreeBSD.org (8.6.11/8.6.6) id LAA00671 for current-outgoing; Fri, 11 Aug 1995 11:09:51 -0700 Received: from halloran-eldar.lcs.mit.edu (halloran-eldar.lcs.mit.edu [18.26.0.159]) by freefall.FreeBSD.org (8.6.11/8.6.6) with SMTP id LAA00635 for ; Fri, 11 Aug 1995 11:09:39 -0700 Received: by halloran-eldar.lcs.mit.edu; (5.65/1.1.3.6) id AA07865; Fri, 11 Aug 1995 14:09:26 -0400 Date: Fri, 11 Aug 1995 14:09:26 -0400 From: Garrett Wollman Message-Id: <9508111809.AA07865@halloran-eldar.lcs.mit.edu> To: current@freebsd.org Subject: Another way of finding the destination of a received UDP packet Sender: current-owner@freebsd.org Precedence: bulk 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