From owner-freebsd-hackers Mon Apr 10 3:16: 4 2000 Delivered-To: freebsd-hackers@freebsd.org Received: from fw.wintelcom.net (ns1.wintelcom.net [209.1.153.20]) by hub.freebsd.org (Postfix) with ESMTP id 886B337B843 for ; Mon, 10 Apr 2000 03:16:01 -0700 (PDT) (envelope-from bright@fw.wintelcom.net) Received: (from bright@localhost) by fw.wintelcom.net (8.10.0/8.10.0) id e3AAgJd00898; Mon, 10 Apr 2000 03:42:19 -0700 (PDT) Date: Mon, 10 Apr 2000 03:42:19 -0700 From: Alfred Perlstein To: Graham Wheeler Cc: hackers@FreeBSD.ORG Subject: Re: Determining traffic on a socket Message-ID: <20000410034218.U4381@fw.wintelcom.net> References: <38F1A456.EAADF652@cequrux.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0.1i In-Reply-To: <38F1A456.EAADF652@cequrux.com>; from gram@cequrux.com on Mon, Apr 10, 2000 at 11:52:22AM +0200 Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG * Graham Wheeler [000410 03:15] wrote: > Hi all > > I doubt that this can be done, but it would solve me a lot of headaches > if it can! > > I would like to know if there is a way I can, given a file descriptor > (which will be a TCP socket), determine how many bytes have been sent > and received through that socket since it was opened. Obviously one > way is to keep a count of reads and writes, but what I really want is > to have a wrapper process that can spawn arbitrary one-shot servers and > then log the traffic produced and consumed by that server when it > terminates. Another option is to communicate with the server via pipes, > but that may break if the server needs to be able to do getsockname() > and getpeername() calls. So the real solution would (I imagine) involve > some kind of kernel querying. > > Any ideas, anyone? Checkout /usr/include/sys/socketvar.h and /usr/src/sys/kern/uipc_socket.c, you should be able to add a "transmitted" feild to the struct sockbuf and keep track of it with minimal effort. I think you could then use an ioctl to retrieve the information. -- -Alfred Perlstein - [bright@wintelcom.net|alfred@freebsd.org] "I have the heart of a child; I keep it in a jar on my desk." To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message