Changeset 781cf2c
- Timestamp:
- 07/21/04 10:01:04 (17 years ago)
- Branches:
- 4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, getfragoff, help, libtrace4, master, ndag_format, pfring, rc-4.0.1, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance, ringtimestampfixes
- Children:
- be54c88
- Parents:
- 750a1e0
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
examples/protocol/protocol.c
rc561c76 r781cf2c 33 33 #include <netdb.h> 34 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 <linux/types.h> 43 #include <linux/linkage.h> 44 #define access_ok(type,addr,size) 1 45 #include <asm/checksum.h> 46 #define IN_CHKSUM(IP) ip_fast_csum((unsigned char *)(IP), 5) 35 47 36 48 #include "libtrace.h" … … 40 52 41 53 char *buffer[4096]; 54 uint64_t badchksum = 0; 55 char *uri = 0; 56 char *filterstring = 0; 42 57 43 int main(int argc, char *argv[]) { 58 int do_cksum = 0; 59 int do_w_cksum = 0; 60 static void usage(); 61 static void parse_cmdline(int argc, char **argv); 44 62 45 char *hostname = "rtclient:chasm.cs.waikato.ac.nz"; 46 char *filterstring = 0; 63 int main(int argc, char **argv) { 64 47 65 struct libtrace_ip *ipptr = 0; 48 66 49 67 int status; // need to pass to rtclient_read_packet 50 68 int psize; 51 if (argc == 2) { 52 hostname = argv[1]; 53 } 54 if (argc == 3) { 55 hostname = argv[1]; 56 filterstring = argv[2]; 57 } 69 70 parse_cmdline(argc,argv); 58 71 59 72 // create an rtclient to hostname, on the default port 60 trace = create_trace( hostname);73 trace = create_trace(uri); 61 74 if (filterstring) { 62 75 filter = libtrace_bpf_setfilter(filterstring); … … 74 87 } 75 88 ipptr = get_ip(trace,buffer,4096); 76 if (ipptr) { 77 printf("%d:%d\n",ipptr->ip_p,get_link_type(trace,buffer,4096)); 89 90 if(do_cksum && IN_CHKSUM(ipptr)) { 91 badchksum ++; 92 } else if (do_w_cksum && ipptr->ip_sum) { 93 badchksum ++; 94 } else { 95 if (ipptr) { 96 printf("%d:%d\n",ipptr->ip_p,get_link_type(trace,buffer,4096)); 97 } 78 98 } 79 99 } 100 if (do_cksum || do_w_cksum) { 101 printf("Bad checksums seen: %llu\n",badchksum); 102 } 80 103 destroy_trace(trace); 81 104 return 0; 82 105 } 106 107 108 static void usage(char *prog) { 109 printf("usage: %s [-h] [-c | -w] [-u <uri>] [-f <filterstring>]\n",prog); 110 printf(" -h this help message\n"); 111 printf(" -c perform ip checksum test\n"); 112 printf(" -w check WDCAPd ip checksum value\n"); 113 printf(" -u uri uri to connect to\n"); 114 printf(" -f filterstring BPF filterstring to apply\n"); 115 printf("\n"); 116 printf(" The use of -c and -w are exclusive: -c is used for normal traces, while -w applies to traces taken from the Waikato Capture point\n"); 117 } 118 119 static void parse_cmdline(int argc, char **argv){ 120 int opt; 121 if (argc == 1) { 122 usage(argv[0]); 123 exit(0); 124 } 125 126 while ((opt = getopt(argc,argv, "hcwu:f:")) != EOF) { 127 switch(opt) { 128 case 'h': 129 usage(argv[0]); 130 exit(0); 131 case 'c': 132 do_cksum = 1; 133 break; 134 case 'w': 135 do_w_cksum = 1; 136 break; 137 case 'u': 138 uri = strdup(optarg); 139 break; 140 case 'f': 141 filterstring = strdup(optarg); 142 break; 143 default: 144 usage(argv[0]); 145 exit(0); 146 } 147 148 } 149 150 if (do_cksum && do_w_cksum) { 151 usage(argv[0]); 152 exit(0); 153 } 154 155 }
Note: See TracChangeset
for help on using the changeset viewer.