From owner-freebsd-net@FreeBSD.ORG Thu Apr 19 05:47:50 2012 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 105BC1065670 for ; Thu, 19 Apr 2012 05:47:50 +0000 (UTC) (envelope-from bra@fsn.hu) Received: from people.fsn.hu (people.fsn.hu [195.228.252.137]) by mx1.freebsd.org (Postfix) with ESMTP id B19628FC0C for ; Thu, 19 Apr 2012 05:47:49 +0000 (UTC) Received: by people.fsn.hu (Postfix, from userid 1001) id 98611CBD98E; Thu, 19 Apr 2012 07:41:38 +0200 (CEST) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.2 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MF-ACE0E1EA [pR: 11.0999] X-CRM114-CacheID: sfid-20120419_07413_EBD187D1 X-CRM114-Status: Good ( pR: 11.0999 ) X-DSPAM-Result: Whitelisted X-DSPAM-Processed: Thu Apr 19 07:41:38 2012 X-DSPAM-Confidence: 0.6874 X-DSPAM-Probability: 0.0000 X-DSPAM-Signature: 4f8fa592633041250412649 X-DSPAM-Factors: 27, From*Attila Nagy , 0.00010, User-Agent*i686, 0.00894, User-Agent*Linux+i686, 0.00998, Date*19+Apr, 0.99000, Date*41+37, 0.99000, Date*07+41, 0.99000, User-Agent*i686+en, 0.01301, User-Agent*Mozilla/5.0+(X11, 0.01377, User-Agent*Linux, 0.01986, User-Agent*U+Linux, 0.02451, User-Agent*rv+1.8.1.23), 0.02776, User-Agent*1.8.1.23), 0.02776, User-Agent*Thunderbird/2.0.0.23, 0.02776, From*Nagy, 0.02776, Received*for+; Thu, 19 Apr 2012 07:41:37 +0200 (CEST) Message-ID: <4F8FA591.4010503@fsn.hu> Date: Thu, 19 Apr 2012 07:41:37 +0200 From: Attila Nagy User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.23) Gecko/20090817 Thunderbird/2.0.0.23 Mnenhy/0.7.6.0 To: freebsd-net@freebsd.org Content-Transfer-Encoding: 7bit MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Subject: SO_BINDTODEVICE or equivalent? X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 19 Apr 2012 05:47:50 -0000 Hi, I want to solve the classic problem of a DHCP server: listening for broadcast UDP packets and figuring out what interface a packet has come in. The Linux solution is SO_BINDTODEVICE, which according to socket(7): SO_BINDTODEVICE Bind this socket to a particular device like "eth0", as specified in the passed interface name. If the name is an empty string or the option length is zero, the socket device binding is removed. The passed option is a variable-length null-terminated interface name string with the maximum size of IFNAMSIZ. If a socket is bound to an interface, only packets received from that particular interface are processed by the socket. Note that this only works for some socket types, particularly AF_INET sockets. It is not supported for packet sockets (use normal [1]bind(2) there). This makes it possible to listen on selected interfaces for (broadcast) packets. FreeBSD currently doesn't implement this feature. Any chances that somebody will do this? What alternatives would you recommend? Raw packet access (like BPF and RAW sockets) finally make the application to do more -mainly useless- work. Are there any other solutions, which doesn't require additional packet parsing? Thanks, References 1. http://linux.die.net/man/2/bind