Changeset 72bfe20
- Timestamp:
- 08/08/05 16:33:16 (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:
- c3274c6
- Parents:
- 8184acc
- Location:
- lib
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/format_erf.c
rdf2dff9 r72bfe20 31 31 #include "libtrace.h" 32 32 #include "libtrace_int.h" 33 #include "format_helper.h" 33 34 #include "rtserver.h" 34 35 #include "parse_cmd.h" … … 136 137 if (S_ISCHR(buf.st_mode)) { 137 138 // DEVICE 139 libtrace->sourcetype = DEVICE; 138 140 if((INPUT.fd = 139 141 dag_open(CONNINFO.path)) < 0) { … … 172 174 if (!strncmp(CONNINFO.path,"-",1)) { 173 175 // STDIN 176 libtrace->sourcetype = STDIN; 174 177 #if HAVE_ZLIB 175 178 INPUT.file = gzdopen(STDIN, "r"); … … 184 187 } 185 188 if (S_ISSOCK(buf.st_mode)) { 186 // SOCKET189 libtrace->sourcetype = SOCKET; 187 190 if ((INPUT.fd = socket( 188 191 AF_UNIX, SOCK_STREAM, 0)) == -1) { … … 203 206 } 204 207 } else { 205 // TRACE208 libtrace->sourcetype = TRACE; 206 209 #if HAVE_ZLIB 207 210 // using gzdopen means we can set O_LARGEFILE … … 230 233 libtrace->format_data = (struct libtrace_format_data_t *) 231 234 malloc(sizeof(struct libtrace_format_data_t)); 235 236 libtrace->sourcetype = RT; 232 237 233 238 if (strlen(uridata) == 0) { … … 733 738 } 734 739 740 static int rtclient_get_fd(struct libtrace_packet_t *packet) { 741 return packet->trace->format_data->input.fd; 742 } 743 744 static int erf_get_fd(struct libtrace_packet_t *packet) { 745 return packet->trace->format_data->input.fd; 746 } 747 735 748 static void dag_help() { 736 749 printf("dag format module: $Revision$\n"); … … 799 812 erf_fin_input, /* fin_input */ 800 813 erf_fin_output, /* fin_output */ 801 NULL, /* read */802 814 erf_read_packet, /* read_packet */ 803 815 erf_write_packet, /* write_packet */ … … 812 824 erf_get_wire_length, /* get_wire_length */ 813 825 erf_set_capture_length, /* set_capture_length */ 826 erf_get_fd, /* get_fd */ 827 trace_event_trace, /* trace_event */ 814 828 erf_help /* help */ 815 829 }; … … 824 838 dag_fin_input, /* fin_input */ 825 839 NULL, /* fin_output */ 826 dag_read, /* read */827 840 dag_read_packet, /* read_packet */ 828 841 NULL, /* write_packet */ … … 837 850 erf_get_wire_length, /* get_wire_length */ 838 851 erf_set_capture_length, /* set_capture_length */ 852 NULL, /* get_fd */ 853 trace_event_trace, /* trace_event */ 839 854 dag_help /* help */ 840 855 }; … … 849 864 rtclient_fin_input, /* fin_input */ 850 865 rtclient_fin_output, /* fin_output */ 851 rtclient_read, /* read */852 866 rtclient_read_packet, /* read_packet */ 853 867 rtclient_write_packet, /* write_packet */ … … 862 876 erf_get_wire_length, /* get_wire_length */ 863 877 erf_set_capture_length, /* set_capture_length */ 878 rtclient_get_fd, /* get_fd */ 879 trace_event_device, /* trace_event */ 864 880 rtclient_help /* help */ 865 881 }; -
lib/format_pcap.c
r9e2a109 r72bfe20 33 33 #include "libtrace.h" 34 34 #include "libtrace_int.h" 35 #include "format_helper.h" 35 36 #include <inttypes.h> 36 37 #include <sys/types.h> … … 56 57 57 58 #if HAVE_PCAP 59 60 #define CONNINFO libtrace->format_data->conn_info 61 #define INPUT libtrace->format_data->input 58 62 59 63 struct libtrace_format_data_t { … … 76 80 libtrace->format_data = (struct libtrace_format_data_t *) 77 81 malloc(sizeof(struct libtrace_format_data_t)); 78 libtrace->format_data->conn_info.path = libtrace->uridata; 79 if (!strncmp(libtrace->format_data->conn_info.path,"-",1)) { 80 if ((libtrace->format_data->input.pcap = 81 pcap_open_offline(libtrace->format_data->conn_info.path, 82 CONNINFO.path = libtrace->uridata; 83 84 libtrace->sourcetype = TRACE; 85 if (!strncmp(CONNINFO.path,"-",1)) { 86 if ((INPUT.pcap = 87 pcap_open_offline(CONNINFO.path, 82 88 errbuf)) == NULL) { 83 89 fprintf(stderr,"%s\n",errbuf); … … 85 91 } 86 92 } else { 87 if (stat( libtrace->format_data->conn_info.path,&buf) == -1) {93 if (stat(CONNINFO.path,&buf) == -1) { 88 94 perror("stat"); 89 95 return 0; 90 96 } 91 97 if (S_ISCHR(buf.st_mode)) { 92 if (( libtrace->format_data->input.pcap =93 pcap_open_live( libtrace->format_data->conn_info.path,98 if ((INPUT.pcap = 99 pcap_open_live(CONNINFO.path, 94 100 4096, 95 101 1, … … 100 106 } 101 107 } else { 102 if (( libtrace->format_data->input.pcap =103 pcap_open_offline( libtrace->format_data->conn_info.path,108 if ((INPUT.pcap = 109 pcap_open_offline(CONNINFO.path, 104 110 errbuf)) == NULL) { 105 111 fprintf(stderr,"%s\n",errbuf); … … 110 116 fprintf(stderr, 111 117 "Unsupported scheme (%s) for format pcap\n", 112 libtrace->format_data->conn_info.path);118 CONNINFO.path); 113 119 return 0; 114 120 … … 117 123 static int pcapint_init_input(struct libtrace_t *libtrace) { 118 124 char errbuf[PCAP_ERRBUF_SIZE]; 119 if ((libtrace->format_data->input.pcap = 120 pcap_open_live(libtrace->format_data->conn_info.path, 125 libtrace->format_data = (struct libtrace_format_data_t *) 126 malloc(sizeof(struct libtrace_format_data_t)); 127 CONNINFO.path = libtrace->uridata; 128 libtrace->sourcetype = INTERFACE; 129 if ((INPUT.pcap = 130 pcap_open_live(CONNINFO.path, 121 131 4096, 122 132 1, … … 149 159 int pcapbytes = 0; 150 160 151 while ((pcapbytes = pcap_dispatch( libtrace->format_data->input.pcap,161 while ((pcapbytes = pcap_dispatch(INPUT.pcap, 152 162 1, /* number of packets */ 153 163 &trace_pcap_handler, … … 274 284 } 275 285 286 static int pcap_get_fd(struct libtrace_packet_t *packet) { 287 return pcap_fileno(packet->trace->format_data->input.pcap); 288 } 289 276 290 static void pcap_help() { 277 291 printf("pcap format module: $Revision$\n"); … … 307 321 pcap_fin_input, /* fin_input */ 308 322 NULL, /* fin_output */ 309 NULL, /* read */310 323 pcap_read_packet, /* read_packet */ 311 324 NULL, /* write_packet */ … … 320 333 pcap_get_wire_length, /* get_wire_length */ 321 334 pcap_set_capture_length, /* set_capture_length */ 335 NULL, /* get_fd */ 336 trace_event_trace, /* trace_event */ 322 337 pcap_help /* help */ 323 338 }; … … 331 346 pcap_fin_input, /* fin_input */ 332 347 NULL, /* fin_output */ 333 NULL, /* read */334 348 pcap_read_packet, /* read_packet */ 335 349 NULL, /* write_packet */ … … 344 358 pcap_get_wire_length, /* get_wire_length */ 345 359 pcap_set_capture_length, /* set_capture_length */ 360 pcap_get_fd, /* get_fd */ 361 trace_event_device, /* trace_event */ 346 362 pcapint_help /* help */ 347 363 }; -
lib/format_template.c
r9e2a109 r72bfe20 31 31 #include "libtrace.h" 32 32 #include "libtrace_int.h" 33 #include "format_helper.h" 33 34 #include <inttypes.h> 34 35 … … 58 59 } 59 60 60 static int template_read(struct libtrace_t *libtrace, void *buffer, size_t len) {61 return -1;62 }63 61 static int template_read_packet(struct libtrace_t *libtrace, struct libtrace_packet_t *packet) { 64 62 return -1; … … 110 108 } 111 109 110 static int template_get_fd(const struct libtrace_packet_t *packet) { 111 return -1; 112 } 113 112 114 static void template_help() { 113 115 return; … … 121 123 template_fin_input, /* fin_input */ 122 124 template_fin_output, /* fin_output */ 123 template_read, /* read */124 125 template_read_packet, /* read_packet */ 125 126 template_write_packet, /* write_packet */ … … 134 135 template_get_wire_length, /* get_wire_length */ 135 136 template_set_capture_length, /* set_capture_length */ 137 template_get_fd, /* get_fd */ 138 trace_event_trace, /* trace_event */ 136 139 template_help /* help */ 137 140 }; -
lib/format_wag.c
r9e2a109 r72bfe20 31 31 #include "libtrace.h" 32 32 #include "libtrace_int.h" 33 #include "format_helper.h" 33 34 #include "wag.h" 34 35 … … 59 60 #endif 60 61 62 #define CONNINFO libtrace->format_data->conn_info 63 #define INPUT libtrace->format_data->input 61 64 struct libtrace_format_data_t { 62 65 union { … … 86 89 libtrace->format_data = (struct libtrace_format_data_t *) 87 90 calloc(1,sizeof(struct libtrace_format_data_t)); 88 libtrace->format_data->conn_info.path = libtrace->uridata; 89 if (!strncmp(libtrace->format_data->conn_info.path,"-",1)) { 91 CONNINFO.path = libtrace->uridata; 92 if (!strncmp(CONNINFO.path,"-",1)) { 93 libtrace->sourcetype = STDIN; 90 94 // STDIN 91 95 #if HAVE_ZLIB 92 libtrace->format_data->input.file = gzdopen(STDIN, "r");96 INPUT.file = gzdopen(STDIN, "r"); 93 97 #else 94 libtrace->format_data->input.file = stdin;98 INPUT.file = stdin; 95 99 #endif 96 100 97 101 } else { 98 if (stat( libtrace->format_data->conn_info.path,&buf) == -1 ) {102 if (stat(CONNINFO.path,&buf) == -1 ) { 99 103 perror("stat"); 100 104 return 0; 101 105 } 102 106 if (S_ISSOCK(buf.st_mode)) { 107 libtrace->sourcetype = SOCKET; 103 108 // SOCKET 104 if (( libtrace->format_data->input.fd = socket(109 if ((INPUT.fd = socket( 105 110 AF_UNIX, SOCK_STREAM, 0)) == -1) { 106 111 perror("socket"); … … 111 116 snprintf(unix_sock.sun_path, 112 117 108,"%s" 113 , libtrace->format_data->conn_info.path);114 115 if (connect( libtrace->format_data->input.fd,118 ,CONNINFO.path); 119 120 if (connect(INPUT.fd, 116 121 (struct sockaddr *)&unix_sock, 117 122 sizeof(struct sockaddr)) == -1) { … … 121 126 } else { 122 127 // TRACE 128 libtrace->sourcetype = TRACE; 123 129 #if HAVE_ZLIB 124 130 // using gzdopen means we can set O_LARGEFILE 125 131 // ourselves. However, this way is messy and 126 132 // we lose any error checking on "open" 127 libtrace->format_data->input.file =133 INPUT.file = 128 134 gzdopen(open( 129 libtrace->format_data->conn_info.path,135 CONNINFO.path, 130 136 O_LARGEFILE), "r"); 131 137 #else 132 libtrace->format_data->input.file =138 INPUT.file = 133 139 fdopen(open( 134 libtrace->format_data->conn_info.path,140 CONNINFO.path, 135 141 O_LARGEFILE), "r"); 136 142 #endif … … 142 148 static int wag_fin_input(struct libtrace_t *libtrace) { 143 149 #if HAVE_ZLIB 144 gzclose( libtrace->format_data->input.file);150 gzclose(INPUT.file); 145 151 #else 146 fclose( libtrace->format_data->input.file);152 fclose(INPUT.file); 147 153 #endif 148 154 } … … 161 167 switch(libtrace->sourcetype) { 162 168 case DEVICE: 163 if ((numbytes=read( libtrace->format_data->input.fd,169 if ((numbytes=read(INPUT.fd, 164 170 buffer, 165 171 len)) == -1) { … … 170 176 default: 171 177 #if HAVE_ZLIB 172 if ((numbytes=gzread( libtrace->format_data->input.file,178 if ((numbytes=gzread(INPUT.file, 173 179 buffer, 174 180 len)) == -1) { … … 178 184 #else 179 185 if ((numbytes=fread(buffer,len,1, 180 libtrace->format_data->input.file)) == 0 ) {181 if(feof( libtrace->format_data->input.file)) {186 INPUT.file)) == 0 ) { 187 if(feof(INPUT.file)) { 182 188 return 0; 183 189 } 184 if(ferror( libtrace->format_data->input.file)) {190 if(ferror(INPUT.file)) { 185 191 perror("fread"); 186 192 return -1; … … 291 297 } 292 298 299 static int wag_get_fd(const struct libtrace_packet_t *packet) { 300 return packet->trace->format_data->input.fd; 301 } 302 303 static struct libtrace_eventobj_t wag_event_trace(struct libtrace_t *trace, struct libtrace_packet_t *packet) { 304 switch(trace->sourcetype) { 305 case DEVICE: 306 return trace_event_device(trace,packet); 307 default: 308 return trace_event_trace(trace,packet); 309 } 310 } 293 311 static int wag_help() { 294 312 printf("wag format module: $Revision$\n"); … … 315 333 wag_fin_input, /* fin_input */ 316 334 NULL, /* fin_output */ 317 NULL, /* read */318 335 wag_read_packet, /* read_packet */ 319 336 NULL, /* write_packet */ … … 328 345 wag_get_wire_length, /* get_wire_length */ 329 346 NULL, /* set_capture_length */ 347 wag_get_fd, /* get_fd */ 348 wag_event_trace, /* trace_event */ 330 349 wag_help /* help */ 331 350 }; -
lib/libtrace_int.h
r9e2a109 r72bfe20 83 83 } packet; 84 84 double tdelta; 85 double trace_start_ts;86 double real_start_ts;85 // double trace_start_ts; 86 // double real_start_ts; 87 87 double trace_last_ts; 88 88 89 double last_ts;90 double start_ts;89 // double last_ts; 90 // double start_ts; 91 91 }; 92 92 … … 151 151 int (*fin_input)(struct libtrace_t *libtrace); 152 152 int (*fin_output)(struct libtrace_out_t *libtrace); 153 int (*read)(struct libtrace_t *libtrace, void *buffer, size_t len);153 // int (*read)(struct libtrace_t *libtrace, void *buffer, size_t len); 154 154 int (*read_packet)(struct libtrace_t *libtrace, struct libtrace_packet_t *packet); 155 155 int (*write_packet)(struct libtrace_out_t *libtrace, struct libtrace_packet_t *packet); … … 164 164 int (*get_wire_length)(const struct libtrace_packet_t *packet); 165 165 size_t (*truncate_packet)(const struct libtrace_packet_t *packet,size_t size); 166 int (*get_fd)(struct libtrace_packet_t *packet); 167 struct libtrace_eventobj_t (*trace_event)(struct libtrace_t *trace, struct libtrace_packet_t *packet); 166 168 void (*help)(); 167 169 }; -
lib/trace.c
ra114d8b5 r72bfe20 113 113 #endif 114 114 115 #if HAVE_PCAP_H116 # include <pcap.h>117 # ifdef HAVE_PCAP_INT_H118 # include <pcap-int.h>119 # endif120 #endif121 122 #ifdef HAVE_ZLIB_H123 # include <zlib.h>124 #endif125 126 127 #include "wag.h"128 129 #ifdef HAVE_DAG_API130 # include "dagnew.h"131 # include "dagapi.h"132 #else133 # include "dagformat.h"134 #endif115 //#if HAVE_PCAP_H 116 //# include <pcap.h> 117 //# ifdef HAVE_PCAP_INT_H 118 //# include <pcap-int.h> 119 //# endif 120 //#endif 121 122 //#ifdef HAVE_ZLIB_H 123 //# include <zlib.h> 124 //#endif 125 126 127 //#include "wag.h" 128 129 //#ifdef HAVE_DAG_API 130 //# include "dagnew.h" 131 //# include "dagapi.h" 132 //#else 133 //# include "dagformat.h" 134 //#endif 135 135 136 136 #include "libtrace_int.h" 137 #include "format_helper.h" 137 138 //#include "format/format_list.h" 138 139 #include <err.h> … … 977 978 packet->trace = trace; 978 979 979 /* Is there a packet ready? */ 980 switch (trace->sourcetype) { 981 #if HAVE_PCAP 982 case INTERFACE: 983 { 984 int data; 985 // XXX FIXME 986 //event.fd = pcap_fileno(trace->input.pcap); 987 if(ioctl(event.fd,FIONREAD,&data)==-1){ 988 perror("ioctl(FIONREAD)"); 989 } 990 if (data>0) { 991 event.size = trace_read_packet(trace,packet); 992 event.type = TRACE_EVENT_PACKET; 993 return event; 994 } 995 event.type = TRACE_EVENT_IOWAIT; 996 return event; 997 } 998 #endif 999 case SOCKET: 1000 case DEVICE: 1001 case RT: 1002 { 1003 int data; 1004 // XXX FIXME 1005 //event.fd = trace->input.fd; 1006 if(ioctl(event.fd,FIONREAD,&data)==-1){ 1007 perror("ioctl(FIONREAD)"); 1008 } 1009 if (data>0) { 1010 event.size = trace_read_packet(trace,packet); 1011 event.type = TRACE_EVENT_PACKET; 1012 return event; 1013 } 1014 event.type = TRACE_EVENT_IOWAIT; 1015 return event; 1016 } 1017 case STDIN: 1018 case TRACE: 1019 { 1020 double ts; 1021 double now; 1022 struct timeval stv; 1023 /* "Prime" the pump */ 1024 if (!trace->event.packet.buffer) { 1025 trace->event.packet.buffer = malloc(4096); 1026 trace->event.packet.size= 1027 trace_read_packet(trace,packet); 1028 event.size = trace->event.packet.size; 1029 if (trace->event.packet.size > 0 ) { 1030 memcpy(trace->event.packet.buffer,packet->buffer,trace->event.packet.size); 1031 } else { 1032 // return here, the test for event.size will sort out the error 1033 event.type = TRACE_EVENT_PACKET; 1034 return event; 1035 } 1036 } 1037 1038 ts=trace_get_seconds(packet); 1039 if (trace->event.tdelta!=0) { 1040 // Get the adjusted current time 1041 gettimeofday(&stv, NULL); 1042 now = stv.tv_sec + ((double)stv.tv_usec / 1000000.0); 1043 now -= trace->event.tdelta; // adjust for trace delta 1044 1045 1046 // if the trace timestamp is still in the future, 1047 // return a SLEEP event, otherwise fire the packet 1048 if (ts > now) { 1049 event.seconds = ts - trace->event.trace_last_ts; 1050 event.type = TRACE_EVENT_SLEEP; 1051 return event; 1052 } 1053 } else { 1054 gettimeofday(&stv, NULL); 1055 // work out the difference between the start of trace replay, 1056 // and the first packet in the trace 1057 trace->event.tdelta = stv.tv_sec + ((double)stv.tv_usec / 1000000.0); 1058 trace->event.tdelta -= ts; 1059 1060 } 1061 1062 // This is the first packet, so just fire away. 1063 packet->size = trace->event.packet.size; 1064 memcpy(packet->buffer,trace->event.packet.buffer,trace->event.packet.size); 1065 1066 free(trace->event.packet.buffer); 1067 trace->event.packet.buffer = 0; 1068 event.type = TRACE_EVENT_PACKET; 1069 1070 trace->event.trace_last_ts = ts; 1071 1072 return event; 1073 } 1074 default: 1075 assert(0); 1076 } 1077 assert(0); 980 if (packet->trace->format->trace_event) { 981 return packet->trace->format->trace_event(trace,packet); 982 } else { 983 return event; 984 } 985 1078 986 } 1079 987
Note: See TracChangeset
for help on using the changeset viewer.