[85c7de8] | 1 | /* |
---|
| 2 | * This file is part of libtrace |
---|
| 3 | * |
---|
| 4 | * Copyright (c) 2004 The University of Waikato, Hamilton, New Zealand. |
---|
| 5 | * Authors: Daniel Lawson |
---|
| 6 | * Perry Lorier |
---|
| 7 | * |
---|
| 8 | * All rights reserved. |
---|
| 9 | * |
---|
| 10 | * This code has been developed by the University of Waikato WAND |
---|
| 11 | * research group. For further information please see http://www.wand.net.nz/ |
---|
| 12 | * |
---|
| 13 | * libtrace is free software; you can redistribute it and/or modify |
---|
| 14 | * it under the terms of the GNU General Public License as published by |
---|
| 15 | * the Free Software Foundation; either version 2 of the License, or |
---|
| 16 | * (at your option) any later version. |
---|
| 17 | * |
---|
| 18 | * libtrace is distributed in the hope that it will be useful, |
---|
| 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 21 | * GNU General Public License for more details. |
---|
| 22 | * |
---|
| 23 | * You should have received a copy of the GNU General Public License |
---|
| 24 | * along with libtrace; if not, write to the Free Software |
---|
| 25 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
| 26 | * |
---|
| 27 | * $Id$ |
---|
| 28 | * |
---|
| 29 | */ |
---|
| 30 | |
---|
| 31 | #include <stdio.h> /* printf */ |
---|
| 32 | #include <netinet/in.h> /* ntohs */ |
---|
| 33 | #include <netdb.h> |
---|
| 34 | #include "dagformat.h" |
---|
| 35 | #include <getopt.h> |
---|
| 36 | |
---|
| 37 | #include <stdlib.h> |
---|
| 38 | #include <string.h> |
---|
| 39 | |
---|
| 40 | #include <errno.h> |
---|
| 41 | |
---|
| 42 | #include "libtrace.h" |
---|
| 43 | |
---|
| 44 | struct libtrace_t *trace; |
---|
| 45 | |
---|
| 46 | char *uri = 0; |
---|
| 47 | |
---|
| 48 | uint64_t rxerr = 0; |
---|
| 49 | uint64_t total = 0; |
---|
| 50 | static void usage(); |
---|
| 51 | static void parse_cmdline(int argc, char **argv); |
---|
| 52 | |
---|
| 53 | int main(int argc, char **argv) { |
---|
| 54 | |
---|
[d56089a] | 55 | struct libtrace_packet_t *packet = trace_create_packet(); |
---|
[85c7de8] | 56 | dag_record_t *erfptr; |
---|
| 57 | |
---|
| 58 | int psize; |
---|
| 59 | |
---|
| 60 | parse_cmdline(argc,argv); |
---|
| 61 | |
---|
| 62 | if (!uri) { |
---|
| 63 | printf("Incorrect usage: need a URI\n"); |
---|
| 64 | usage(argv[0]); |
---|
| 65 | } |
---|
| 66 | trace = trace_create(uri); |
---|
| 67 | for (;;) { |
---|
| 68 | if ((psize = trace_read_packet(trace, &packet)) <= 0) { |
---|
| 69 | // terminate |
---|
| 70 | break; |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | erfptr = (dag_record_t *)packet.buffer; |
---|
| 74 | |
---|
| 75 | |
---|
| 76 | if (erfptr->flags.rxerror) { |
---|
| 77 | rxerr++; |
---|
| 78 | printf("."); |
---|
| 79 | fflush(stdout); |
---|
| 80 | } |
---|
| 81 | total++; |
---|
| 82 | |
---|
| 83 | } |
---|
| 84 | printf("RX Errors seen: %llu\n",(unsigned long long) rxerr); |
---|
| 85 | printf("Total packets seen: %llu\n",(unsigned long long)total); |
---|
| 86 | trace_destroy(trace); |
---|
| 87 | return 0; |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | |
---|
| 91 | static void usage(char *prog) { |
---|
| 92 | printf("usage: %s [-h] [-u <uri>] \n",prog); |
---|
| 93 | printf(" -h this help message\n"); |
---|
| 94 | printf(" -u uri uri to connect to\n"); |
---|
| 95 | printf("\n"); |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | static void parse_cmdline(int argc, char **argv){ |
---|
| 99 | int opt; |
---|
| 100 | if (argc == 1) { |
---|
| 101 | usage(argv[0]); |
---|
| 102 | exit(0); |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | while ((opt = getopt(argc,argv, "hu:")) != EOF) { |
---|
| 106 | switch(opt) { |
---|
| 107 | case 'h': |
---|
| 108 | usage(argv[0]); |
---|
| 109 | exit(0); |
---|
| 110 | case 'u': |
---|
| 111 | uri = strdup(optarg); |
---|
| 112 | break; |
---|
| 113 | default: |
---|
| 114 | usage(argv[0]); |
---|
| 115 | exit(0); |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | } |
---|