From owner-freebsd-hackers Mon Oct 28 18:14:46 1996 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id SAA15552 for hackers-outgoing; Mon, 28 Oct 1996 18:14:46 -0800 (PST) Received: from parkplace.cet.co.jp (parkplace.cet.co.jp [202.32.64.1]) by freefall.freebsd.org (8.7.5/8.7.3) with ESMTP id SAA15543 for ; Mon, 28 Oct 1996 18:14:43 -0800 (PST) Received: from localhost (michaelh@localhost) by parkplace.cet.co.jp (8.8.0/CET-v2.1) with SMTP id CAA29683; Tue, 29 Oct 1996 02:14:34 GMT Date: Tue, 29 Oct 1996 11:14:33 +0900 (JST) From: Michael Hancock To: Per Hojmark cc: hackers@freebsd.org Subject: Re: sockets programming question In-Reply-To: <199610290018.QAA21190@mustang.via.net> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk On Mon, 28 Oct 1996, Per Hojmark wrote: > > I want to build a database server process that: > - listens on a port > - connects to incoming users > - forks to create new state & connection info for database. > - does some database lookups > - returns info to user > - closes connection. > > So, suppose I was listening on port 1234, when I get a connection > from a remote machine, do I need to switch to a new port number? > > I notice that many programs use 'well known' port numbers, but after > forking, seem to switch to a port > 1024. It appears that they use > the 'well-known' port number just for the initial connection. The deamon needs to run as root to listen on low numbered ports. While you're root you can write the logs and then hand off the real work to the children which run as a different uid and switch to a high numbered port. The loop you describe is so common that you should try to use a library. Try asking at http://www.isc.org for the eventlib. Regards, Mike Hancock