Changeset 0bd9361
- Timestamp:
- 09/15/06 16:06:50 (15 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:
- 3af7b80
- Parents:
- e4976e1
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/format_pcapfile.c
r5d233a5 r0bd9361 41 41 #include <string.h> 42 42 #include <errno.h> 43 #include <fcntl.h> 43 44 44 45 #define DATA(x) ((struct pcapfile_format_data_t*)((x)->format_data)) 46 #define DATAOUT(x) ((struct pcapfile_format_data_out_t*)((x)->format_data)) 45 47 46 48 typedef struct pcapfile_header_t { … … 61 63 struct pcapfile_format_data_out_t { 62 64 libtrace_io_t *file; 65 int level; 66 int flag; 63 67 64 68 }; … … 68 72 69 73 DATA(libtrace)->file=NULL; 74 75 return 0; 76 } 77 78 static int pcapfile_init_output(libtrace_out_t *libtrace) { 79 libtrace->format_data = 80 malloc(sizeof(struct pcapfile_format_data_out_t)); 81 82 DATAOUT(libtrace)->file=NULL; 83 DATAOUT(libtrace)->level=0; 84 DATAOUT(libtrace)->flag=O_CREAT|O_WRONLY; 70 85 71 86 return 0; … … 136 151 } 137 152 153 static int pcapfile_start_output(libtrace_out_t *libtrace) 154 { 155 return 0; 156 } 157 138 158 static int pcapfile_config_input(libtrace_t *libtrace, 139 159 trace_option_t option, … … 150 170 free(libtrace->format_data); 151 171 return 0; /* success */ 172 } 173 174 static int pcapfile_fin_output(libtrace_out_t *libtrace) 175 { 176 libtrace_io_close(DATA(libtrace)->file); 177 free(libtrace->format_data); 178 libtrace->format_data=NULL; 179 return 0; /* success */ 180 } 181 182 static int pcapfile_config_output(libtrace_out_t *libtrace, 183 trace_option_t option, 184 void *data) 185 { 186 trace_set_err_out(libtrace,TRACE_ERR_UNKNOWN_OPTION, 187 "Unknown option %i", option); 188 return -1; 152 189 } 153 190 … … 203 240 } 204 241 205 #if 0 206 static void pcapfile_write_packet(libtrace_out_t *out, 207 const libtrace_packet_t *packet) 208 { 209 struct pcapfile_pkt_hdr_t hdr; 210 211 tv = trace_get_timeval(packet); 242 static int pcapfile_write_packet(libtrace_out_t *out, 243 libtrace_packet_t *packet) 244 { 245 struct libtrace_pcapfile_pkt_hdr_t hdr; 246 struct timeval tv = trace_get_timeval(packet); 247 int numbytes; 248 int ret; 249 250 /* Now we know the link type write out a header if we've not done 251 * so already 252 */ 253 if (!DATAOUT(out)->file) { 254 struct pcapfile_header_t hdr; 255 256 DATAOUT(out)->file=trace_open_file_out(out, 257 DATAOUT(out)->level, 258 DATAOUT(out)->flag); 259 if (!DATAOUT(out)->file) 260 return -1; 261 262 hdr.magic_number = 0xa1b2c3d4; 263 hdr.version_major = 2; 264 hdr.version_minor = 4; 265 hdr.thiszone = 0; 266 hdr.sigfigs = 0; 267 hdr.snaplen = 65536; 268 hdr.network = 269 libtrace_to_pcap_dlt(trace_get_link_type(packet)); 270 271 libtrace_io_write(DATAOUT(out)->file, &hdr, sizeof(hdr)); 272 } 273 212 274 hdr.ts_sec = tv.tv_sec; 213 275 hdr.ts_usec = tv.tv_usec; 214 276 hdr.caplen = trace_get_capture_length(packet); 215 hdr.wirelen = trace_get_wire_length(packet); 216 217 write(fd,&hdr,sizeof(hdr)); 218 write(fd,packet->payload,hdr.caplen); 219 220 } 221 #endif 222 277 /* PCAP doesn't include the FCS, we do */ 278 hdr.wirelen = trace_get_wire_length(packet)-4; 279 280 numbytes=libtrace_io_write(DATAOUT(out)->file, 281 &hdr, sizeof(hdr)); 282 283 if (numbytes!=sizeof(hdr)) 284 return -1; 285 286 ret=libtrace_io_write(DATAOUT(out)->file, 287 trace_get_link(packet), 288 trace_get_capture_length(packet)); 289 290 if (ret!=trace_get_capture_length(packet)) 291 return -1; 292 293 return numbytes+ret; 294 } 223 295 224 296 static libtrace_linktype_t pcapfile_get_link_type( … … 358 430 pcapfile_start_input, /* start_input */ 359 431 NULL, /* pause_input */ 360 NULL,/* init_output */361 NULL,/* config_output */362 NULL,/* start_output */432 pcapfile_init_output, /* init_output */ 433 pcapfile_config_output, /* config_output */ 434 pcapfile_start_output, /* start_output */ 363 435 pcapfile_fin_input, /* fin_input */ 364 NULL,/* fin_output */436 pcapfile_fin_output, /* fin_output */ 365 437 pcapfile_read_packet, /* read_packet */ 366 438 NULL, /* fin_packet */ 367 NULL,/* write_packet */439 pcapfile_write_packet, /* write_packet */ 368 440 pcapfile_get_link_type, /* get_link_type */ 369 441 pcapfile_get_direction, /* get_direction */
Note: See TracChangeset
for help on using the changeset viewer.