Changeset b535184 for examples/pcap2erf/pcap2erf.c
- Timestamp:
- 08/05/04 16:14:07 (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:
- 2137b49
- Parents:
- 9729a8d
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
examples/pcap2erf/pcap2erf.c
ra79ddbe rb535184 46 46 #include <linux/if_ether.h> 47 47 48 extern "C" {48 //extern "C" { 49 49 #include "dagformat.h" 50 50 #include "libtrace.h" 51 }51 //} 52 52 53 53 struct libtrace_t *trace; … … 66 66 int main(int argc, char *argv[]) { 67 67 68 char * hostname;68 char *uri; 69 69 int psize = 0; 70 int status = 0;71 70 char *filename; 72 71 FILE* input; 73 72 74 73 struct pcap_pkthdr *header; 74 struct libtrace_packet_t packet; 75 75 unsigned long seconds, subseconds; 76 76 unsigned short rlen, lctr, wlen, offset, pad; … … 80 80 uint32_t netmask = 0; 81 81 int data_size; 82 struct tcphdr*tcpptr = 0;82 struct libtrace_tcp *tcpptr = 0; 83 83 int octets[4]; 84 84 int hlen; 85 ip *ipptr;85 struct libtrace_ip *ipptr; 86 86 87 87 88 88 // 2 parameters only, both neccessary 89 89 if (argc == 3) { 90 hostname= strdup(argv[1]);90 uri = strdup(argv[1]); 91 91 filename = strdup(argv[2]); 92 92 } … … 159 159 //---------------------------------------------------------------------- 160 160 161 // create an trace to hostname, on the default port162 trace = create_trace(hostname);161 // create an trace to the given uri 162 trace = trace_create(uri); 163 163 164 164 for (;;) { 165 if ((psize = libtrace_read_packet(trace, buffer,SCANSIZE, &status))165 if ((psize = trace_read_packet(trace, &packet)) 166 166 == -1) { 167 167 // terminate … … 169 169 } 170 170 // buffer returned is pcap-->ethernet-->upperlayers 171 header = (struct pcap_pkthdr*) 171 header = (struct pcap_pkthdr*)packet.buffer; 172 172 173 173 // if this isnt an ip packet, ignore it 174 if(! (( buffer + sizeof(struct pcap_pkthdr))[12] == 8 &&175 ( buffer + sizeof(struct pcap_pkthdr))[13] == 0))174 if(! ((packet.buffer + sizeof(struct pcap_pkthdr))[12] == 8 && 175 (packet.buffer + sizeof(struct pcap_pkthdr))[13] == 0)) 176 176 continue; 177 177 178 ipptr = (ip *)(buffer + (sizeof(uint8_t)*30));// wtf is 30 178 179 ipptr = trace_get_ip(&packet); 179 180 hlen = ipptr->ip_hl*4; 180 181 … … 183 184 { 184 185 case 1: data_size = 14 + hlen; break; 185 case 6: tcpptr = (struct tcphdr*) ((uint8_t *)ipptr + hlen);186 case 6: tcpptr = (struct libtrace_tcp *) ((uint8_t *)ipptr + hlen); 186 187 data_size = 14 + hlen + (tcpptr->doff*4); break; 187 188 case 17: data_size = 14 + hlen + 8; break; … … 244 245 245 246 // write as much of the packet as we need (just the headers) 246 fwrite( buffer + sizeof(pcap_pkthdr), 1, data_size, stdout);247 } 248 249 destroy_trace(trace);247 fwrite(packet.buffer + sizeof(pcap_pkthdr), 1, data_size, stdout); 248 } 249 250 trace_destroy(trace); 250 251 return 0; 251 252 }
Note: See TracChangeset
for help on using the changeset viewer.