From owner-freebsd-hackers@FreeBSD.ORG Wed Apr 16 11:07:40 2003 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id A49D837B401 for ; Wed, 16 Apr 2003 11:07:40 -0700 (PDT) Received: from srv1.cosmo-project.de (srv1.cosmo-project.de [213.83.6.106]) by mx1.FreeBSD.org (Postfix) with ESMTP id E2AEB43FBF for ; Wed, 16 Apr 2003 11:07:38 -0700 (PDT) (envelope-from ticso@cicely9.cicely.de) Received: from cicely5.cicely.de (cicely5.cicely.de [IPv6:3ffe:400:8d0:301:200:92ff:fe9b:20e7]) by srv1.cosmo-project.de (8.12.9/8.12.9) with ESMTP id h3GI79cx098878 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=OK); Wed, 16 Apr 2003 20:07:26 +0200 (CEST) (envelope-from ticso@cicely9.cicely.de) Received: from cicely9.cicely.de (cicely9.cicely.de [IPv6:3ffe:400:8d0:301:210:5aff:fe30:1c1a]) by cicely5.cicely.de (8.12.9/8.12.9) with ESMTP id h3GI74tn013893 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 16 Apr 2003 20:07:04 +0200 (CEST) (envelope-from ticso@cicely9.cicely.de) Received: from cicely9.cicely.de (localhost [127.0.0.1]) by cicely9.cicely.de (8.12.9/8.12.8) with ESMTP id h3GI73tA007333; Wed, 16 Apr 2003 20:07:04 +0200 (CEST) (envelope-from ticso@cicely9.cicely.de) Received: (from ticso@localhost) by cicely9.cicely.de (8.12.9/8.12.9/Submit) id h3GI714p007332; Wed, 16 Apr 2003 20:07:01 +0200 (CEST) (envelope-from ticso) Date: Wed, 16 Apr 2003 20:07:00 +0200 From: Bernd Walter To: Jan Grant Message-ID: <20030416180659.GD6845@cicely9.cicely.de> References: <200304161349.h3GDnKxl008394@lurza.secnetix.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Operating-System: FreeBSD cicely9.cicely.de 5.0-CURRENT alpha User-Agent: Mutt/1.5.3i cc: freebsd-hackers@freebsd.org Subject: Re: Multiple ip-numbers in jails (fixed INADDR_ANY behaviour). X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: ticso@cicely.de List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Apr 2003 18:07:41 -0000 On Wed, Apr 16, 2003 at 03:34:38PM +0100, Jan Grant wrote: > You can't have multiple processes listen on the same address and port, > but you CAN have one listen on a specific IP and port and another listen > on INADDR_ANY and the same port. By extension, you'd expect a _more > specific_ binding of INADDR_ANY to override a more general one. You *can* have multiple processes listen on the same address and port. 1) SO_REUSEPORT 2) You can pass a listen filedescriptor between processes (fork, UDS). [74]cicely30> cat foo.c #include #include #include int main (int argc, char *argv[]) { int listenfd, connfd; struct sockaddr_in cliaddr, servaddr; socklen_t clilen; int val; listenfd = socket(AF_INET, SOCK_STREAM, 0); bzero(&servaddr, sizeof(servaddr)); servaddr.sin_family = AF_INET; servaddr.sin_addr.s_addr = htonl(INADDR_ANY); servaddr.sin_port = htons(7000); val = 1; setsockopt(listenfd, SOL_SOCKET, SO_REUSEPORT, &val, sizeof(val)); bind(listenfd, (struct sockaddr*)&servaddr, sizeof(servaddr)); listen(listenfd, 2); for (;;) { clilen = sizeof(cliaddr); connfd = accept(listenfd, (struct sockaddr*)&cliaddr, &clilen); /* do something */ close(connfd); } } [75]cicely30> gcc -o foo foo.c [76]cicely30> ./foo & [1] 35763 [77]cicely30> ./foo & [2] 35764 [78]cicely30> netstat -an | grep 7000 tcp4 0 0 *.7000 *.* LISTEN tcp4 0 0 *.7000 *.* LISTEN -- B.Walter BWCT http://www.bwct.de ticso@bwct.de info@bwct.de