Changeset 3073c04 for lib/format_pcap.c
- Timestamp:
- 08/24/05 15:34:32 (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:
- 1974620
- Parents:
- e01bfa8
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/format_pcap.c
rffc8c8d r3073c04 64 64 #if HAVE_PCAP 65 65 66 static struct libtrace_format_t *pcap_ptr = 0; 67 static struct libtrace_format_t *pcapint_ptr = 0; 68 66 69 #define CONNINFO libtrace->format_data->conn_info 67 70 #define INPUT libtrace->format_data->input 68 71 #define OUTPUT libtrace->format_data->output 69 72 struct libtrace_format_data_t { 70 73 union { … … 75 78 /** Information about the current state of the input device */ 76 79 union { 77 int fd;78 FILE *file;79 80 pcap_t *pcap; 80 81 } input; 81 82 }; 83 84 struct libtrace_format_data_out_t { 85 union { 86 char *path; 87 char *interface; 88 } conn_info; 89 struct { 90 pcap_t *pcap; 91 pcap_dumper_t *dump; 92 } output; 93 }; 94 95 static int linktype_to_dlt(libtrace_linktype_t t) { 96 static int table[] = { 97 -1, /* LEGACY */ 98 -1, /* HDLC over POS */ 99 DLT_EN10MB, /* Ethernet */ 100 -1, /* ATM */ 101 DLT_IEEE802_11, /* 802.11 */ 102 -1 /* END OF TABLE */ 103 }; 104 if (t>sizeof(table)/sizeof(*table)) { 105 return -1; 106 } 107 return table[t]; 108 } 82 109 83 110 static int pcap_init_input(struct libtrace_t *libtrace) { … … 126 153 } 127 154 155 static int pcap_init_output(struct libtrace_out_t *libtrace) { 156 char errbuf[PCAP_ERRBUF_SIZE]; 157 struct stat buf; 158 libtrace->format_data = (struct libtrace_format_data_out_t *) 159 malloc(sizeof(struct libtrace_format_data_out_t)); 160 CONNINFO.path = libtrace->uridata; 161 OUTPUT.pcap = NULL; 162 OUTPUT.dump = NULL; 163 } 164 128 165 static int pcapint_init_input(struct libtrace_t *libtrace) { 129 166 char errbuf[PCAP_ERRBUF_SIZE]; … … 145 182 146 183 static int pcap_fin_input(struct libtrace_t *libtrace) { 147 return -1; 184 pcap_close(INPUT.pcap); 185 free(libtrace->format_data); 186 return 0; 187 } 188 189 static int pcap_fin_output(struct libtrace_out_t *libtrace) { 190 pcap_dump_flush(OUTPUT.dump); 191 pcap_dump_close(OUTPUT.dump); 192 return 0; 148 193 } 149 194 … … 173 218 } 174 219 return (packet->size - sizeof(struct pcap_pkthdr)); 220 } 221 222 static int pcap_write_packet(struct libtrace_out_t *libtrace, struct libtrace_packet_t *packet) { 223 struct pcap_pkthdr pcap_pkt_hdr; 224 void *link = trace_get_link(packet); 225 226 if (!OUTPUT.pcap) { 227 OUTPUT.pcap = pcap_open_dead( 228 linktype_to_dlt(trace_get_link_type(packet)), 229 65536); 230 OUTPUT.dump = pcap_dump_open(OUTPUT.pcap,CONNINFO.path); 231 fflush((FILE *)OUTPUT.dump); 232 } 233 if (packet->trace->format == pcap_ptr || 234 packet->trace->format == pcapint_ptr) { 235 //if (!strncasecmp(packet->trace->format->name,"pcap",4)) { 236 // this is a pcap trace anyway 237 238 pcap_dump((u_char*)OUTPUT.dump,(struct pcap_pkthdr *)packet->buffer,link); 239 } else { 240 pcap_pkt_hdr.ts = trace_get_timeval(packet); 241 pcap_pkt_hdr.caplen = trace_get_capture_length(packet); 242 pcap_pkt_hdr.len = trace_get_wire_length(packet); 243 244 pcap_dump((u_char*)OUTPUT.pcap, &pcap_pkt_hdr, link); 245 } 246 return 0; 175 247 } 176 248 … … 322 394 "$Id$", 323 395 pcap_init_input, /* init_input */ 324 NULL,/* init_output */396 pcap_init_output, /* init_output */ 325 397 NULL, /* config_output */ 326 398 pcap_fin_input, /* fin_input */ 327 NULL,/* fin_output */399 pcap_fin_output, /* fin_output */ 328 400 pcap_read_packet, /* read_packet */ 329 NULL,/* write_packet */401 pcap_write_packet, /* write_packet */ 330 402 pcap_get_link, /* get_link */ 331 403 pcap_get_link_type, /* get_link_type */ … … 368 440 }; 369 441 442 //pcap_ptr = &pcap; 443 //pcapint_ptr = &pcapint; 444 370 445 void __attribute__((constructor)) pcap_constructor() { 371 register_format(&pcap); 372 register_format(&pcapint); 446 pcap_ptr = &pcap; 447 pcapint_ptr = &pcapint; 448 register_format(pcap_ptr); 449 register_format(pcapint_ptr); 373 450 } 374 451
Note: See TracChangeset
for help on using the changeset viewer.