/* * This file is part of libtrace * * Copyright (c) 2004 The University of Waikato, Hamilton, New Zealand. * Authors: Daniel Lawson * Perry Lorier * * All rights reserved. * * This code has been developed by the University of Waikato WAND * research group. For further information please see http://www.wand.net.nz/ * * libtrace is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * libtrace is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with libtrace; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * $Id$ * */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "libtrace.h" struct libtrace_t *trace; uint64_t tot=0; /* Process a trace, counting packets that match filter(s) */ void run_trace(char *uri) { struct libtrace_packet_t *packet = trace_packet_create(); uint64_t count = 0; uint64_t bytes = 0; uint64_t nontcp_count = 0; uint64_t nontcp_bytes = 0; trace = trace_create(uri); for (;;) { int psize; if ((psize = trace_read_packet(trace, &packet)) <1) { break; } if (trace_get_tcp(&packet)) { ++nontcp_count; nontcp_bytes+=trace_get_wire_length(&packet); } ++count; bytes+=trace_get_wire_length(&packet); ++tot; } trace_destroy(trace); } #define TIMER_SUB(res,a,b) \ do { \ res.tv_sec = a.tv_sec - b.tv_sec; \ res.tv_usec = a.tv_usec - b.tv_usec; \ if (res.tv_usec < 0) { \ --res.tv_sec; \ res.tv_usec += 1000000; \ } \ } while(0) int main(int argc, char *argv[]) { int i; struct timeval start,end; struct timeval interval; struct rusage start_usage,end_usage; getrusage(RUSAGE_SELF,&start_usage); gettimeofday(&start,NULL); for(i=optind;i