Changeset 9e2a109 for lib/format_pcap.c
- Timestamp:
- 08/04/05 15:37:08 (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:
- ef55d05
- Parents:
- fe43699
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/format_pcap.c
r7d69878 r9e2a109 32 32 #include "config.h" 33 33 #include "libtrace.h" 34 #include " format.h"34 #include "libtrace_int.h" 35 35 #include <inttypes.h> 36 36 #include <sys/types.h> … … 57 57 #if HAVE_PCAP 58 58 59 struct libtrace_format_data_t { 60 union { 61 char *path; /**< information for local sockets */ 62 char *interface; /**< intormation for reading of network 63 interfaces */ 64 } conn_info; 65 /** Information about the current state of the input device */ 66 union { 67 int fd; 68 FILE *file; 69 pcap_t *pcap; 70 } input; 71 }; 72 59 73 static int pcap_init_input(struct libtrace_t *libtrace) { 60 74 char errbuf[PCAP_ERRBUF_SIZE]; 61 75 struct stat buf; 62 if (!strncmp(libtrace->conn_info.path,"-",1)) { 63 if ((libtrace->input.pcap = 64 pcap_open_offline(libtrace->conn_info.path, 76 libtrace->format_data = (struct libtrace_format_data_t *) 77 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, 65 82 errbuf)) == NULL) { 66 83 fprintf(stderr,"%s\n",errbuf); … … 68 85 } 69 86 } else { 70 if (stat(libtrace-> conn_info.path,&buf) == -1) {87 if (stat(libtrace->format_data->conn_info.path,&buf) == -1) { 71 88 perror("stat"); 72 89 return 0; 73 90 } 74 91 if (S_ISCHR(buf.st_mode)) { 75 if ((libtrace-> input.pcap =76 pcap_open_live(libtrace-> conn_info.path,92 if ((libtrace->format_data->input.pcap = 93 pcap_open_live(libtrace->format_data->conn_info.path, 77 94 4096, 78 95 1, … … 83 100 } 84 101 } else { 85 if ((libtrace-> input.pcap =86 pcap_open_offline(libtrace-> conn_info.path,102 if ((libtrace->format_data->input.pcap = 103 pcap_open_offline(libtrace->format_data->conn_info.path, 87 104 errbuf)) == NULL) { 88 105 fprintf(stderr,"%s\n",errbuf); … … 93 110 fprintf(stderr, 94 111 "Unsupported scheme (%s) for format pcap\n", 95 libtrace-> conn_info.path);112 libtrace->format_data->conn_info.path); 96 113 return 0; 97 114 … … 100 117 static int pcapint_init_input(struct libtrace_t *libtrace) { 101 118 char errbuf[PCAP_ERRBUF_SIZE]; 102 if ((libtrace-> input.pcap =103 pcap_open_live(libtrace-> conn_info.path,119 if ((libtrace->format_data->input.pcap = 120 pcap_open_live(libtrace->format_data->conn_info.path, 104 121 4096, 105 122 1, … … 132 149 int pcapbytes = 0; 133 150 134 while ((pcapbytes = pcap_dispatch(libtrace-> input.pcap,151 while ((pcapbytes = pcap_dispatch(libtrace->format_data->input.pcap, 135 152 1, /* number of packets */ 136 153 &trace_pcap_handler, … … 151 168 int linktype = 0; 152 169 pcapptr = (struct pcap_pkthdr *)packet->buffer; 153 linktype = pcap_datalink(packet->trace-> input.pcap);170 linktype = pcap_datalink(packet->trace->format_data->input.pcap); 154 171 switch(linktype) { 155 172 case DLT_NULL: … … 280 297 printf("\n"); 281 298 } 282 static struct format_t pcap = { 299 300 301 static struct libtrace_format_t pcap = { 283 302 "pcap", 284 303 "$Id$", … … 304 323 }; 305 324 306 static struct format_t pcapint = {325 static struct libtrace_format_t pcapint = { 307 326 "pcapint", 308 327 "$Id$",
Note: See TracChangeset
for help on using the changeset viewer.