From owner-freebsd-hackers@FreeBSD.ORG Sun Feb 29 14:41:23 2004 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 BEE7716A4CE for ; Sun, 29 Feb 2004 14:41:23 -0800 (PST) Received: from smtpout.mac.com (A17-250-248-87.apple.com [17.250.248.87]) by mx1.FreeBSD.org (Postfix) with ESMTP id AFBCD43D1D for ; Sun, 29 Feb 2004 14:41:23 -0800 (PST) (envelope-from justin@mac.com) Received: from mac.com (smtpin08-en2 [10.13.10.153]) by smtpout.mac.com (Xserve/MantshX 2.0) with ESMTP id i1TMfNNS005016 for ; Sun, 29 Feb 2004 14:41:23 -0800 (PST) Received: from mac.com (c-24-6-87-110.client.comcast.net [24.6.87.110]) (authenticated bits=0) by mac.com (Xserve/smtpin08/MantshX 3.0) with ESMTP id i1TMfM5l002224 (version=TLSv1/SSLv3 cipher=DES-CBC3-SHA bits=168 verify=NO) for ; Sun, 29 Feb 2004 14:41:23 -0800 (PST) Date: Sun, 29 Feb 2004 14:41:20 -0800 Content-Type: text/plain; charset=US-ASCII; format=flowed Mime-Version: 1.0 (Apple Message framework v553) From: Justin Walker To: freebsd-hackers@freebsd.org Content-Transfer-Encoding: 7bit In-Reply-To: Message-Id: <651556AE-6B08-11D8-BD24-00306544D642@mac.com> X-Mailer: Apple Mail (2.553) Subject: Re: Sockets and the owner process X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 29 Feb 2004 22:41:23 -0000 On Saturday, February 28, 2004, at 09:52 AM, grinder wrote: > I want to create a small kernel module which logs the socket > operations. > > So in my module i have a socket structure, and i want to know > which process (thread) owns it. But the socket structure isn't > contains any reference to the process structure. If i walk through > the vnode table i can find my socket by the so_gencnt "unique id", > but the vnode structure isn't have any variables back to the proc > structure. > > Is it possible to get the owner proc structure for a socket? Not really. Socket descriptors, like other file-descriptors, can be handed off by the fork/exec process, and via local domain sockets to unrelated processes, so by the time that the socket is actually used, there can be no relation to the process that created it (e.g., inetd/xinetd creates it, waits for a connection, accepts the connection, and then passes the descriptor to the service process via fork/exec, and closes its version of that socket). The best you can hope for is to determine processes that are actually using the socket, and that can vary during the socket's lifetime. You would have to scour the file descriptor tables in all process structures to determine which processes had a handle on each socket you have an interest in. There is no real "ownership" of anything accessed via file descriptors. Regards, Justin -- Justin C. Walker, Curmudgeon-At-Large * Institute for General Semantics | It's not whether you win or lose... | It's whether *I* win or lose. *--------------------------------------*-------------------------------*