Changeset eeab9832
- Timestamp:
- 03/03/06 18:24:18 (16 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:
- 7ac9705
- Parents:
- c3e6e47
- Location:
- lib
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/format_erf.c
r30c0246 reeab9832 155 155 #ifdef HAVE_DAG 156 156 static int dag_init_input(struct libtrace_t *libtrace) { 157 struct stat buf; 158 157 159 libtrace->format_data = (struct erf_format_data_t *) 158 160 malloc(sizeof(struct erf_format_data_t)); 159 return 0;160 }161 162 static int dag_start_input(struct libtrace_t *libtrace) {163 struct stat buf;164 161 if (stat(libtrace->uridata, &buf) == -1) { 165 162 trace_set_err(libtrace,errno,"stat(%s)",libtrace->uridata); … … 178 175 return -1; 179 176 } 180 if(dag_start(INPUT.fd) < 0) {181 trace_set_err(libtrace,errno,"Cannot start DAG %s",182 libtrace->uridata);183 return -1;184 }185 177 } else { 186 178 trace_set_err(libtrace,errno,"Not a valid dag device: %s", … … 190 182 return 0; 191 183 } 184 192 185 #endif 193 186 … … 195 188 * so that the ip header is aligned on a 32 bit boundary. 196 189 */ 197 static int erf_get_padding(const structlibtrace_packet_t *packet)190 static int erf_get_padding(const libtrace_packet_t *packet) 198 191 { 199 switch(trace_get_link_type(packet)) { 200 case TRACE_TYPE_ETH: return 2; 192 dag_record_t *erfptr = (dag_record_t *)packet->header; 193 switch(erfptr->type) { 194 case TYPE_ETH: return 2; 201 195 default: return 0; 202 196 } 203 197 } 204 198 205 static int erf_get_framing_length(const structlibtrace_packet_t *packet)199 static int erf_get_framing_length(const libtrace_packet_t *packet) 206 200 { 207 201 return dag_record_size + erf_get_padding(packet); … … 209 203 210 204 211 static int erf_init_input( structlibtrace_t *libtrace)205 static int erf_init_input(libtrace_t *libtrace) 212 206 { 213 207 libtrace->format_data = malloc(sizeof(struct erf_format_data_t)); … … 334 328 } 335 329 336 static int rtclient_init_input( structlibtrace_t *libtrace) {330 static int rtclient_init_input(libtrace_t *libtrace) { 337 331 char *scan; 338 332 libtrace->format_data = malloc(sizeof(struct erf_format_data_t)); … … 396 390 } 397 391 398 static int erf_init_output( structlibtrace_out_t *libtrace) {392 static int erf_init_output(libtrace_out_t *libtrace) { 399 393 libtrace->format_data = calloc(1,sizeof(struct erf_format_data_out_t)); 400 394 … … 406 400 } 407 401 408 static int erf_config_output( structlibtrace_out_t *libtrace, trace_option_t option, void *value) {402 static int erf_config_output(libtrace_out_t *libtrace, trace_option_t option, void *value) { 409 403 410 404 switch (option) { … … 425 419 426 420 #ifdef HAVE_DAG 427 static int dag_ fin_input(structlibtrace_t *libtrace) {421 static int dag_pause_input(libtrace_t *libtrace) { 428 422 dag_stop(INPUT.fd); 423 return 0; /* success */ 424 } 425 426 static int dag_fin_input(libtrace_t *libtrace) { 427 /* dag pause input implicitly called to cleanup before this */ 428 dag_close(INPUT.fd); 429 429 free(libtrace->format_data); 430 } 431 #endif 432 433 static int rtclient_fin_input(struct libtrace_t *libtrace) { 430 return 0; /* success */ 431 } 432 #endif 433 434 static int rtclient_fin_input(libtrace_t *libtrace) { 434 435 free(CONNINFO.rt.hostname); 435 436 close(INPUT.fd); … … 438 439 } 439 440 440 static int erf_fin_input( structlibtrace_t *libtrace) {441 static int erf_fin_input(libtrace_t *libtrace) { 441 442 LIBTRACE_CLOSE(INPUT.file); 442 443 free(libtrace->format_data); … … 444 445 } 445 446 446 static int erf_fin_output( structlibtrace_out_t *libtrace) {447 static int erf_fin_output(libtrace_out_t *libtrace) { 447 448 LIBTRACE_CLOSE(OUTPUT.file); 448 449 free(libtrace->format_data); … … 451 452 452 453 #if HAVE_DAG 453 static int dag_read(struct libtrace_t *libtrace, int block_flag) { 454 int numbytes; 455 static short lctr = 0; 456 struct dag_record_t *erfptr = 0; 457 int rlen; 454 static int dag_read(libtrace_t *libtrace, int block_flag) { 458 455 459 456 if (DAG.diff != 0) … … 461 458 462 459 DAG.bottom = DAG.top; 460 463 461 DAG.top = dag_offset( 464 462 INPUT.fd, 465 463 &(DAG.bottom), 466 464 block_flag); 467 DAG.diff = DAG.top - 468 DAG.bottom; 469 470 numbytes=DAG.diff; 465 466 DAG.diff = DAG.top - DAG.bottom; 467 471 468 DAG.offset = 0; 472 return numbytes; 473 } 474 #endif 475 476 #if HAVE_DAG 469 return DAG.diff; 470 } 471 477 472 /* FIXME: dag_read_packet shouldn't update the pointers, dag_fin_packet 478 473 * should do that. 479 474 */ 480 static int dag_read_packet( struct libtrace_t *libtrace, structlibtrace_packet_t *packet) {475 static int dag_read_packet(libtrace_t *libtrace, libtrace_packet_t *packet) { 481 476 int numbytes; 482 477 int size; 483 478 dag_record_t *erfptr; 484 void *buffer = packet->buffer;485 void *buffer2 = buffer;486 int rlen;487 479 488 480 if (packet->buf_control == TRACE_CTRL_PACKET) { … … 494 486 packet->type = RT_DATA_ERF; 495 487 496 if ((numbytes = dag_read(libtrace,0)) < =0)488 if ((numbytes = dag_read(libtrace,0)) < 0) 497 489 return numbytes; 490 assert(numbytes>0); 498 491 499 492 /*DAG always gives us whole packets */ 500 erfptr = (dag_record_t *) (( void*)DAG.buf +493 erfptr = (dag_record_t *) ((char *)DAG.buf + 501 494 (DAG.bottom + DAG.offset)); 502 495 size = ntohs(erfptr->rlen); 503 496 504 if ( size > LIBTRACE_PACKET_BUFSIZE) { 505 assert( size < LIBTRACE_PACKET_BUFSIZE); 506 } 497 assert( size >= dag_record_size ); 498 assert( size < LIBTRACE_PACKET_BUFSIZE); 507 499 508 500 packet->buffer = erfptr; … … 511 503 packet->payload = NULL; 512 504 } else { 513 packet->payload = packet->buffer + erf_get_framing_length(packet); 505 packet->payload = (char*)packet->buffer 506 + erf_get_framing_length(packet); 514 507 } 515 508 … … 517 510 DAG.diff -= size; 518 511 519 assert(DAG.diff >= 0);520 521 512 return (size); 522 513 } 514 515 static int dag_start_input(libtrace_t *libtrace) { 516 if(dag_start(INPUT.fd) < 0) { 517 trace_set_err(libtrace,errno,"Cannot start DAG %s", 518 libtrace->uridata); 519 return -1; 520 } 521 /* dags appear to have a bug where if you call dag_start after 522 * calling dag_stop, and at least one packet has arrived, bad things 523 * happen. flush the memory hole 524 */ 525 while(dag_read(libtrace,1)!=0) 526 DAG.diff=0; 527 return 0; 528 } 523 529 #endif 524 530 525 static int erf_read_packet( struct libtrace_t *libtrace, structlibtrace_packet_t *packet) {531 static int erf_read_packet(libtrace_t *libtrace, libtrace_packet_t *packet) { 526 532 int numbytes; 527 533 int size; … … 572 578 } 573 579 574 static int rtclient_read( structlibtrace_t *libtrace, void *buffer, size_t len) {580 static int rtclient_read(libtrace_t *libtrace, void *buffer, size_t len) { 575 581 int numbytes; 576 582 … … 599 605 } 600 606 601 static int rtclient_read_packet( struct libtrace_t *libtrace, structlibtrace_packet_t *packet) {607 static int rtclient_read_packet(libtrace_t *libtrace, libtrace_packet_t *packet) { 602 608 int numbytes = 0; 603 609 char buf[RP_BUFSIZE]; … … 618 624 619 625 do { 620 struct libtrace_packet_statusstatus;626 libtrace_packet_status_t status; 621 627 int size; 622 628 if (tracefifo_out_available(libtrace->fifo) == 0 … … 771 777 } 772 778 773 static libtrace_linktype_t erf_get_link_type(const structlibtrace_packet_t *packet) {779 static libtrace_linktype_t erf_get_link_type(const libtrace_packet_t *packet) { 774 780 dag_record_t *erfptr = 0; 775 781 erfptr = (dag_record_t *)packet->header; … … 777 783 } 778 784 779 static int8_t erf_get_direction(const structlibtrace_packet_t *packet) {785 static int8_t erf_get_direction(const libtrace_packet_t *packet) { 780 786 dag_record_t *erfptr = 0; 781 787 erfptr = (dag_record_t *)packet->header; … … 783 789 } 784 790 785 static int8_t erf_set_direction(const structlibtrace_packet_t *packet, int8_t direction) {791 static int8_t erf_set_direction(const libtrace_packet_t *packet, int8_t direction) { 786 792 dag_record_t *erfptr = 0; 787 793 erfptr = (dag_record_t *)packet->header; … … 790 796 } 791 797 792 static uint64_t erf_get_erf_timestamp(const structlibtrace_packet_t *packet) {798 static uint64_t erf_get_erf_timestamp(const libtrace_packet_t *packet) { 793 799 dag_record_t *erfptr = 0; 794 800 erfptr = (dag_record_t *)packet->header; … … 796 802 } 797 803 798 static int erf_get_capture_length(const structlibtrace_packet_t *packet) {804 static int erf_get_capture_length(const libtrace_packet_t *packet) { 799 805 dag_record_t *erfptr = 0; 800 806 erfptr = (dag_record_t *)packet->header; … … 802 808 } 803 809 804 static int erf_get_wire_length(const structlibtrace_packet_t *packet) {810 static int erf_get_wire_length(const libtrace_packet_t *packet) { 805 811 dag_record_t *erfptr = 0; 806 812 erfptr = (dag_record_t *)packet->header; … … 808 814 } 809 815 810 static size_t erf_set_capture_length( structlibtrace_packet_t *packet, size_t size) {816 static size_t erf_set_capture_length(libtrace_packet_t *packet, size_t size) { 811 817 dag_record_t *erfptr = 0; 812 818 assert(packet); … … 825 831 826 832 #ifdef HAVE_DAG 827 struct libtrace_eventobj_t trace_event_dag(struct libtrace_t *trace, structlibtrace_packet_t *packet) {828 structlibtrace_eventobj_t event = {0,0,0.0,0};833 libtrace_eventobj_t trace_event_dag(libtrace_t *trace, libtrace_packet_t *packet) { 834 libtrace_eventobj_t event = {0,0,0.0,0}; 829 835 int dag_fd; 830 836 int data; … … 914 920 erf_fin_output, /* fin_output */ 915 921 erf_read_packet, /* read_packet */ 922 NULL, /* fin_packet */ 916 923 erf_write_packet, /* write_packet */ 917 924 erf_get_link_type, /* get_link_type */ … … 930 937 NULL, /* get_fd */ 931 938 trace_event_trace, /* trace_event */ 932 erf_help /* help */ 939 erf_help, /* help */ 940 NULL /* next pointer */ 933 941 }; 934 942 … … 941 949 NULL, /* config_input */ 942 950 dag_start_input, /* start_input */ 943 NULL,/* pause_input */951 dag_pause_input, /* pause_input */ 944 952 NULL, /* init_output */ 945 953 NULL, /* config_output */ … … 948 956 NULL, /* fin_output */ 949 957 dag_read_packet, /* read_packet */ 958 NULL, /* fin_packet */ 950 959 NULL, /* write_packet */ 951 960 erf_get_link_type, /* get_link_type */ … … 964 973 NULL, /* get_fd */ 965 974 trace_event_dag, /* trace_event */ 966 dag_help /* help */ 975 dag_help, /* help */ 976 NULL /* next pointer */ 967 977 }; 968 978 #endif … … 982 992 NULL, /* fin_output */ 983 993 rtclient_read_packet, /* read_packet */ 994 NULL, /* fin_packet */ 984 995 NULL, /* write_packet */ 985 996 erf_get_link_type, /* get_link_type */ … … 998 1009 rtclient_get_fd, /* get_fd */ 999 1010 trace_event_device, /* trace_event */ 1000 rtclient_help /* help */ 1011 rtclient_help, /* help */ 1012 NULL /* next pointer */ 1001 1013 }; 1002 1014 -
lib/format_legacy.c
rd8f02df reeab9832 254 254 NULL, /* fin_output */ 255 255 legacy_read_packet, /* read_packet */ 256 NULL, /* fin_packet */ 256 257 NULL, /* write_packet */ 257 258 legacyatm_get_link_type, /* get_link_type */ … … 270 271 NULL, /* get_fd */ 271 272 trace_event_trace, /* trace_event */ 272 legacyatm_help /* help */ 273 legacyatm_help, /* help */ 274 NULL /* next pointer */ 273 275 }; 274 276 … … 287 289 NULL, /* fin_output */ 288 290 legacy_read_packet, /* read_packet */ 291 NULL, /* fin_packet */ 289 292 NULL, /* write_packet */ 290 293 legacyeth_get_link_type, /* get_link_type */ … … 303 306 NULL, /* get_fd */ 304 307 trace_event_trace, /* trace_event */ 305 legacyeth_help /* help */ 308 legacyeth_help, /* help */ 309 NULL /* next pointer */ 306 310 }; 307 311 … … 320 324 NULL, /* fin_output */ 321 325 legacy_read_packet, /* read_packet */ 326 NULL, /* fin_packet */ 322 327 NULL, /* write_packet */ 323 328 legacypos_get_link_type, /* get_link_type */ … … 336 341 NULL, /* get_fd */ 337 342 trace_event_trace, /* trace_event */ 338 legacypos_help /* help */ 343 legacypos_help, /* help */ 344 NULL, /* next pointer */ 339 345 }; 340 346 -
lib/format_pcap.c
r6c248a9 reeab9832 314 314 } 315 315 316 static libtrace_linktype_t pcap_get_link_type(const structlibtrace_packet_t *packet) {316 static libtrace_linktype_t pcap_get_link_type(const libtrace_packet_t *packet) { 317 317 struct pcap_pkthdr *pcapptr = 0; 318 318 int linktype = 0; … … 462 462 pcap_fin_output, /* fin_output */ 463 463 pcap_read_packet, /* read_packet */ 464 NULL, /* fin_packet */ 464 465 pcap_write_packet, /* write_packet */ 465 466 pcap_get_link_type, /* get_link_type */ … … 478 479 NULL, /* get_fd */ 479 480 trace_event_trace, /* trace_event */ 480 pcap_help /* help */ 481 pcap_help, /* help */ 482 NULL /* next pointer */ 481 483 }; 482 484 … … 495 497 NULL, /* fin_output */ 496 498 pcap_read_packet, /* read_packet */ 499 NULL, /* fin_packet */ 497 500 NULL, /* write_packet */ 498 501 pcap_get_link_type, /* get_link_type */ … … 511 514 pcap_get_fd, /* get_fd */ 512 515 trace_event_device, /* trace_event */ 513 pcapint_help /* help */ 516 pcapint_help, /* help */ 517 NULL /* next pointer */ 514 518 }; 515 519 -
lib/format_rt.c
r30c0246 reeab9832 514 514 NULL, /* fin_output */ 515 515 rt_read_packet, /* read_packet */ 516 NULL, /* fin_packet */ 516 517 NULL, /* write_packet */ 517 518 NULL, /* get_link_type */ … … 530 531 rt_get_fd, /* get_fd */ 531 532 trace_event_device, /* trace_event */ 532 rt_help /* help */ 533 rt_help, /* help */ 534 NULL /* next pointer */ 533 535 }; 534 536 -
lib/format_wag.c
r6c248a9 reeab9832 463 463 NULL, /* fin_output */ 464 464 wag_read_packet, /* read_packet */ 465 NULL, /* fin_packet */ 465 466 NULL, /* write_packet */ 466 467 wag_get_link_type, /* get_link_type */ … … 479 480 wag_get_fd, /* get_fd */ 480 481 trace_event_device, /* trace_event */ 481 wag_help /* help */ 482 wag_help, /* help */ 483 NULL /* next pointer */ 482 484 }; 483 485 … … 498 500 wtf_fin_output, /* fin_output */ 499 501 wtf_read_packet, /* read_packet */ 502 NULL, /* fin_packet */ 500 503 wtf_write_packet, /* write_packet */ 501 504 wag_get_link_type, /* get_link_type */ … … 514 517 NULL, /* get_fd */ 515 518 trace_event_trace, /* trace_event */ 516 wtf_help /* help */ 519 wtf_help, /* help */ 520 NULL /* next pointer */ 517 521 }; 518 522 -
lib/libtrace.h
r0d57541 reeab9832 58 58 #include <sys/types.h> 59 59 #include <netinet/in.h> 60 #include <stdbool.h> 60 61 /** API version as 2 byte hex digits, eg 0xXXYYZZ */ 61 62 #define LIBTRACE_API_VERSION 0x030000 /* 3.0.00 */ … … 462 463 libtrace_err_t trace_get_err(libtrace_t *trace); 463 464 465 /** Return if there is an error 466 * @param trace the trace file to check the error state on 467 * This does not clear the error status, and only returns true or false. 468 */ 469 bool trace_is_err(libtrace_t *trace); 470 471 /** Output an error message to stderr and clear the error status. 472 * @param trace the trace with the error to output 473 * @param msg the message to prefix to the error 474 * This function does clear the error status. 475 */ 476 void trace_perror(libtrace_t *trace, const char *msg,...); 477 464 478 /** Check (and clear) the current error state of an output trace 465 479 * @param trace the output trace file to check the error state on … … 469 483 */ 470 484 libtrace_err_t trace_get_err_output(libtrace_out_t *trace); 485 486 /** Return if there is an error 487 * @param trace the trace file to check the error state on 488 * This does not clear the error status, and only returns true or false. 489 */ 490 bool trace_is_err_output(libtrace_out_t *trace); 491 492 /** Output an error message to stderr and clear the error status. 493 * @param trace the trace with the error to output 494 * @param msg the message to prefix to the error 495 * This function does clear the error status. 496 */ 497 void trace_perror_output(libtrace_out_t *trace, const char *msg,...); 498 471 499 472 500 /*@}*/ … … 835 863 */ 836 864 SIMPLE_FUNCTION 837 inlinelibtrace_linktype_t trace_get_link_type(const libtrace_packet_t *packet);865 libtrace_linktype_t trace_get_link_type(const libtrace_packet_t *packet); 838 866 839 867 /** Get the destination MAC addres -
lib/libtrace_int.h
r0d57541 reeab9832 193 193 */ 194 194 int (*read_packet)(libtrace_t *libtrace, struct libtrace_packet_t *packet); 195 /** finalise a packet 196 * cleanup any resources used by a packet that can't be reused for 197 * the next packet. 198 */ 199 void (*fin_packet)(libtrace_packet_t *packet); 195 200 /** write a packet to a trace from the provided packet 196 201 * (or NULL if output not supported) … … 302 307 /** return information about this trace format to standard out */ 303 308 void (*help)(); 309 /** next pointer, should be NULL */ 310 struct libtrace_format_t *next; 304 311 }; 305 312 -
lib/trace.c
r6c248a9 reeab9832 124 124 struct trace_err_t trace_err; 125 125 126 struct libtrace_format_t **format_list = 0; 127 int format_size = 0; 128 int nformats = 0; 126 static struct libtrace_format_t *formats_list = 0; 129 127 130 128 /* strncpy is not assured to copy the final \0, so we … … 145 143 146 144 void register_format(struct libtrace_format_t *f) { 147 if (format_list == 0) { 148 format_size = 10; 149 format_list = malloc( 150 sizeof(struct libtrace_format_t *) * 151 format_size 152 ); 153 } else if (format_size == nformats) { 154 format_size = format_size + 10; 155 format_list = realloc(format_list, 156 sizeof(struct libtrace_format_t *) * 157 format_size); 158 } 159 format_list[nformats] = f; 145 assert(f->next==NULL); 146 f->next=formats_list; 147 formats_list=f; 160 148 /* Now, verify things */ 161 149 #if 0 … … 230 218 } 231 219 #endif 232 nformats++;233 220 } 234 221 … … 239 226 */ 240 227 void trace_help() { 241 int i = 0;228 struct libtrace_format_t *tmp; 242 229 printf("libtrace %s\n",PACKAGE_VERSION); 243 for (i = 0; i < nformats; i++) { 244 if (format_list[i]->help) { 245 format_list[i]->help(); 246 } 230 for(tmp=formats_list;tmp;tmp=tmp->next) { 231 if (tmp->help) 232 tmp->help(); 247 233 } 248 234 } … … 292 278 char *scan = 0; 293 279 const char *uridata = 0; 294 int i = 0;280 struct libtrace_format_t *tmp; 295 281 296 282 trace_err.err_num = TRACE_ERR_NOERROR; … … 308 294 libtrace->started=false; 309 295 310 for (i = 0; i < nformats; i++) { 311 if (strlen(scan) == strlen(format_list[i]->name) && 312 strncasecmp(scan, 313 format_list[i]->name, 314 strlen(scan)) == 0) { 315 libtrace->format=format_list[i]; 296 for (tmp=formats_list;tmp;tmp=tmp->next) { 297 if (strlen(scan) == strlen(tmp->name) && 298 strncasecmp(scan, tmp->name, strlen(scan)) == 0 299 ) { 300 libtrace->format=tmp; 316 301 break; 317 302 } … … 320 305 trace_set_err(libtrace, TRACE_ERR_BAD_FORMAT, 321 306 "Unknown format (%s)",scan); 322 return 0;307 return libtrace; 323 308 } 324 309 … … 368 353 char *scan = calloc(sizeof(char),URI_PROTO_LINE); 369 354 char *uridata; 370 int i;355 struct libtrace_format_t *tmp; 371 356 372 357 trace_err.err_num = TRACE_ERR_NOERROR; … … 380 365 libtrace->format = 0; 381 366 382 for (i = 0; i < nformats; i++) {383 if (strlen(scan) == strlen( format_list[i]->name) &&367 for(tmp=formats_list;tmp;tmp=tmp->next) { 368 if (strlen(scan) == strlen(tmp->name) && 384 369 !strncasecmp(scan, 385 format_list[i]->name,370 tmp->name, 386 371 strlen(scan))) { 387 libtrace->format= format_list[i];372 libtrace->format=tmp; 388 373 break; 389 374 } … … 410 395 411 396 libtrace_out_t *trace_create_output(const char *uri) { 412 structlibtrace_out_t *libtrace = malloc(sizeof(struct libtrace_out_t));397 libtrace_out_t *libtrace = malloc(sizeof(struct libtrace_out_t)); 413 398 414 399 char *scan = 0; 415 400 const char *uridata = 0; 416 int i;401 struct libtrace_format_t *tmp; 417 402 418 403 trace_err.err_num = TRACE_ERR_NOERROR; … … 420 405 421 406 if ((uridata = trace_parse_uri(uri, &scan)) == 0) { 422 trace_set_err_out(libtrace,TRACE_ERR_BAD_FORMAT,"Bad uri format (%s)",uri); 407 trace_set_err_out(libtrace,TRACE_ERR_BAD_FORMAT, 408 "Bad uri format (%s)",uri); 423 409 return libtrace; 424 410 } 425 411 426 412 427 libtrace->format = 0;428 for (i = 0; i < nformats; i++) {429 if (strlen(scan) == strlen( format_list[i]->name) &&413 libtrace->format = NULL; 414 for(tmp=formats_list;tmp;tmp=tmp->next) { 415 if (strlen(scan) == strlen(tmp->name) && 430 416 !strncasecmp(scan, 431 format_list[i]->name,417 tmp->name, 432 418 strlen(scan))) { 433 libtrace->format= format_list[i];419 libtrace->format=tmp; 434 420 break; 435 421 } 436 422 } 437 if (libtrace->format == 0) {423 if (libtrace->format == NULL) { 438 424 trace_set_err_out(libtrace,TRACE_ERR_BAD_FORMAT, 439 425 "Unknown output format (%s)",scan); 440 return 0;426 return libtrace; 441 427 } 442 428 libtrace->uridata = strdup(uridata); … … 452 438 case -1: /* failure */ 453 439 free(libtrace); 454 return 0;440 return libtrace; 455 441 case 0: /* success */ 456 442 break; … … 501 487 } 502 488 503 libtrace->started= false;489 libtrace->started=true; 504 490 return 0; 505 491 } … … 689 675 assert(packet->size<65536); 690 676 assert(packet->size>0); 677 assert(libtrace->started); 691 678 692 679 if (libtrace->format->write_packet) { … … 1675 1662 } 1676 1663 1664 bool trace_is_err(libtrace_t *trace) 1665 { 1666 return trace->err.err_num != 0; 1667 } 1668 1669 void trace_perror(libtrace_t *trace,const char *msg,...) 1670 { 1671 char buf[256]; 1672 va_list va; 1673 va_start(va,msg); 1674 vsnprintf(buf,sizeof(buf),msg,va); 1675 va_end(va); 1676 if(trace->err.err_num) { 1677 fprintf(stderr,"%s(%s): %s\n", 1678 buf,trace->uridata,trace->err.problem); 1679 } else { 1680 fprintf(stderr,"%s(%s): No error\n", 1681 buf,trace->uridata); 1682 } 1683 } 1684 1677 1685 libtrace_err_t trace_get_err_output(libtrace_out_t *trace) 1678 1686 { … … 1681 1689 trace->err.problem[0]='\0'; 1682 1690 return err; 1691 } 1692 1693 bool trace_is_err_output(libtrace_out_t *trace) 1694 { 1695 return trace->err.err_num != 0; 1696 } 1697 1698 void trace_perror_output(libtrace_out_t *trace,const char *msg,...) 1699 { 1700 char buf[256]; 1701 va_list va; 1702 va_start(va,msg); 1703 vsnprintf(buf,sizeof(buf),msg,va); 1704 va_end(va); 1705 if(trace->err.err_num) { 1706 fprintf(stderr,"%s(%s): %s\n", 1707 buf,trace->uridata,trace->err.problem); 1708 } else { 1709 fprintf(stderr,"%s(%s): No error\n",buf,trace->uridata); 1710 } 1683 1711 } 1684 1712
Note: See TracChangeset
for help on using the changeset viewer.