Changeset ab4cb04
- Timestamp:
- 02/27/06 14:31:09 (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:
- d5879cc
- Parents:
- afd0b73
- Location:
- lib
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/format_erf.c
rafd0b73 rab4cb04 72 72 #endif 73 73 74 #define CONNINFO libtrace->format_data->conn_info 75 #define INPUT libtrace->format_data->input 76 #define OUTPUT libtrace->format_data->output 74 #define DATA(x) ((struct libtrace_format_data_t *)x->format_data) 75 #define DATAOUT(x) ((struct libtrace_format_data_out_t *)x->format_data) 76 #define CONNINFO DATA(libtrace)->conn_info 77 #define INPUT DATA(libtrace)->input 78 #define OUTPUT DATAOUT(libtrace)->output 77 79 #if HAVE_DAG 78 #define DAG libtrace->format_data->dag79 #endif 80 #define OPTIONS libtrace->format_data->options80 #define DAG DATA(libtrace)->dag 81 #endif 82 #define OPTIONS DATAOUT(libtrace)->options 81 83 struct libtrace_format_data_t { 82 84 union { … … 206 208 static int erf_start_input(struct libtrace_t *libtrace) 207 209 { 208 libtrace->format_data->input.file = trace_open_file(libtrace);209 210 if ( libtrace->format_data->input.file)211 return 1;210 INPUT.file = trace_open_file(libtrace); 211 212 if (!INPUT.file) 213 return -1; 212 214 213 215 return 0; … … 216 218 static int rtclient_init_input(struct libtrace_t *libtrace) { 217 219 char *scan; 218 char *uridata = libtrace->uridata;219 struct hostent *he;220 struct sockaddr_in remote;221 220 libtrace->format_data = (struct libtrace_format_data_t *) 222 221 malloc(sizeof(struct libtrace_format_data_t)); 223 222 224 223 225 if (strlen( uridata) == 0) {224 if (strlen(libtrace->uridata) == 0) { 226 225 CONNINFO.rt.hostname = 227 226 strdup("localhost"); … … 229 228 COLLECTOR_PORT; 230 229 } else { 231 if ((scan = strchr( uridata,':')) == NULL) {230 if ((scan = strchr(libtrace->uridata,':')) == NULL) { 232 231 CONNINFO.rt.hostname = 233 strdup( uridata);232 strdup(libtrace->uridata); 234 233 CONNINFO.rt.port = 235 234 COLLECTOR_PORT; 236 235 } else { 237 236 CONNINFO.rt.hostname = 238 (char *)strndup( uridata,239 (scan - uridata));237 (char *)strndup(libtrace->uridata, 238 (scan - libtrace->uridata)); 240 239 CONNINFO.rt.port = 241 240 atoi(++scan); … … 243 242 } 244 243 244 } 245 246 static int rtclient_start_input(libtrace_t *libtrace) 247 { 248 struct hostent *he; 249 struct sockaddr_in remote; 245 250 if ((he=gethostbyname(CONNINFO.rt.hostname)) == NULL) { 246 251 trace_set_err(libtrace,errno,"failed to resolve %s", 247 252 CONNINFO.rt.hostname); 248 return 0;253 return -1; 249 254 } 250 255 if ((INPUT.fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) { 251 256 trace_set_err(libtrace,errno,"socket(AF_INET,SOCK_STREAM)"); 252 return 0;257 return -1; 253 258 } 254 259 … … 264 269 return 0; 265 270 } 266 return 1;271 return -1; 267 272 } 268 273 … … 683 688 } 684 689 685 static int rtclient_get_fd(const libtrace_t * trace) {686 return trace->format_data->input.fd;687 } 688 689 static int erf_get_fd(const libtrace_t * trace) {690 return trace->format_data->input.fd;690 static int rtclient_get_fd(const libtrace_t *libtrace) { 691 return INPUT.fd; 692 } 693 694 static int erf_get_fd(const libtrace_t *libtrace) { 695 return INPUT.fd; 691 696 } 692 697 … … 841 846 rtclient_init_input, /* init_input */ 842 847 NULL, /* config_input */ 843 NULL,/* start_input */848 rtclient_start_input, /* start_input */ 844 849 NULL, /* pause_input */ 845 850 NULL, /* init_output */ -
lib/format_legacy.c
rafd0b73 rab4cb04 75 75 static struct libtrace_format_t legacyatm; 76 76 77 #define INPUT libtrace->format_data->input 78 #define OUTPUT libtrace->format_data->output 77 #define DATA(x) ((struct legacy_format_data_t *)x->format_data) 78 79 #define INPUT DATA(libtrace)->input 79 80 #if HAVE_DAG 80 #define DAG libtrace->format_data->dag81 #define DAG DATA(libtrace)->dag 81 82 #endif 82 #define OPTIONS libtrace->format_data->options 83 struct libtrace_format_data_t { 84 union { 85 struct { 86 char *hostname; 87 short port; 88 } rt; 89 char *path; 90 } conn_info; 83 84 struct legacy_format_data_t { 91 85 union { 92 86 int fd; … … 100 94 }; 101 95 102 struct libtrace_format_data_out_t {103 union {104 struct {105 char *hostname;106 short port;107 } rt;108 char *path;109 } conn_info;110 };111 112 113 96 static int legacyeth_get_framing_length(const struct libtrace_packet_t *packet UNUSED) 114 97 { … … 128 111 static int erf_init_input(struct libtrace_t *libtrace) 129 112 { 130 libtrace->format_data = (struct libtrace_format_data_t *) 131 malloc(sizeof(struct libtrace_format_data_t)); 132 133 libtrace->format_data->input.file = trace_open_file(libtrace); 134 135 if (libtrace->format_data->input.file) 136 return 1; 113 libtrace->format_data = malloc(sizeof(struct legacy_format_data_t)); 137 114 138 115 return 0; 139 116 } 117 118 static int erf_start_input(libtrace_t *libtrace) 119 { 120 DATA(libtrace)->input.file = trace_open_file(libtrace); 121 122 if (DATA(libtrace)->input.file) 123 return 0; 124 125 return -1; 140 126 } 141 127 … … 258 244 erf_init_input, /* init_input */ 259 245 NULL, /* config_input */ 260 NULL,/* start_input */246 erf_start_input, /* start_input */ 261 247 NULL, /* pause_input */ 262 248 NULL, /* init_output */ … … 291 277 erf_init_input, /* init_input */ 292 278 NULL, /* config_input */ 293 NULL,/* start_input */279 erf_start_input, /* start_input */ 294 280 NULL, /* pause_input */ 295 281 NULL, /* init_output */ … … 324 310 erf_init_input, /* init_input */ 325 311 NULL, /* config_input */ 326 NULL,/* start_input */312 erf_start_input, /* start_input */ 327 313 NULL, /* pause_input */ 328 314 NULL, /* init_output */ -
lib/format_pcap.c
rafd0b73 rab4cb04 69 69 static struct libtrace_format_t pcapint; 70 70 71 #define DATA(x) ((struct libtrace_format_data_t*)((x)->format_data)) 72 73 #define INPUT libtrace->format_data->input 74 #define OUTPUT libtrace->format_data->output 75 struct libtrace_format_data_t { 71 #define DATA(x) ((struct pcap_format_data_t*)((x)->format_data)) 72 #define DATAOUT(x) ((struct pcap_format_data_out_t*)((x)->format_data)) 73 74 #define INPUT DATA(libtrace)->input 75 #define OUTPUT DATAOUT(libtrace)->output 76 struct pcap_format_data_t { 76 77 union { 77 78 char *path; /**< information for local sockets */ … … 88 89 }; 89 90 90 struct libtrace_format_data_out_t {91 struct pcap_format_data_out_t { 91 92 union { 92 93 char *path; … … 103 104 104 105 static int pcap_init_input(struct libtrace_t *libtrace) { 105 libtrace->format_data = (struct libtrace_format_data_t *) 106 malloc(sizeof(struct libtrace_format_data_t)); 106 libtrace->format_data = malloc(sizeof(struct pcap_format_data_t)); 107 107 108 108 INPUT.pcap = NULL; … … 163 163 164 164 static int pcap_init_output(struct libtrace_out_t *libtrace) { 165 libtrace->format_data = (struct libtrace_format_data_out_t *) 166 malloc(sizeof(struct libtrace_format_data_out_t)); 165 libtrace->format_data = malloc(sizeof(struct pcap_format_data_out_t)); 167 166 OUTPUT.trace.pcap = NULL; 168 167 OUTPUT.trace.dump = NULL; … … 171 170 172 171 static int pcapint_init_input(struct libtrace_t *libtrace) { 173 libtrace->format_data = (struct libtrace_format_data_t *) 174 malloc(sizeof(struct libtrace_format_data_t)); 172 libtrace->format_data = malloc(sizeof(struct pcap_format_data_t)); 175 173 DATA(libtrace)->filter = NULL; 176 174 DATA(libtrace)->snaplen = LIBTRACE_PACKET_BUFSIZE; … … 225 223 } 226 224 227 static int pcapint_init_output(struct libtrace_out_t *libtrace) {228 trace_set_err_out(libtrace,TRACE_ERR_NO_INIT_OUT,229 "Writing to a pcap interface not implemented yet");230 return -1;231 }232 233 225 static int pcap_fin_input(struct libtrace_t *libtrace) { 234 pcap_close(INPUT.pcap); 226 /* we don't need to close the pcap object since libtrace will have 227 * paused the trace for us. 228 */ 235 229 free(libtrace->format_data); 236 230 return 0; 237 231 } 238 232 239 static int pcap_fin_output( structlibtrace_out_t *libtrace) {233 static int pcap_fin_output(libtrace_out_t *libtrace) { 240 234 pcap_dump_flush(OUTPUT.trace.dump); 241 235 pcap_dump_close(OUTPUT.trace.dump); … … 243 237 free(libtrace->format_data); 244 238 return 0; 245 }246 247 static int pcapint_fin_output(struct libtrace_out_t *libtrace __attribute__((unused))) {248 return -1;249 239 } 250 240 … … 288 278 } 289 279 290 static int pcap_write_packet(struct libtrace_out_t *libtrace, const struct libtrace_packet_t *packet) { 280 static int pcap_start_output(libtrace_out_t *libtrace) 281 { 282 assert(!OUTPUT.trace.dump); 283 OUTPUT.trace.dump = pcap_dump_open(OUTPUT.trace.pcap, 284 libtrace->uridata); 285 fflush((FILE *)OUTPUT.trace.dump); 286 } 287 288 static int pcap_write_packet(libtrace_out_t *libtrace, const libtrace_packet_t *packet) { 291 289 struct pcap_pkthdr pcap_pkt_hdr; 292 290 … … 295 293 libtrace_to_pcap_dlt(trace_get_link_type(packet)), 296 294 65536); 297 OUTPUT.trace.dump = pcap_dump_open(OUTPUT.trace.pcap,298 libtrace->uridata);299 fflush((FILE *)OUTPUT.trace.dump);300 295 } 301 296 if (libtrace->format == &pcap || … … 318 313 } 319 314 320 static int pcapint_write_packet(struct libtrace_out_t *libtrace __attribute__((unused)), const struct libtrace_packet_t *packet __attribute__((unused))) {321 322 assert(0);323 return 0;324 }325 326 315 static libtrace_linktype_t pcap_get_link_type(const struct libtrace_packet_t *packet) { 327 316 struct pcap_pkthdr *pcapptr = 0; 328 317 int linktype = 0; 329 318 pcapptr = (struct pcap_pkthdr *)packet->header; 330 linktype = pcap_datalink( packet->trace->format_data->input.pcap);319 linktype = pcap_datalink(DATA(packet->trace)->input.pcap); 331 320 return pcap_dlt_to_libtrace(linktype); 332 321 } … … 430 419 431 420 static int pcap_get_fd(const libtrace_t *trace) { 432 return pcap_fileno( trace->format_data->input.pcap);421 return pcap_fileno(DATA(trace)->input.pcap); 433 422 } 434 423 … … 463 452 TRACE_FORMAT_PCAP, 464 453 pcap_init_input, /* init_input */ 465 NULL,/* config_input */454 pcap_config_input, /* config_input */ 466 455 pcap_start_input, /* start_input */ 467 456 pcap_pause_input, /* pause_input */ 468 457 pcap_init_output, /* init_output */ 469 458 NULL, /* config_output */ 470 NULL,/* start_output */459 pcap_start_output, /* start_output */ 471 460 pcap_fin_input, /* fin_input */ 472 461 pcap_fin_output, /* fin_output */ … … 499 488 pcapint_start_input, /* start_input */ 500 489 pcap_pause_input, /* pause_input */ 501 pcapint_init_output,/* init_output */490 NULL, /* init_output */ 502 491 NULL, /* config_output */ 503 492 NULL, /* start_output */ 504 493 pcap_fin_input, /* fin_input */ 505 pcapint_fin_output,/* fin_output */494 NULL, /* fin_output */ 506 495 pcap_read_packet, /* read_packet */ 507 pcapint_write_packet,/* write_packet */496 NULL, /* write_packet */ 508 497 pcap_get_link_type, /* get_link_type */ 509 498 pcap_get_direction, /* get_direction */ -
lib/format_rt.c
rafd0b73 rab4cb04 66 66 #include <stdlib.h> 67 67 68 #define RT_INFO libtrace->format_data68 #define RT_INFO ((struct rt_format_data_t*)libtrace->format_data) 69 69 70 70 int reliability = 0; … … 91 91 92 92 93 struct libtrace_format_data_t {93 struct rt_format_data_t { 94 94 char *hostname; 95 95 int port; … … 175 175 char *scan; 176 176 char *uridata = libtrace->uridata; 177 libtrace->format_data = (struct libtrace_format_data_t *) 178 malloc(sizeof(struct libtrace_format_data_t)); 177 libtrace->format_data = malloc(sizeof(struct rt_format_data_t)); 179 178 180 179 RT_INFO->dummy_erf = NULL; … … 486 485 487 486 static int rt_get_fd(const struct libtrace_t *trace) { 488 return trace->format_data->input_fd;487 return ((struct rt_format_data_t *)trace->format_data)->input_fd; 489 488 } 490 489 -
lib/format_wag.c
rafd0b73 rab4cb04 79 79 static struct libtrace_format_t wag_trace; 80 80 81 #define INPUT libtrace->format_data->input82 #define OUTPUT libtrace->format_data->output83 #define OPTIONS libtrace->format_data->options 84 85 struct libtrace_format_data_t { 86 union { 87 char *path; /**< information for local sockets */ 88 } conn_info; 81 #define DATA(x) ((struct wag_format_data_t *)x->format_data) 82 #define DATAOUT(x) ((struct wag_format_data_out_t *)x->format_data) 83 84 #define INPUT DATA(libtrace)->input 85 #define OUTPUT DATAOUT(libtrace)->output 86 #define OPTIONS DATAOUT(libtrace)->options 87 88 struct wag_format_data_t { 89 89 /** Information about the current state of the input device */ 90 90 union { … … 98 98 }; 99 99 100 struct libtrace_format_data_out_t { 101 union { 102 char *path; 103 } conn_info; 100 struct wag_format_data_out_t { 104 101 union { 105 102 struct { … … 118 115 }; 119 116 120 static int wag_init_input(struct libtrace_t *libtrace) { 117 static int wag_init_input(libtrace_t *libtrace) { 118 libtrace->format_data = calloc(1, sizeof(struct wag_format_data_t)); 119 120 return 0; 121 } 122 123 static int wag_start_input(libtrace_t *libtrace) 124 { 121 125 struct stat buf; 122 libtrace->format_data = (struct libtrace_format_data_t *)123 calloc(1,sizeof(struct libtrace_format_data_t));124 125 126 if (stat(libtrace->uridata,&buf) == -1 ) { 126 127 trace_set_err(libtrace,errno,"stat(%s)",libtrace->uridata); 127 return 0;128 return -1; 128 129 } 129 130 if (S_ISCHR(buf.st_mode)) { 130 131 131 INPUT.fd = open(libtrace->uridata, O_RDONLY); 132 133 132 } else { 134 133 trace_set_err(libtrace,TRACE_ERR_INIT_FAILED, 135 134 "%s is not a valid char device", 136 135 libtrace->uridata); 137 return 0; 138 139 } 140 return 1; 136 return -1; 137 } 138 return 0; 141 139 } 142 140 143 141 static int wtf_init_input(struct libtrace_t *libtrace) 144 142 { 145 libtrace->format_data = (struct libtrace_format_data_t *) 146 malloc(sizeof(struct libtrace_format_data_t)); 147 148 return 1; 143 libtrace->format_data = malloc(sizeof(struct wag_format_data_t)); 144 145 return 0; 149 146 } 150 147 151 148 static int wtf_start_input(libtrace_t *libtrace) 152 149 { 153 libtrace->format_data->input.file = trace_open_file(libtrace);154 155 if ( libtrace->format_data->input.file)156 return 1;157 158 return 0;150 DATA(libtrace)->input.file = trace_open_file(libtrace); 151 152 if (DATA(libtrace)->input.file) 153 return 0; 154 155 return -1; 159 156 } 160 157 161 158 static int wtf_init_output(struct libtrace_out_t *libtrace) { 162 libtrace->format_data = (struct libtrace_format_data_out_t *) 163 calloc(1,sizeof(struct libtrace_format_data_out_t)); 159 libtrace->format_data = calloc(1,sizeof(struct wag_format_data_out_t)); 164 160 165 161 OUTPUT.file = 0; … … 205 201 } 206 202 203 static int wag_pause_input(libtrace_t *libtrace) 204 { 205 close(INPUT.fd); 206 } 207 207 208 static int wag_fin_input(struct libtrace_t *libtrace) { 208 close(INPUT.fd);209 209 free(libtrace->format_data); 210 210 return 0; … … 417 417 418 418 static int wag_get_fd(const libtrace_t *trace) { 419 return trace->format_data->input.fd;419 return DATA(trace)->input.fd; 420 420 } 421 421 … … 454 454 wag_init_input, /* init_input */ 455 455 NULL, /* config_input */ 456 NULL,/* start_input */457 NULL,/* pause_input */456 wag_start_input, /* start_input */ 457 wag_pause_input, /* pause_input */ 458 458 NULL, /* init_output */ 459 459 NULL, /* config_output */ -
lib/libtrace_int.h
rafd0b73 rab4cb04 95 95 struct libtrace_t { 96 96 struct libtrace_format_t *format; /**< format driver pointer */ 97 struct libtrace_format_data_t*format_data; /**<format data pointer */97 void *format_data; /**<format data pointer */ 98 98 bool started; /**< if this trace has started */ 99 99 libtrace_err_t err; /**< error information */ … … 181 181 int (*start_output)(libtrace_out_t *libtrace); 182 182 /** @} */ 183 /** finish an input trace, cleanup (or NULL if input not supported) */ 183 /** finish an input trace, cleanup (or NULL if input not supported) 184 * if the trace is not paused, libtrace will pause the trace before 185 * calling this function. 186 */ 184 187 int (*fin_input)(libtrace_t *libtrace); 185 188 /** finish an output trace, cleanup (or NULL if output not supported) */ … … 200 203 libtrace_linktype_t (*get_link_type)(const libtrace_packet_t *packet); 201 204 /** return the direction of this packet 202 * This function pointer may be NULL if the format does not support 203 * getting a direction. 205 * @note This callback may be NULL if not supported. 204 206 */ 205 207 int8_t (*get_direction)(const libtrace_packet_t *packet); 206 208 /** set the direction of this packet 207 * This function pointer may be NULL if the format does not support 208 * setting a direction. 209 * @note This callback may be NULL if not supported. 209 210 */ 210 211 int8_t (*set_direction)(const libtrace_packet_t *packet, int8_t direction); -
lib/trace.c
rafd0b73 rab4cb04 487 487 void trace_destroy(struct libtrace_t *libtrace) { 488 488 assert(libtrace); 489 if (libtrace->started && libtrace->format->pause_input) 490 libtrace->format->pause_input(libtrace); 489 491 libtrace->format->fin_input(libtrace); 490 492 /* need to free things! */
Note: See TracChangeset
for help on using the changeset viewer.