Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 20 Oct 1996 10:44:38 -0600 (MDT)
From:      Wes Peters <softweyr@xmission.com>
To:        BRETT_GLASS@infoworld.com
Cc:        questions@freebsd.org
Subject:   Programming question: How to identify owner of a socket?
Message-ID:  <199610201644.KAA04057@obie.softweyr.com>
In-Reply-To: <85170681@toto.iv>

next in thread | previous in thread | raw e-mail | index | archive | help
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






Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199610201644.KAA04057>