From f3e058c1f07df9174241c9ddf47b553b5f806978 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Wed, 11 Feb 2004 19:17:10 +0000 Subject: start develop --- Makefile | 11 +++++++++++ ifstat.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ main.c | 46 ++++++++++++++++++++++++++++++++++++++++++++ main.h | 32 +++++++++++++++++++++++++++++++ output.c | 27 ++++++++++++++++++++++++++ 5 files changed, 183 insertions(+) create mode 100644 Makefile create mode 100644 ifstat.c create mode 100644 main.c create mode 100644 main.h create mode 100644 output.c diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..dc7d3c3 --- /dev/null +++ b/Makefile @@ -0,0 +1,11 @@ +# $Id$ + +PROG= netmet +SRCS= main.c ifstat.c output.c +BINGRP= kmem +BINMODE=2555 +NOMAN= +DPADD= ${LIBCURSES} ${LIBKVM} +LDADD= -lkvm -lcurses + +. include diff --git a/ifstat.c b/ifstat.c new file mode 100644 index 0000000..2566e8d --- /dev/null +++ b/ifstat.c @@ -0,0 +1,67 @@ +/* $Id$ */ +/* + * Copyright (c) 2004 demon + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "main.h" + +kvm_t *kvmd = NULL; +void *ifhead; + +int if_init(void) { + char *vmunix = NULL, *core = NULL; + char errbuf[_POSIX2_LINE_MAX]; + + struct nlist nl[] = { { "_ifnet" }, { NULL } }; + + kvmd = kvm_openfiles(vmunix, core, NULL, O_RDONLY, errbuf); + if (kvmd == NULL) + errx(1,"%s", errbuf); + + if ((kvm_nlist(kvmd, nl)) == -1) + errx(1, "%s", kvm_geterr(kvmd)); + + if (kvm_read(kvmd, nl->n_value, &ifhead, sizeof(nl->n_value)) != sizeof(nl->n_value)) + errx(1, "%s", kvm_geterr(kvmd)); +} + +int if_stat(char *ifname) { + struct ifnet ifnet; + void *addr; + + addr = ifhead; + + for (; addr != NULL; addr = (struct ifnet *)ifnet.if_list.tqe_next) { + if (kvm_read(kvmd, (unsigned long)addr, &ifnet, sizeof(ifnet)) != sizeof(ifnet)) + errx(1, "%s", kvm_geterr(kvmd)); + if (strncmp(ifnet.if_xname, ifname, strlen(ifname)) == NULL) { + curr.ib = ifnet.if_ibytes; + curr.ob = ifnet.if_obytes; + } + } +} + +int if_fini(void) { + kvm_close(kvmd); + exit(0); +} diff --git a/main.c b/main.c new file mode 100644 index 0000000..a72caff --- /dev/null +++ b/main.c @@ -0,0 +1,46 @@ +/* $Id$ */ +/* + * Copyright (c) 2004 demon + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include +#include "main.h" + +int main(int argc, char **argv) { + struct stat last; + struct stat diff; + + initscr(); + + if_init(); + if_stat(argv[1]?argv[1]:"xl0"); + last.ib = curr.ib; + last.ob = curr.ob; + while(1) { + if_stat(argv[1]?argv[1]:"xl0"); + diff.ib = curr.ib - last.ib; + diff.ob = curr.ob - last.ob; + curses_print(diff.ib, diff.ob); + + last.ib = curr.ib; + last.ob = curr.ob; + sleep(1); + }; + if_fini(); + + endwin(); + exit(0); +} diff --git a/main.h b/main.h new file mode 100644 index 0000000..a519942 --- /dev/null +++ b/main.h @@ -0,0 +1,32 @@ +/* $Id$ */ +/* + * Copyright (c) 2004 demon + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#define kB 1024 +#define MB (kB*1024) + +int if_init(void); +int if_stat(char *); +int if_fini(void); + +struct stat { + long long ib; + long long ob; +}; + +struct stat curr; + +int curses_print(long long, long long); diff --git a/output.c b/output.c new file mode 100644 index 0000000..7f37c3a --- /dev/null +++ b/output.c @@ -0,0 +1,27 @@ +/* $Id$ */ +/* + * Copyright (c) 2004 demon + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include +// #include "main.h" + +int curses_print(long long ib, long long ob) { +// move(0,0); + clear(); + printw("I: %ld\n", ib); + printw("O: %ld\n", ob); + refresh(); +} -- cgit v1.2.3