Changeset 3073c04 for lib/format_wag.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_wag.c
rffc8c8d r3073c04 63 63 #endif 64 64 65 static struct libtrace_format_t *wag_ptr = 0; 66 65 67 #define CONNINFO libtrace->format_data->conn_info 66 68 #define INPUT libtrace->format_data->input 69 #define OUTPUT libtrace->format_data->output 70 #define OPTIONS libtrace->format_data->options 71 67 72 struct libtrace_format_data_t { 68 73 union { … … 83 88 #endif 84 89 } input; 90 }; 91 92 struct libtrace_format_data_out_t { 93 union { 94 char *path; 95 } conn_info; 96 union { 97 struct { 98 int level; 99 } zlib; 100 } options; 101 union { 102 int fd; 103 #if HAVE_ZLIB 104 gzFile *file; 105 #else 106 FILE *file; 107 #endif 108 } output; 85 109 }; 86 110 … … 150 174 } 151 175 176 static int wag_init_output(struct libtrace_out_t *libtrace) { 177 char *filemode = 0; 178 libtrace->format_data = (struct libtrace_format_data_out_t *) 179 calloc(1,sizeof(struct libtrace_format_data_out_t)); 180 181 OPTIONS.zlib.level = 0; 182 asprintf(&filemode,"wb%d",OPTIONS.zlib.level); 183 if (!strncmp(libtrace->uridata,"-",1)) { 184 // STDOUT 185 #if HAVE_ZLIB 186 OUTPUT.file = gzdopen(dup(1), filemode); 187 #else 188 OUTPUT.file = stdout; 189 #endif 190 } else { 191 // TRACE 192 #if HAVE_ZLIB 193 OUTPUT.file = gzdopen(open( 194 libtrace->uridata, 195 O_CREAT | O_LARGEFILE | O_WRONLY, 196 S_IRUSR | S_IWUSR), filemode); 197 #else 198 OUTPUT.file = fdopen(open( 199 O_CREAT | O_LARGEFILE | O_WRONLY, 200 S_IRUSR | S_IWUSR), "w"); 201 #endif 202 } 203 204 return 1; 205 } 206 207 static int wag_config_output(struct libtrace_out_t *libtrace, int argc, char *argv[]) { 208 #if HAVE_ZLIB 209 int opt; 210 int level = OPTIONS.zlib.level; 211 optind = 1; 212 while ((opt = getopt(argc, argv, "z:")) != EOF) { 213 switch (opt) { 214 case 'z': 215 level = atoi(optarg); 216 break; 217 default: 218 printf("Bad argument to wag: %s\n", opt); 219 return -1; 220 } 221 } 222 if (level != OPTIONS.zlib.level) { 223 if (level > 9 || level < 0) { 224 // retarded level choice 225 printf("Compression level must be between 0 and 9 inclusive - you selected %i \n", level); 226 } else { 227 OPTIONS.zlib.level = level; 228 return gzsetparams(OUTPUT.file, level, Z_DEFAULT_STRATEGY); 229 } 230 } 231 #endif 232 return 0; 233 } 234 152 235 static int wag_fin_input(struct libtrace_t *libtrace) { 153 236 #if HAVE_ZLIB … … 155 238 #else 156 239 fclose(INPUT.file); 240 #endif 241 } 242 243 static int wag_fin_output(struct libtrace_out_t *libtrace) { 244 #if HAVE_ZLIB 245 gzclose(OUTPUT.file); 246 #else 247 fclose(OUTPUT.file); 157 248 #endif 158 249 } … … 259 350 return numbytes; 260 351 } while(1); 352 } 353 354 static int wag_write_packet(struct libtrace_out_t *libtrace, struct libtrace_packet_t *packet) { 355 int numbytes =0 ; 356 if (packet->trace->format != wag_ptr) { 357 fprintf(stderr,"Cannot convert from wag to %s format yet\n", 358 packet->trace->format->name); 359 return -1; 360 } 361 #if HAVE_ZLIB 362 if ((numbytes = gzwrite(OUTPUT.file, packet->buffer, packet->size)) == 0) { 363 perror("gzwrite"); 364 return -1; 365 } 366 #else 367 if ((numbytes = write(OUTPUT.file, packet->buffer, packet->size)) == 0) { 368 perror("write"); 369 return -1; 370 } 371 #endif 372 return numbytes; 261 373 } 262 374 … … 333 445 "$Id$", 334 446 wag_init_input, /* init_input */ 335 NULL,/* init_output */336 NULL,/* config_output */447 wag_init_output, /* init_output */ 448 wag_config_output, /* config_output */ 337 449 wag_fin_input, /* fin_input */ 338 NULL,/* fin_output */450 wag_fin_output, /* fin_output */ 339 451 wag_read_packet, /* read_packet */ 340 NULL,/* write_packet */452 wag_write_packet, /* write_packet */ 341 453 wag_get_link, /* get_link */ 342 454 wag_get_link_type, /* get_link_type */ … … 355 467 356 468 void __attribute__((constructor)) wag_constructor() { 357 register_format(&wag); 358 } 469 wag_ptr = &wag; 470 register_format(wag_ptr); 471 }
Note: See TracChangeset
for help on using the changeset viewer.