- Timestamp:
- 02/17/06 14:49:14 (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:
- 65a5900
- Parents:
- f03fc17
- Location:
- lib
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/common.h
r7068467 r3d4d52d 1 1 #ifndef COMMON_H 2 2 #define COMMON_H 1 3 4 #include "config.h" 3 5 4 6 #ifdef __cplusplus … … 17 19 # define LIBTRACE_CLOSE(file) gzclose(file) 18 20 # define LIBTRACE_WRITE(file,buf,len) gzwrite(file,buf,len) 21 # define LIBTRACE_FILE gzFile* 19 22 #else 20 23 # define LIBTRACE_READ(file,buf,len) read(file,buf,len) … … 23 26 # define LIBTRACE_CLOSE(file) close(file) 24 27 # define LIBTRACE_WRITE(file,buf,len) write(file,buf,len) 28 # define LIBTRACE_FILE int 25 29 #endif 26 30 -
lib/fifo.c
r880aa58 r3d4d52d 85 85 86 86 if ((fifo->base = malloc(fifo->length)) == 0) { 87 libtrace_set_err(errno,"malloc failed");87 trace_set_err(errno,"malloc failed"); 88 88 return 0; 89 89 } -
lib/format_erf.c
rf03fc17 r3d4d52d 69 69 #define COLLECTOR_PORT 3435 70 70 71 /* Catch undefined O_LARGEFILE on *BSD etc */72 #ifndef O_LARGEFILE73 # define O_LARGEFILE 074 #endif75 76 71 static struct libtrace_format_t erf; 77 72 static struct libtrace_format_t rtclient; … … 93 88 short port; 94 89 } rt; 95 char *path;96 90 } conn_info; 97 91 98 92 union { 99 93 int fd; 100 #if HAVE_ZLIB 101 gzFile *file; 102 #else 103 int file; 104 #endif 94 LIBTRACE_FILE file; 105 95 } input; 106 96 … … 161 151 malloc(sizeof(struct libtrace_format_data_t)); 162 152 163 CONNINFO.path = libtrace->uridata; 164 if (stat(CONNINFO.path,&buf) == -1) { 165 trace_set_err(errno,"stat(%s)",CONNINFO.path); 153 if (stat(packet->trace->uridata) == -1) { 154 trace_set_err(errno,"stat(%s)",libtrace->uridata); 166 155 return 0; 167 156 } 168 157 if (S_ISCHR(buf.st_mode)) { 169 158 /* DEVICE */ 170 if((INPUT.fd = dag_open( CONNINFO.path)) < 0) {159 if((INPUT.fd = dag_open(packet->trace->uridata)) < 0) { 171 160 trace_set_err(errno,"Cannot open DAG %s", 172 CONNINFO.path);161 packet->trace->uridata); 173 162 return 0; 174 163 } 175 164 if((DAG.buf = (void *)dag_mmap(INPUT.fd)) == MAP_FAILED) { 176 165 trace_set_err(errno,"Cannot mmap DAG %s", 177 CONNINFO.path);166 packet->trace->uridata); 178 167 return 0; 179 168 } 180 169 if(dag_start(INPUT.fd) < 0) { 181 170 trace_set_err(errno,"Cannot start DAG %s", 182 CONNINFO.path);171 packet->trace->uridata); 183 172 return 0; 184 173 } 185 174 } else { 186 175 trace_set_err(errno,"Not a valid dag device: %s", 187 CONNINFO.path);176 packet->trace->uridata); 188 177 return 0; 189 178 } … … 209 198 210 199 211 static int erf_init_input(struct libtrace_t *libtrace) { 212 struct stat buf; 213 struct sockaddr_un unix_sock; 200 static int erf_init_input(struct libtrace_t *libtrace) 201 { 214 202 libtrace->format_data = (struct libtrace_format_data_t *) 215 203 malloc(sizeof(struct libtrace_format_data_t)); 216 204 217 CONNINFO.path = libtrace->uridata; 218 if (!strncmp(CONNINFO.path,"-",1)) { 219 /* STDIN */ 220 INPUT.file = LIBTRACE_FDOPEN(fileno(stdin), "r"); 221 } else { 222 if (stat(CONNINFO.path,&buf) == -1 ) { 223 trace_set_err(errno,"stat(%s)", 224 CONNINFO.path); 225 return 0; 226 } 227 if (S_ISSOCK(buf.st_mode)) { 228 if ((INPUT.fd = socket( 229 AF_UNIX, SOCK_STREAM, 0)) == -1) { 230 trace_set_err(errno, 231 "socket(AF_UNIX,SOCK_STREAM)"); 232 return 0; 233 } 234 unix_sock.sun_family = AF_UNIX; 235 bzero(unix_sock.sun_path,108); 236 snprintf(unix_sock.sun_path, 237 108,"%s" 238 ,CONNINFO.path); 239 240 if (connect(INPUT.fd, 241 (struct sockaddr *)&unix_sock, 242 sizeof(struct sockaddr)) == -1) { 243 trace_set_err(errno, 244 "connect(%s)", CONNINFO.path); 245 return 0; 246 } 247 } else { 248 int fd; 249 250 251 /* we use an FDOPEN call to reopen an FD 252 * returned from open(), so that we can set 253 * O_LARGEFILE. This gets around gzopen not 254 * letting you do this... 255 */ 256 fd=open(CONNINFO.path,O_LARGEFILE); 257 if (fd==-1) { 258 trace_set_err(errno,"Unable to open %s", 259 CONNINFO.path); 260 } 261 INPUT.file = LIBTRACE_FDOPEN(open( 262 CONNINFO.path, 263 O_LARGEFILE),"r"); 264 } 265 } 266 return 1; 205 libtrace->format_data->input.file = trace_open_file(libtrace); 206 207 if (libtrace->format_data->input.file) 208 return 1; 209 210 return 0; 267 211 } 268 212 … … 494 438 dag_record_size)) == -1) { 495 439 trace_set_err(errno,"read(%s)", 496 CONNINFO.path);440 packet->trace->uridata); 497 441 return -1; 498 442 } … … 513 457 buffer2, 514 458 size)) != size) { 515 trace_set_err(errno, "read(%s)", CONNINFO.path);459 trace_set_err(errno, "read(%s)", packet->trace->uridata); 516 460 return -1; 517 461 } … … 635 579 int numbytes = 0; 636 580 if ((numbytes = LIBTRACE_WRITE(OUTPUT.file, erfptr, dag_record_size + pad)) == 0) { 637 trace_set_err(errno,"write(%s)", CONNINFO.path);581 trace_set_err(errno,"write(%s)",libtrace->uridata); 638 582 return -1; 639 583 } … … 641 585 if (buffer) { 642 586 if ((numbytes=LIBTRACE_WRITE(OUTPUT.file, buffer, size)) == 0) { 643 trace_set_err(errno,"write(%s)", CONNINFO.path);587 trace_set_err(errno,"write(%s)",libtrace->uridata); 644 588 return -1; 645 589 } -
lib/format_helper.c
r880aa58 r3d4d52d 36 36 #include <stdio.h> 37 37 #include <string.h> 38 #include <errno.h> 39 #include <fcntl.h> /* for O_LARGEFILE */ 38 40 #ifdef HAVE_INTTYPES_H 39 41 # include <inttypes.h> … … 135 137 136 138 } 139 140 /* Catch undefined O_LARGEFILE on *BSD etc */ 141 #ifndef O_LARGEFILE 142 # define O_LARGEFILE 0 143 #endif 144 145 LIBTRACE_FILE trace_open_file(libtrace_t *trace) 146 { 147 int fd; 148 LIBTRACE_FILE ret; 149 150 151 if (strcmp(trace->uridata,"-")==0) { 152 ret=LIBTRACE_FDOPEN(fileno(stdin),"r"); 153 return ret; 154 } 155 156 /* We open the file with open(2), so we can provide O_LARGEFILE 157 * as zlib doesn't always do it itself 158 */ 159 fd=open(trace->uridata,O_LARGEFILE); 160 if (fd==-1) { 161 trace_set_err(errno,"Unable to open %s",trace->uridata); 162 return 0; 163 } 164 ret=LIBTRACE_FDOPEN(fd,"r"); 165 return ret; 166 } -
lib/format_helper.h
r7068467 r3d4d52d 31 31 #ifndef FORMAT_HELPER_H 32 32 #define FORMAT_HELPER_H 33 #include "common.h" 33 34 34 int trace_read( structlibtrace_t *libtrace, void *buffer, size_t len);35 int trace_read(libtrace_t *libtrace, void *buffer, size_t len); 35 36 36 struct libtrace_eventobj_t trace_event_device(struct libtrace_t *trace, struct libtrace_packet_t *packet); 37 struct libtrace_eventobj_t trace_event_trace(struct libtrace_t *trace, struct libtrace_packet_t *packet); 37 struct libtrace_eventobj_t trace_event_device(libtrace_t *trace, libtrace_packet_t *packet); 38 struct libtrace_eventobj_t trace_event_trace(libtrace_t *trace, libtrace_packet_t *packet); 39 40 LIBTRACE_FILE trace_open_file(libtrace_t *libtrace); 38 41 #endif /* FORMAT_HELPER_H */ -
lib/format_legacy.c
rf03fc17 r3d4d52d 127 127 } 128 128 129 static int erf_init_input(struct libtrace_t *libtrace) { 130 struct stat buf; 131 struct sockaddr_un unix_sock; 129 static int erf_init_input(struct libtrace_t *libtrace) 130 { 132 131 libtrace->format_data = (struct libtrace_format_data_t *) 133 132 malloc(sizeof(struct libtrace_format_data_t)); 134 133 135 CONNINFO.path = libtrace->uridata; 136 if (!strncmp(CONNINFO.path,"-",1)) { 137 /* STDIN */ 138 INPUT.file = LIBTRACE_FDOPEN(fileno(stdin), "r"); 139 } else { 140 if (stat(CONNINFO.path,&buf) == -1 ) { 141 trace_set_err(errno,"stat(%s)",CONNINFO.path); 142 return 0; 143 } 144 if (S_ISSOCK(buf.st_mode)) { 145 if ((INPUT.fd = socket( 146 AF_UNIX, SOCK_STREAM, 0)) == -1) { 147 trace_set_err("socket(%s)",CONNINFO.path); 148 return 0; 149 } 150 unix_sock.sun_family = AF_UNIX; 151 bzero(unix_sock.sun_path,108); 152 snprintf(unix_sock.sun_path, 153 108,"%s" 154 ,CONNINFO.path); 155 156 if (connect(INPUT.fd, 157 (struct sockaddr *)&unix_sock, 158 sizeof(struct sockaddr)) == -1) { 159 trace_set_err("socket(%s)",CONNINFO.path); 160 return 0; 161 } 162 } else { 163 int fd; 164 165 /* we use an FDOPEN call to reopen an FD 166 // returned from open(), so that we can set 167 // O_LARGEFILE. This gets around gzopen not 168 // letting you do this... 169 */ 170 fd=open( CONNINFO.path, O_LARGEFILE); 171 if (fd==-1) { 172 trace_set_err(errno,"open(%s)",CONNINFO.path); 173 return 0; 174 } 175 INPUT.file = LIBTRACE_FDOPEN(fd,"r"); 176 } 177 } 178 return 1; 134 libtrace->format_data->input.file = trace_open_file(libtrace); 135 136 if (libtrace->format_data->input.file) 137 return 1; 138 139 return 0; 140 179 141 } 180 142 -
lib/format_pcap.c
rf03fc17 r3d4d52d 226 226 if (!OUTPUT.trace.pcap) { 227 227 OUTPUT.trace.pcap = (pcap_t *)pcap_open_dead( 228 linktype_to_dlt(trace_get_link_type(packet)),229 228 libtrace_to_pcap_dlt(trace_get_link_type(packet)), 229 65536); 230 230 OUTPUT.trace.dump = pcap_dump_open(OUTPUT.trace.pcap,CONNINFO.path); 231 231 fflush((FILE *)OUTPUT.trace.dump); -
lib/format_wag.c
rf03fc17 r3d4d52d 148 148 } 149 149 150 static int wtf_init_input(struct libtrace_t *libtrace) {151 150 static int wtf_init_input(struct libtrace_t *libtrace) 151 { 152 152 libtrace->format_data = (struct libtrace_format_data_t *) 153 calloc(1,sizeof(struct libtrace_format_data_t)); 154 CONNINFO.path = libtrace->uridata; 155 156 if (!strncmp(CONNINFO.path,"-",1)) { 157 /* STDIN */ 158 INPUT.file = LIBTRACE_FDOPEN(fileno(stdin),"r"); 159 } else { 160 int fd; 161 /* TRACE */ 162 163 /* we use an FDOPEN call to reopen an FD 164 * returned from open(), so that we can set 165 * O_LARGEFILE. This gets around gzopen not 166 * letting you do this... 167 */ 168 fd = open(CONNINFO.path, O_LARGEFILE); 169 if (fd==-1) { 170 trace_set_err(errno,"open(%s)",CONNINFO.path); 171 return 0; 172 } 173 INPUT.file = LIBTRACE_FDOPEN(fd, "r"); 174 175 } 176 return 1; 177 } 178 153 malloc(sizeof(struct libtrace_format_data_t)); 154 155 libtrace->format_data->input.file = trace_open_file(libtrace); 156 157 if (libtrace->format_data->input.file) 158 return 1; 159 160 return 0; 161 } 179 162 180 163 static int wtf_init_output(struct libtrace_out_t *libtrace) { … … 340 323 341 324 if ((numbytes = LIBTRACE_READ(INPUT.file, buffer, sizeof(struct frame_t))) == -1) { 342 libtrace_set_err(errno,"read(%s)",packet->trace->uridata);325 trace_set_err(errno,"read(%s)",packet->trace->uridata); 343 326 return -1; 344 327 } … … 355 338 356 339 if ((numbytes=LIBTRACE_READ(INPUT.file, buffer2, size)) != size) { 357 libtrace_set_err(errno,"read(%s)",packet->trace->uridata);340 trace_set_err(errno,"read(%s)",packet->trace->uridata); 358 341 return -1; 359 342 } … … 379 362 */ 380 363 if ((numbytes = LIBTRACE_WRITE(OUTPUT.file, packet->header, trace_get_framing_length(packet))) == -1) { 381 libtrace_set_err(errno,"write(%s)",packet->trace->uridata);364 trace_set_err(errno,"write(%s)",packet->trace->uridata); 382 365 return -1; 383 366 } 384 367 if ((numbytes = LIBTRACE_WRITE(OUTPUT.file, packet->payload, 385 368 packet->size - trace_get_framing_length(packet))) == 0) { 386 libtrace_set_err(errno,"write(%s)",packet->trace->uridata);369 trace_set_err(errno,"write(%s)",packet->trace->uridata); 387 370 return -1; 388 371 } -
lib/libtrace.h
r880aa58 r3d4d52d 879 879 */ 880 880 const char *trace_parse_uri(const char *uri, char **format); 881 882 /** libtrace error information */ 883 extern struct trace_err_t{ 884 int err_num; /**< error code */ 885 char problem[255]; /**< the format, uri etc that caused the error for reporting purposes */ 886 } trace_err; 881 887 #ifdef __cplusplus 882 888 } /* extern "C" */ -
lib/libtrace_int.h
rf03fc17 r3d4d52d 75 75 76 76 77 extern struct trace_err_t{78 int err_num; /* error code */79 char problem[255]; /* the format, uri etc that caused the error for reporting purposes */80 } trace_err;81 77 82 void trace_set_err or(int errcode,const char *msg,...);78 void trace_set_err(int errcode,const char *msg,...); 83 79 84 80 #define RP_BUFSIZE 65536 -
lib/trace.c
rf03fc17 r3d4d52d 51 51 #include <sys/stat.h> 52 52 #include <sys/types.h> 53 #include <stdarg.h> 53 54 54 55 #ifdef HAVE_LIMITS_H … … 1511 1512 * @param msg a plaintext error message 1512 1513 */ 1513 void trace_set_err or(int errcode,const char *msg,...)1514 void trace_set_err(int errcode,const char *msg,...) 1514 1515 { 1515 1516 va_list va; 1516 va_start( msg,va);1517 va_start(va,msg); 1517 1518 trace_err.err_num=errcode; 1518 1519 vsnprintf(trace_err.problem,sizeof(trace_err.problem),msg,va); 1519 va_end( );1520 } 1520 va_end(va); 1521 }
Note: See TracChangeset
for help on using the changeset viewer.