From owner-freebsd-questions Sun Oct 20 19:20:41 1996 Return-Path: owner-questions Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id TAA12291 for questions-outgoing; Sun, 20 Oct 1996 19:20:41 -0700 (PDT) Received: from obie.softweyr.com (slc93.modem.xmission.com [204.228.136.93]) by freefall.freebsd.org (8.7.5/8.7.3) with ESMTP id TAA12279 for ; Sun, 20 Oct 1996 19:20:36 -0700 (PDT) Received: (from wes@localhost) by obie.softweyr.com (8.7.5/8.6.12) id KAA04057; Sun, 20 Oct 1996 10:44:38 -0600 (MDT) Date: Sun, 20 Oct 1996 10:44:38 -0600 (MDT) Message-Id: <199610201644.KAA04057@obie.softweyr.com> From: Wes Peters To: BRETT_GLASS@infoworld.com CC: questions@freebsd.org Subject: Programming question: How to identify owner of a socket? In-Reply-To: <85170681@toto.iv> Sender: owner-questions@freebsd.org X-Loop: FreeBSD.org Precedence: bulk BRETT GLASS writes: > [...] > To do this, the daemon has to verify that the client's IP address > matches that of the local host. It should then verify that the client's IP > port number belongs to a local instance of SLiRP. Finally, it should > identify the user by looking up the owner of the SLiRP process. > > I'm sure all of this is possible. However, since I'm not experienced at > building IP daemons under UNIX, I don't know quite how to do it. What are > the system calls that: > > Let a daemon find the IP address of the connecting client? > > Let it find the IP port number of the connecting client? getpeername(2) returns a sockaddr structure for an open socket connection. In the case of an IP connection, this will actually be a struct sockaddr_in, which contains both the port number (sin_port) and address (sin_addr) of the "other" end of the connection. > Map the IP port number to a process and user on the local machine? As far as I know, the client would have to send this information across the link to the server. You may want to look into the ident library and pidentd server from the package net/pidentd-2.7b3.tgz. > And can these all be called from Perl, so I can do the first draft of the > daemon without coding it in C? I know perl can call getpeername; I haven't looked into the ident protocol used by identd enough to guess there. If nothing else, you could probably just create the request yourself in perl and send it to the identd using sendto. In general, if it can be accomplished in C, you can do it in perl also; the difference is in the details. ;^) > Any help will be much appreciated. Good Luck. -- "Where am I, and what am I doing in this handbasket?" Wes Peters Softweyr LLC http://www.xmission.com/~softweyr softweyr@xmission.com