Date: Mon, 10 Apr 2000 03:42:19 -0700 From: Alfred Perlstein <bright@wintelcom.net> To: Graham Wheeler <gram@cequrux.com> Cc: hackers@FreeBSD.ORG Subject: Re: Determining traffic on a socket Message-ID: <20000410034218.U4381@fw.wintelcom.net> In-Reply-To: <38F1A456.EAADF652@cequrux.com>; from gram@cequrux.com on Mon, Apr 10, 2000 at 11:52:22AM %2B0200 References: <38F1A456.EAADF652@cequrux.com>
next in thread | previous in thread | raw e-mail | index | archive | help
* Graham Wheeler <gram@cequrux.com> [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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20000410034218.U4381>