From: Ralph Ronnquist Date: Sun, 26 Jun 2022 01:02:41 +0000 (+1000) Subject: change to use renamed vector X-Git-Tag: 0.1~11 X-Git-Url: https://git.rrq.au/?a=commitdiff_plain;h=9e0cc3c3727ec7069e7f6f6ae252895308753b5a;hp=c2fcc2eaad945b2bee685ca8b71c565158da0e18;p=rrq%2Frrqmisc.git change to use renamed vector --- diff --git a/socket-sniff/Makefile b/socket-sniff/Makefile index 4f8b149..d9d783f 100644 --- a/socket-sniff/Makefile +++ b/socket-sniff/Makefile @@ -1,11 +1,9 @@ default: socket-sniff -.INTERMEDIATE: socket-sniff.o -socket-sniff.o: CFLAGS = -Wall -I../pvector -g -socket-sniff.o: socket-sniff.c | ignores.i +CFLAGS = -Wall -I../vector -g -fmax-errors=1 +LDLIBS = -L../vector -lvector -socket-sniff: LDLIBS = -L../pvector -lpvector -socket-sniff: socket-sniff.o +.INTERMEDIATE: socket-sniff.o clean: rm -f socket-sniff diff --git a/socket-sniff/socket-sniff.c b/socket-sniff/socket-sniff.c index ae9f41d..545c9f7 100644 --- a/socket-sniff/socket-sniff.c +++ b/socket-sniff/socket-sniff.c @@ -29,17 +29,19 @@ static int OLD = 600; // Number of characters for text format IP holdings #define IPBUFMAX 40 +// Count record for IP -> length mapping typedef struct _Count { - struct _Count *next; - struct _Count *prev; - struct timeval when; - int ignore; - int last; - int accum; - int total; - char ip[ IPBUFMAX ]; + struct _Count *next; // Next Count in time order + struct _Count *prev; // Previous Count in time order + struct timeval when; // Last update time for this Count record + int ignore; // Flag to leave out from reports + int last; // The saved accumulation from the last report period + int accum; // Current accumulation + int total; // The total accumulation (reduced by fading) + char ip[ IPBUFMAX ]; // The IP concerned, in ascii } Count; +// Print message and exit static void die(char *m) { fprintf( stderr, "%s\n", m ); exit( 1 ); @@ -60,8 +62,9 @@ static unsigned long Countp_hashcode(void *key) { return hashvector_hashcode( key, IPBUFMAX ); } +// The hashvector of seen IP static hashvector TBL = { - .table = { 256, 0 }, + .table = { VECTOR_SLOTS, 0 }, .fill = 0, .holes = 0, .keyhashcode = Countp_hashcode, @@ -69,11 +72,13 @@ static hashvector TBL = { .haskey = Countp_haskey }; +// The Count records in time order static struct { Count *head; Count *tail; } trail; +// Temporary buffer for IP addresses in ascii static char buffer[ IPBUFMAX ]; /*============================================================ @@ -177,7 +182,7 @@ static int Countp_fade_and_print(unsigned long index,void *x,void *d) { return 0; } -static int Countp_reclaim(pvector *pv,unsigned long ix,void *item,void *data) { +static int Countp_reclaim(vector *pv,unsigned long ix,void *item,void *data) { return 0; } @@ -248,11 +253,11 @@ static void add_show_table(char *ip,size_t length) { show = now.tv_sec; } show += DELAY; // Time for next output - pvector ordered = { 0, 0 }; + vector ordered = { 0, 0 }; hashvector_contents( &TBL, &ordered ); - pvector_qsort( &ordered, Countp_compare ); - pvector_iterate( &ordered, Countp_fade_and_print, 0 ); - pvector_resize( &ordered, 0, Countp_reclaim, 0 ); + vector_qsort( &ordered, Countp_compare ); + vector_iterate( &ordered, Countp_fade_and_print, 0 ); + vector_resize( &ordered, 0, Countp_reclaim, 0 ); fprintf( stdout, "==%ld/%ld/%ld\n", TBL.fill, TBL.holes, TBL.table.size ); }