Changeset 37195b4
- Timestamp:
- 02/10/06 10:52:41 (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:
- 7f32bb5
- Parents:
- 56ef532
- Location:
- lib
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/Makefile.am
r3b8a5ef r37195b4 3 3 4 4 extra_DIST = format_template.c 5 libtrace_la_SOURCES = trace.c fifo.c fifo.h common.h format_erf.c format_pcap.c format_wag.c format_helper.c format_helper.h parse_cmd.c parse_cmd.h libtrace_int.h lt_inttypes.h 5 libtrace_la_SOURCES = trace.c fifo.c fifo.h common.h \ 6 format_erf.c format_pcap.c format_wag.c format_legacy.c \ 7 format_helper.c format_helper.h \ 8 parse_cmd.c parse_cmd.h libtrace_int.h lt_inttypes.h 6 9 if DAG2_4 7 10 nodist_libtrace_la_SOURCES = dagopts.c dagapi.c -
lib/format_erf.c
r56ef532 r37195b4 76 76 static struct libtrace_format_t dag; 77 77 #endif 78 static struct libtrace_format_t legacypos;79 static struct libtrace_format_t legacyeth;80 static struct libtrace_format_t legacyatm;81 78 82 79 #define CONNINFO libtrace->format_data->conn_info … … 203 200 } 204 201 205 static int legacyeth_get_framing_length(const struct libtrace_packet_t *packet UNUSED)206 {207 return sizeof(legacy_ether_t);208 }209 210 static int legacypos_get_framing_length(const struct libtrace_packet_t *packet UNUSED)211 {212 return sizeof(legacy_pos_t);213 }214 215 static int legacyatm_get_framing_length(const struct libtrace_packet_t *packet UNUSED)216 {217 return sizeof(legacy_cell_t);218 }219 202 220 203 static int erf_init_input(struct libtrace_t *libtrace) { … … 490 473 #endif 491 474 492 static int legacy_read_packet(struct libtrace_t *libtrace, struct libtrace_packet_t *packet) {493 int numbytes;494 void *buffer = packet->buffer;495 496 if ((numbytes=LIBTRACE_READ(INPUT.file,497 buffer,498 64)) == -1) {499 perror("libtrace_read");500 return -1;501 }502 packet->status.type = RT_DATA;503 packet->status.message = 0;504 packet->size = 64;505 506 packet->header = packet->buffer;507 packet->payload = packet->buffer +508 packet->trace->format->get_framing_length(packet);509 510 return 64;511 512 }513 475 static int erf_read_packet(struct libtrace_t *libtrace, struct libtrace_packet_t *packet) { 514 476 int numbytes; … … 758 720 } 759 721 760 static void *legacypos_get_link(const struct libtrace_packet_t *packet) {761 return (void *)packet->payload;762 }763 764 static libtrace_linktype_t legacypos_get_link_type(const struct libtrace_packet_t *packet UNUSED) {765 return TRACE_TYPE_LEGACY_POS;766 }767 768 static void *legacyatm_get_link(const struct libtrace_packet_t *packet) {769 return (void *)packet->payload;770 }771 772 static libtrace_linktype_t legacyatm_get_link_type(const struct libtrace_packet_t *packet UNUSED) {773 return TRACE_TYPE_LEGACY_ATM;774 }775 776 static void *legacyeth_get_link(const struct libtrace_packet_t *packet) {777 return (void *)packet->payload;778 }779 780 static libtrace_linktype_t legacyeth_get_link_type(const struct libtrace_packet_t *packet UNUSED) {781 return TRACE_TYPE_LEGACY_ETH;782 }783 784 785 786 722 static void *erf_get_link(const struct libtrace_packet_t *packet) { 787 723 return (void *)packet->payload; … … 821 757 } 822 758 823 static int legacy_get_capture_length(const struct libtrace_packet_t *packet __attribute__((unused))) {824 return 64;825 }826 827 static int legacypos_get_wire_length(const struct libtrace_packet_t *packet) {828 legacy_pos_t *lpos = (legacy_pos_t *)packet->header;829 return ntohs(lpos->wlen);830 }831 832 static int legacyatm_get_wire_length(const struct libtrace_packet_t *packet UNUSED) {833 return 53;834 }835 836 static int legacyeth_get_wire_length(const struct libtrace_packet_t *packet) {837 legacy_ether_t *leth = (legacy_ether_t *)packet->header;838 return ntohs(leth->wlen);839 }840 759 static int erf_get_capture_length(const struct libtrace_packet_t *packet) { 841 760 dag_record_t *erfptr = 0; … … 910 829 #endif 911 830 912 static void legacypos_help() {913 printf("legacypos format module: $Revision$\n");914 printf("Supported input URIs:\n");915 printf("\tlegacypos:/path/to/file\t(uncompressed)\n");916 printf("\tlegacypos:/path/to/file.gz\t(gzip-compressed)\n");917 printf("\tlegacypos:-\t(stdin, either compressed or not)\n");918 printf("\n");919 printf("\te.g.: legacypos:/tmp/trace.gz\n");920 printf("\n");921 }922 923 static void legacyatm_help() {924 printf("legacyatm format module: $Revision$\n");925 printf("Supported input URIs:\n");926 printf("\tlegacyatm:/path/to/file\t(uncompressed)\n");927 printf("\tlegacyatm:/path/to/file.gz\t(gzip-compressed)\n");928 printf("\tlegacyatm:-\t(stdin, either compressed or not)\n");929 printf("\n");930 printf("\te.g.: legacyatm:/tmp/trace.gz\n");931 printf("\n");932 }933 934 static void legacyeth_help() {935 printf("legacyeth format module: $Revision$\n");936 printf("Supported input URIs:\n");937 printf("\tlegacyeth:/path/to/file\t(uncompressed)\n");938 printf("\tlegacyeth:/path/to/file.gz\t(gzip-compressed)\n");939 printf("\tlegacyeth:-\t(stdin, either compressed or not)\n");940 printf("\n");941 printf("\te.g.: legacyeth:/tmp/trace.gz\n");942 printf("\n");943 }944 945 831 static void erf_help() { 946 832 printf("erf format module: $Revision$\n"); … … 987 873 } 988 874 989 static struct libtrace_format_t legacyatm = {990 "legacyatm",991 "$Id$",992 "legacyatm",993 erf_init_input, /* init_input */994 NULL, /* init_output */995 NULL, /* config_output */996 erf_fin_input, /* fin_input */997 NULL, /* fin_output */998 legacy_read_packet, /* read_packet */999 NULL, /* write_packet */1000 legacyatm_get_link, /* get_link */1001 legacyatm_get_link_type, /* get_link_type */1002 NULL, /* get_direction */1003 NULL, /* set_direction */1004 erf_get_erf_timestamp, /* get_erf_timestamp */1005 NULL, /* get_timeval */1006 NULL, /* get_seconds */1007 legacy_get_capture_length, /* get_capture_length */1008 legacyatm_get_wire_length, /* get_wire_length */1009 legacyatm_get_framing_length, /* get_framing_length */1010 NULL, /* set_capture_length */1011 NULL, /* get_fd */1012 trace_event_trace, /* trace_event */1013 legacyatm_help /* help */1014 };1015 1016 static struct libtrace_format_t legacyeth = {1017 "legacyeth",1018 "$Id$",1019 "legacyeth",1020 erf_init_input, /* init_input */1021 NULL, /* init_output */1022 NULL, /* config_output */1023 erf_fin_input, /* fin_input */1024 NULL, /* fin_output */1025 legacy_read_packet, /* read_packet */1026 NULL, /* write_packet */1027 legacyeth_get_link, /* get_link */1028 legacyeth_get_link_type, /* get_link_type */1029 NULL, /* get_direction */1030 NULL, /* set_direction */1031 erf_get_erf_timestamp, /* get_erf_timestamp */1032 NULL, /* get_timeval */1033 NULL, /* get_seconds */1034 legacy_get_capture_length, /* get_capture_length */1035 legacyeth_get_wire_length, /* get_wire_length */1036 legacyeth_get_framing_length, /* get_framing_length */1037 NULL, /* set_capture_length */1038 NULL, /* get_fd */1039 trace_event_trace, /* trace_event */1040 legacyeth_help /* help */1041 };1042 1043 static struct libtrace_format_t legacypos = {1044 "legacypos",1045 "$Id$",1046 "legacypos",1047 erf_init_input, /* init_input */1048 NULL, /* init_output */1049 NULL, /* config_output */1050 erf_fin_input, /* fin_input */1051 NULL, /* fin_output */1052 legacy_read_packet, /* read_packet */1053 NULL, /* write_packet */1054 legacypos_get_link, /* get_link */1055 legacypos_get_link_type, /* get_link_type */1056 NULL, /* get_direction */1057 NULL, /* set_direction */1058 erf_get_erf_timestamp, /* get_erf_timestamp */1059 NULL, /* get_timeval */1060 NULL, /* get_seconds */1061 legacy_get_capture_length, /* get_capture_length */1062 legacypos_get_wire_length, /* get_wire_length */1063 legacypos_get_framing_length, /* get_framing_length */1064 NULL, /* set_capture_length */1065 NULL, /* get_fd */1066 trace_event_trace, /* trace_event */1067 legacypos_help /* help */1068 };1069 1070 1071 875 static struct libtrace_format_t erf = { 1072 876 "erf", … … 1074 878 "erf", 1075 879 erf_init_input, /* init_input */ 880 NULL, /* config_input */ 881 NULL, /* start_input */ 1076 882 erf_init_output, /* init_output */ 1077 883 erf_config_output, /* config_output */ 884 NULL, /* start_output */ 1078 885 erf_fin_input, /* fin_input */ 1079 886 erf_fin_output, /* fin_output */ 1080 887 erf_read_packet, /* read_packet */ 1081 888 erf_write_packet, /* write_packet */ 1082 erf_get_link, /* get_link */1083 889 erf_get_link_type, /* get_link_type */ 1084 890 erf_get_direction, /* get_direction */ … … 1102 908 "erf", 1103 909 dag_init_input, /* init_input */ 910 NULL, /* config_input */ 911 NULL, /* start_output */ 1104 912 NULL, /* init_output */ 1105 913 NULL, /* config_output */ 914 NULL, /* start_output */ 1106 915 dag_fin_input, /* fin_input */ 1107 916 NULL, /* fin_output */ 1108 917 dag_read_packet, /* read_packet */ 1109 918 NULL, /* write_packet */ 1110 erf_get_link, /* get_link */1111 919 erf_get_link_type, /* get_link_type */ 1112 920 erf_get_direction, /* get_direction */ … … 1130 938 "erf", 1131 939 rtclient_init_input, /* init_input */ 940 NULL, /* config_input */ 941 NULL, /* start_input */ 1132 942 NULL, /* init_output */ 1133 943 NULL, /* config_output */ 944 NULL, /* start_output */ 1134 945 rtclient_fin_input, /* fin_input */ 1135 946 NULL, /* fin_output */ 1136 947 rtclient_read_packet, /* read_packet */ 1137 948 NULL, /* write_packet */ 1138 erf_get_link, /* get_link */1139 949 erf_get_link_type, /* get_link_type */ 1140 950 erf_get_direction, /* get_direction */ … … 1157 967 register_format(&dag); 1158 968 #endif 1159 register_format(&rtclient); 1160 register_format(&legacypos); 1161 register_format(&legacyeth); 1162 register_format(&legacyatm); 1163 } 969 } -
lib/format_pcap.c
r3b8a5ef r37195b4 425 425 "pcap", 426 426 pcap_init_input, /* init_input */ 427 NULL, /* config_input */ 428 NULL, /* start_input */ 427 429 pcap_init_output, /* init_output */ 428 430 NULL, /* config_output */ 431 NULL, /* start_output */ 429 432 pcap_fin_input, /* fin_input */ 430 433 pcap_fin_output, /* fin_output */ 431 434 pcap_read_packet, /* read_packet */ 432 435 pcap_write_packet, /* write_packet */ 433 pcap_get_link, /* get_link */434 436 pcap_get_link_type, /* get_link_type */ 435 437 pcap_get_direction, /* get_direction */ … … 452 454 "pcap", 453 455 pcapint_init_input, /* init_input */ 456 NULL, /* config_input */ 457 NULL, /* start_input */ 454 458 pcapint_init_output, /* init_output */ 455 459 NULL, /* config_output */ 460 NULL, /* start_output */ 456 461 pcap_fin_input, /* fin_input */ 457 462 pcapint_fin_output, /* fin_output */ 458 463 pcap_read_packet, /* read_packet */ 459 464 pcapint_write_packet, /* write_packet */ 460 pcap_get_link, /* get_link */461 465 pcap_get_link_type, /* get_link_type */ 462 466 pcap_get_direction, /* get_direction */ -
lib/format_wag.c
r2e8aa42 r37195b4 495 495 "wtf", 496 496 wag_init_input, /* init_input */ 497 NULL, /* config_input */ 498 NULL, /* start_input */ 497 499 NULL, /* init_output */ 498 500 NULL, /* config_output */ 501 NULL, /* start_output */ 499 502 wag_fin_input, /* fin_input */ 500 503 NULL, /* fin_output */ 501 504 wag_read_packet, /* read_packet */ 502 505 NULL, /* write_packet */ 503 wag_get_link, /* get_link */504 506 wag_get_link_type, /* get_link_type */ 505 507 wag_get_direction, /* get_direction */ … … 524 526 "wtf", 525 527 wtf_init_input, /* init_input */ 528 NULL, /* config input */ 529 NULL, /* start input */ 526 530 wtf_init_output, /* init_output */ 527 531 wtf_config_output, /* config_output */ 532 NULL, /* start output */ 528 533 wtf_fin_input, /* fin_input */ 529 534 wtf_fin_output, /* fin_output */ 530 535 wtf_read_packet, /* read_packet */ 531 536 wtf_write_packet, /* write_packet */ 532 wag_get_link, /* get_link */533 537 wag_get_link_type, /* get_link_type */ 534 538 wag_get_direction, /* get_direction */ -
lib/libtrace_int.h
rf9374e9 r37195b4 71 71 #endif 72 72 73 #include <stdbool.h> 74 73 75 typedef enum {SOCKET, TRACE, STDIN, DEVICE, INTERFACE, RT } source_t; 74 76 … … 100 102 struct libtrace_format_data_t *format_data; /**<format data pointer */ 101 103 source_t sourcetype; /**< The type (device,file, etc */ 104 bool started; 102 105 103 106 struct libtrace_event_t event; … … 150 153 char *type; 151 154 int (*init_input)(struct libtrace_t *libtrace); 155 int (*config_input)(struct libtrace_t *libtrace,char *option,void *value); 156 int (*start_input)(struct libtrace_t *libtrace); 152 157 int (*init_output)(struct libtrace_out_t *libtrace); 153 158 int (*config_output)(struct libtrace_out_t *libtrace, int argc, char *argv[]); 159 int (*start_output)(struct libtrace_out_t *libtrace); 154 160 int (*fin_input)(struct libtrace_t *libtrace); 155 161 int (*fin_output)(struct libtrace_out_t *libtrace); 156 162 int (*read_packet)(struct libtrace_t *libtrace, struct libtrace_packet_t *packet); 157 163 int (*write_packet)(struct libtrace_out_t *libtrace, const struct libtrace_packet_t *packet); 158 void* (*get_link)(const struct libtrace_packet_t *packet);159 164 libtrace_linktype_t (*get_link_type)(const struct libtrace_packet_t *packet); 160 165 int8_t (*get_direction)(const struct libtrace_packet_t *packet); -
lib/trace.c
rbb09ce4 r37195b4 154 154 155 155 void register_format(struct libtrace_format_t *f) { 156 // fprintf(stderr,"Registering input format %s\n",f->name);157 156 if (format_list == 0) { 158 157 format_size = 10; … … 311 310 assert( libtrace->fifo); 312 311 free(scan); 312 libtrace->started=false; 313 313 return libtrace; 314 314 } … … 430 430 } 431 431 432 /* Start a trace 433 * @param libtrace the input trace to start 434 * @returns 0 on success 435 * 436 * This does the work associated with actually starting up 437 * the trace. it may fail. 438 */ 439 int trace_start(struct libtrace_t *libtrace) 440 { 441 if (libtrace->format->start_input) { 442 int ret=libtrace->format->start_input(libtrace); 443 if (!ret) { 444 return ret; 445 } 446 } 447 448 libtrace->started=true; 449 return 0; 450 } 451 432 452 /* Parses an output options string and calls the appropriate function to deal with output options. 433 453 * … … 520 540 int trace_read_packet(struct libtrace_t *libtrace, struct libtrace_packet_t *packet) { 521 541 522 if (!libtrace) { 523 fprintf(stderr,"You called trace_read_packet() with a NULL libtrace parameter!\n"); 524 } 525 assert(libtrace); 526 assert(packet); 542 assert(libtrace && "You called trace_read_packet() with a NULL libtrace parameter!\n"); 543 assert(libtrace->started && "BUG: You must call libtrace_start() before trace_read_packet()\n"); 544 assert(packet); 527 545 528 546 /* Store the trace we are reading from into the packet opaque
Note: See TracChangeset
for help on using the changeset viewer.