- struct timeval now;
- if ( gettimeofday( &now, 0 ) ) {
- perror( "gettimeofday" );
- exit( 1 );
+ item->accum += length;
+ item->when = now;
+ // Link in item to the trail end
+ if ( trail.head == 0 ) {
+ trail.head = item;
+ } else {
+ trail.tail->next = item;
+ item->prev = trail.tail;
+ }
+ trail.tail = item;
+ // Drop counters older than an hour
+ while ( trail.head->when.tv_sec + OLD < item->when.tv_sec ) {
+ Count *old = trail.head;
+ trail.head = old->next;
+ if ( trail.head ) {
+ trail.head->prev = 0;
+ }
+ fprintf( stdout, "drop %s\n", old->ip );
+ HashVector_delete( &TBL, old );
+ free( old );