- Timestamp:
- 02/24/06 11:39:57 (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:
- c6a6c3a
- Parents:
- 913721f
- Location:
- lib
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/format_erf.c
rc1f2553 r0ea3526 151 151 struct stat buf; 152 152 if (stat(libtrace->uridata, &buf) == -1) { 153 trace_set_err( errno,"stat(%s)",libtrace->uridata);153 trace_set_err(libtrace,errno,"stat(%s)",libtrace->uridata); 154 154 return 0; 155 155 } … … 157 157 /* DEVICE */ 158 158 if((INPUT.fd = dag_open(libtrace->uridata)) < 0) { 159 trace_set_err( errno,"Cannot open DAG %s",159 trace_set_err(libtrace,errno,"Cannot open DAG %s", 160 160 libtrace->uridata); 161 161 return 0; 162 162 } 163 163 if((DAG.buf = (void *)dag_mmap(INPUT.fd)) == MAP_FAILED) { 164 trace_set_err( errno,"Cannot mmap DAG %s",164 trace_set_err(libtrace,errno,"Cannot mmap DAG %s", 165 165 libtrace->uridata); 166 166 return 0; 167 167 } 168 168 if(dag_start(INPUT.fd) < 0) { 169 trace_set_err( errno,"Cannot start DAG %s",169 trace_set_err(libtrace,errno,"Cannot start DAG %s", 170 170 libtrace->uridata); 171 171 return 0; 172 172 } 173 173 } else { 174 trace_set_err( errno,"Not a valid dag device: %s",174 trace_set_err(libtrace,errno,"Not a valid dag device: %s", 175 175 libtrace->uridata); 176 176 return 0; … … 244 244 245 245 if ((he=gethostbyname(CONNINFO.rt.hostname)) == NULL) { 246 trace_set_err( errno,"failed to resolve %s",246 trace_set_err(libtrace,errno,"failed to resolve %s", 247 247 CONNINFO.rt.hostname); 248 248 return 0; 249 249 } 250 250 if ((INPUT.fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) { 251 trace_set_err( errno,"socket(AF_INET,SOCK_STREAM)");251 trace_set_err(libtrace,errno,"socket(AF_INET,SOCK_STREAM)"); 252 252 return 0; 253 253 } … … 260 260 if (connect(INPUT.fd, (struct sockaddr *)&remote, 261 261 sizeof(struct sockaddr)) == -1) { 262 trace_set_err( errno,"connect(%s)",262 trace_set_err(libtrace,errno,"connect(%s)", 263 263 CONNINFO.rt.hostname); 264 264 return 0; … … 289 289 default: 290 290 /* Unknown option */ 291 trace_set_err (TRACE_ERR_UNKNOWN_OPTION,291 trace_set_err_out(libtrace,TRACE_ERR_UNKNOWN_OPTION, 292 292 "Unknown option"); 293 293 return -1; … … 406 406 packet->buffer, 407 407 dag_record_size)) == -1) { 408 trace_set_err( errno,"read(%s)",408 trace_set_err(libtrace,errno,"read(%s)", 409 409 libtrace->uridata); 410 410 return -1; … … 427 427 buffer2, 428 428 size)) != size) { 429 trace_set_err( errno, "read(%s)", libtrace->uridata);429 trace_set_err(libtrace,errno, "read(%s)", libtrace->uridata); 430 430 return -1; 431 431 } … … 455 455 continue; 456 456 } 457 trace_set_err( errno,"recv(%s)",457 trace_set_err(libtrace,errno,"recv(%s)", 458 458 libtrace->uridata); 459 459 return -1; … … 548 548 /* FIXME: Shouldn't this return != dag_record_size+pad on error? */ 549 549 if ((numbytes = LIBTRACE_WRITE(OUTPUT.file, erfptr, dag_record_size + pad)) == 0) { 550 trace_set_err(errno,"write(%s)",libtrace->uridata); 550 trace_set_err_out(libtrace,errno, 551 "write(%s)",libtrace->uridata); 551 552 return -1; 552 553 } 553 554 554 555 if ((numbytes=LIBTRACE_WRITE(OUTPUT.file, buffer, size)) == 0) { 555 trace_set_err(errno,"write(%s)",libtrace->uridata); 556 trace_set_err_out(libtrace,errno, 557 "write(%s)",libtrace->uridata); 556 558 return -1; 557 559 } -
lib/format_helper.c
r9836f12 r0ea3526 47 47 #include <sys/ioctl.h> 48 48 #include <assert.h> 49 #include <stdarg.h> 49 50 50 51 struct libtrace_eventobj_t trace_event_device(struct libtrace_t *trace, struct libtrace_packet_t *packet) { … … 166 167 fd=open(trace->uridata,O_LARGEFILE); 167 168 if (fd==-1) { 168 trace_set_err( errno,"Unable to open %s",trace->uridata);169 trace_set_err(trace,errno,"Unable to open %s",trace->uridata); 169 170 return 0; 170 171 } … … 199 200 fd=open(trace->uridata,fileflag,0666); 200 201 if (fd==-1) { 201 trace_set_err(errno,"Unable to open %s",trace->uridata); 202 trace_set_err_out(trace, 203 errno,"Unable to open %s",trace->uridata); 202 204 return 0; 203 205 } … … 205 207 if (ret==NULL) { 206 208 printf("%s\n",filemode); 207 trace_set_err(TRACE_ERR_INIT_FAILED,"gz out of memory"); 209 trace_set_err_out(trace, 210 TRACE_ERR_INIT_FAILED,"gz out of memory"); 208 211 } 209 212 return ret; … … 211 214 212 215 213 216 /** Update the libtrace error 217 * @param errcode either an Econstant from libc, or a LIBTRACE_ERROR 218 * @param msg a plaintext error message 219 * @internal 220 */ 221 void trace_set_err(libtrace_t *trace,int errcode,const char *msg,...) 222 { 223 char buf[256]; 224 va_list va; 225 va_start(va,msg); 226 trace->err.err_num=errcode; 227 if (errcode>0) { 228 vsnprintf(buf,sizeof(buf),msg,va); 229 snprintf(trace->err.problem,sizeof(trace->err.problem), 230 "%s: %s",buf,strerror(errno)); 231 } else { 232 vsnprintf(trace->err.problem,sizeof(trace->err.problem), 233 msg,va); 234 } 235 va_end(va); 236 } 237 238 /** Update the libtrace for output traces error 239 * @param errcode either an Econstant from libc, or a LIBTRACE_ERROR 240 * @param msg a plaintext error message 241 * @internal 242 */ 243 void trace_set_err_out(libtrace_out_t *trace,int errcode,const char *msg,...) 244 { 245 char buf[256]; 246 va_list va; 247 va_start(va,msg); 248 trace->err.err_num=errcode; 249 if (errcode>0) { 250 vsnprintf(buf,sizeof(buf),msg,va); 251 snprintf(trace->err.problem,sizeof(trace->err.problem), 252 "%s: %s",buf,strerror(errno)); 253 } else { 254 vsnprintf(trace->err.problem,sizeof(trace->err.problem), 255 msg,va); 256 } 257 va_end(va); 258 } 259 -
lib/format_legacy.c
rd3b2234 r0ea3526 159 159 buffer, 160 160 64)) == -1) { 161 trace_set_err( errno,"read(%s)",libtrace->uridata);161 trace_set_err(libtrace,errno,"read(%s)",libtrace->uridata); 162 162 return -1; 163 163 } -
lib/format_pcap.c
r9836f12 r0ea3526 119 119 pcap_open_offline(libtrace->uridata, 120 120 errbuf)) == NULL) { 121 trace_set_err( TRACE_ERR_INIT_FAILED,"%s",121 trace_set_err(libtrace,TRACE_ERR_INIT_FAILED,"%s", 122 122 errbuf); 123 123 return -1; … … 127 127 if (pcap_setfilter(INPUT.pcap,&DATA(libtrace)->filter->filter) 128 128 == -1) { 129 trace_set_err( TRACE_ERR_INIT_FAILED,"%s",129 trace_set_err(libtrace,TRACE_ERR_INIT_FAILED,"%s", 130 130 pcap_geterr(INPUT.pcap)); 131 131 return -1; … … 150 150 /* can't do promisc on a trace! fall thru */ 151 151 default: 152 trace_set_err( TRACE_ERR_UNKNOWN_OPTION,152 trace_set_err(libtrace,TRACE_ERR_UNKNOWN_OPTION, 153 153 "Unknown option %i", option); 154 154 return -1; … … 194 194 return 0; 195 195 default: 196 trace_set_err( TRACE_ERR_UNKNOWN_OPTION,196 trace_set_err(libtrace,TRACE_ERR_UNKNOWN_OPTION, 197 197 "Unknown option %i", option); 198 198 return -1; … … 209 209 1, 210 210 errbuf)) == NULL) { 211 trace_set_err( TRACE_ERR_INIT_FAILED,"%s",errbuf);211 trace_set_err(libtrace,TRACE_ERR_INIT_FAILED,"%s",errbuf); 212 212 return -1; 213 213 } … … 216 216 if (pcap_setfilter(INPUT.pcap,&DATA(libtrace)->filter->filter) 217 217 == -1) { 218 trace_set_err( TRACE_ERR_INIT_FAILED,"%s",218 trace_set_err(libtrace,TRACE_ERR_INIT_FAILED,"%s", 219 219 pcap_geterr(INPUT.pcap)); 220 220 return -1; … … 225 225 } 226 226 227 static int pcapint_init_output(struct libtrace_out_t *libtrace __attribute__((unused))) { 228 trace_set_err(TRACE_ERR_NO_INIT_OUT,"Writing to a pcap interface not implemented yet"); 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"); 229 230 return -1; 230 231 } … … 329 330 } 330 331 331 static int8_t pcap_get_direction(const structlibtrace_packet_t *packet) {332 static int8_t pcap_get_direction(const libtrace_packet_t *packet) { 332 333 int8_t direction = -1; 333 334 switch(pcap_get_link_type(packet)) { … … 337 338 sll = trace_get_link(packet); 338 339 if (!sll) { 339 trace_set_err(TRACE_ERR_BAD_PACKET, 340 trace_set_err(packet->trace, 341 TRACE_ERR_BAD_PACKET, 340 342 "Bad or missing packet"); 341 343 return -1; … … 365 367 pflog = trace_get_link(packet); 366 368 if (!pflog) { 367 trace_set_err(TRACE_ERR_BAD_PACKET, 369 trace_set_err(packet->trace, 370 TRACE_ERR_BAD_PACKET, 368 371 "Bad or missing packet"); 369 372 return -1; -
lib/format_wag.c
rc1f2553 r0ea3526 124 124 125 125 if (stat(libtrace->uridata,&buf) == -1 ) { 126 trace_set_err( errno,"stat(%s)",libtrace->uridata);126 trace_set_err(libtrace,errno,"stat(%s)",libtrace->uridata); 127 127 return 0; 128 128 } … … 132 132 133 133 } else { 134 trace_set_err( TRACE_ERR_INIT_FAILED,134 trace_set_err(libtrace,TRACE_ERR_INIT_FAILED, 135 135 "%s is not a valid char device", 136 136 libtrace->uridata); … … 193 193 case TRACE_OPTION_OUTPUT_COMPRESS: 194 194 /* E feature unavailable */ 195 trace_set_err (TRACE_ERR_OPTION_UNAVAIL,195 trace_set_err_out(libtrace,TRACE_ERR_OPTION_UNAVAIL, 196 196 "zlib not supported"); 197 197 return -1; … … 199 199 default: 200 200 /* E unknown feature */ 201 trace_set_err (TRACE_ERR_UNKNOWN_OPTION,201 trace_set_err_out(libtrace,TRACE_ERR_UNKNOWN_OPTION, 202 202 "Unknown option"); 203 203 return -1; … … 242 242 continue; 243 243 244 trace_set_err( errno,"read(%s)",libtrace->uridata);244 trace_set_err(libtrace,errno,"read(%s)",libtrace->uridata); 245 245 return -1; 246 246 } … … 257 257 258 258 if (magic != 0xdaa1) { 259 trace_set_err(TRACE_ERR_BAD_PACKET,"magic number bad or missing"); 259 trace_set_err(libtrace, 260 TRACE_ERR_BAD_PACKET,"magic number bad or missing"); 260 261 return -1; 261 262 } … … 273 274 if (errno == EINTR || errno==EAGAIN) 274 275 continue; 275 trace_set_err( errno,"read(%s)",libtrace->uridata);276 trace_set_err(libtrace,errno,"read(%s)",libtrace->uridata); 276 277 return -1; 277 278 } … … 321 322 322 323 if ((numbytes = LIBTRACE_READ(INPUT.file, buffer, sizeof(struct frame_t))) == -1) { 323 trace_set_err(errno,"read(%s,frame_t)",packet->trace->uridata); 324 trace_set_err(libtrace,errno, 325 "read(%s,frame_t)",packet->trace->uridata); 324 326 return -1; 325 327 } … … 330 332 331 333 if (htons(((struct frame_t *)buffer)->magic) != 0xdaa1) { 332 trace_set_err(TRACE_ERR_BAD_PACKET,"Insufficient magic"); 334 trace_set_err(libtrace, 335 TRACE_ERR_BAD_PACKET,"Insufficient magic"); 333 336 return -1; 334 337 } … … 341 344 342 345 if ((numbytes=LIBTRACE_READ(INPUT.file, buffer2, size)) != size) { 343 trace_set_err(errno,"read(%s,buffer)",packet->trace->uridata); 346 trace_set_err(libtrace, 347 errno,"read(%s,buffer)",packet->trace->uridata); 344 348 return -1; 345 349 } … … 354 358 int numbytes =0 ; 355 359 if (packet->trace->format != &wag_trace) { 356 trace_set_err (TRACE_ERR_NO_CONVERSION,360 trace_set_err_out(libtrace,TRACE_ERR_NO_CONVERSION, 357 361 "Cannot convert from wag trace format to %s format yet", 358 362 packet->trace->format->name); … … 365 369 if ((numbytes = LIBTRACE_WRITE(OUTPUT.file, packet->header, 366 370 trace_get_framing_length(packet))) == -1) { 367 trace_set_err(errno,"write(%s)",packet->trace->uridata); 371 trace_set_err_out(libtrace,errno, 372 "write(%s)",packet->trace->uridata); 368 373 return -1; 369 374 } 370 375 if ((numbytes = LIBTRACE_WRITE(OUTPUT.file, packet->payload, 371 376 trace_get_capture_length(packet)) == -1)) { 372 trace_set_err(errno,"write(%s)",packet->trace->uridata); 377 trace_set_err_out(libtrace, 378 errno,"write(%s)",packet->trace->uridata); 373 379 return -1; 374 380 } -
lib/libtrace.h
rd3b2234 r0ea3526 105 105 uint8_t type; /**< rt protocol type for the packet */ 106 106 } libtrace_packet_t; 107 107 108 /** libtrace error information */ 109 typedef struct trace_err_t{ 110 int err_num; /**< error code */ 111 char problem[255]; /**< the format, uri etc that caused the error for reporting purposes */ 112 } libtrace_err_t; 108 113 109 114 /** Enumeration of error codes */ … … 433 438 434 439 /** Close a trace output file, freeing up any resources it may have been using 435 *436 440 * @param trace the output trace file to be destroyed 437 441 * … … 439 443 */ 440 444 void trace_destroy_output(libtrace_out_t *trace); 445 446 /** Check (and clear) the current error state of an input trace 447 * @param trace the trace file to check the error state on 448 * @return Error report 449 * This reads and returns the current error state and sets the current error 450 * to "no error". 451 */ 452 libtrace_err_t trace_get_err(libtrace_t *trace); 453 454 /** Check (and clear) the current error state of an output trace 455 * @param trace the output trace file to check the error state on 456 * @return Error report 457 * This reads and returns the current error state and sets the current error 458 * to "no error". 459 */ 460 libtrace_err_t trace_get_err_output(libtrace_out_t *trace); 441 461 442 462 /*@}*/ … … 925 945 926 946 927 /** libtrace error information */928 extern struct trace_err_t{929 int err_num; /**< error code */930 char problem[255]; /**< the format, uri etc that caused the error for reporting purposes */931 } trace_err;932 947 #ifdef __cplusplus 933 948 } /* extern "C" */ -
lib/libtrace_int.h
rc1f2553 r0ea3526 74 74 75 75 76 void trace_set_err(int errcode,const char *msg,...);77 76 78 77 #define RP_BUFSIZE 65536 … … 96 95 struct libtrace_format_data_t *format_data; /**<format data pointer */ 97 96 bool started; 98 97 libtrace_err_t err; 99 98 struct libtrace_event_t event; 100 99 char *uridata; … … 111 110 struct libtrace_format_t *format; 112 111 struct libtrace_format_data_out_t *format_data; 113 112 bool started; 113 libtrace_err_t err; 114 114 char *uridata; 115 115 struct tracefifo_t *fifo; 116 bool started; 117 }; 118 116 }; 117 118 void trace_set_err(libtrace_t *trace, int errcode,const char *msg,...); 119 void trace_set_err_out(libtrace_out_t *trace, int errcode, const char *msg,...); 119 120 120 121 struct trace_sll_header_t { -
lib/trace.c
rd3b2234 r0ea3526 223 223 224 224 trace_err.err_num = TRACE_ERR_NOERROR; 225 libtrace->format=NULL; 225 226 226 227 /* parse the URI to determine what sort of event we are dealing with */ 227 228 if ((uridata = trace_parse_uri(uri, &scan)) == 0) { 228 return 0; 229 trace_set_err(libtrace,TRACE_ERR_BAD_FORMAT,"Bad uri format"); 230 return libtrace; 229 231 } 230 232 … … 233 235 libtrace->snaplen = 0; 234 236 235 libtrace->format = 0;236 237 for (i = 0; i < nformats; i++) { 237 238 if (strlen(scan) == strlen(format_list[i]->name) && … … 244 245 } 245 246 if (libtrace->format == 0) { 246 trace_set_err( TRACE_ERR_BAD_FORMAT,247 trace_set_err(libtrace, TRACE_ERR_BAD_FORMAT, 247 248 "Unknown format (%s)",scan); 248 249 return 0; … … 255 256 256 257 if (libtrace->format->init_input) { 257 if (!libtrace->format->init_input( 258 if (!libtrace->format->init_input(libtrace)) { 258 259 /* init_input should call trace_set_err to set 259 260 * the error message 260 261 */ 261 return 0;262 return libtrace; 262 263 } 263 264 } else { 264 trace_set_err( TRACE_ERR_NO_INIT,265 trace_set_err(libtrace,TRACE_ERR_NO_INIT, 265 266 "Format does not support input (%s)",scan); 266 return 0;267 return libtrace; 267 268 } 268 269 269 270 270 271 libtrace->fifo = create_tracefifo(1048576); 271 assert( 272 assert(libtrace->fifo); 272 273 free(scan); 273 274 libtrace->started=false; 275 trace_set_err(libtrace,0,""); 274 276 return libtrace; 275 277 } … … 309 311 } 310 312 if (libtrace->format == 0) { 311 trace_set_err( TRACE_ERR_BAD_FORMAT,313 trace_set_err(libtrace,TRACE_ERR_BAD_FORMAT, 312 314 "Unknown format (%s)",scan); 313 315 return 0; … … 323 325 * @param uri the uri string describing the output format and destination 324 326 * @returns opaque pointer to a libtrace_output_t 325 * @author Shane Alcock326 *327 * Valid URI's are: - gzerf:/path/to/erf/file.gz - gzerf:/path/to/erf/file -328 * rtserver:hostname - rtserver:hostname:port329 327 * 330 328 * If an error occured when attempting to open the output trace, NULL is … … 343 341 344 342 if ((uridata = trace_parse_uri(uri, &scan)) == 0) { 345 return 0; 343 trace_set_err_out(libtrace,TRACE_ERR_BAD_FORMAT,"Bad uri format"); 344 return libtrace; 346 345 } 347 346 … … 358 357 } 359 358 if (libtrace->format == 0) { 360 trace_set_err (TRACE_ERR_BAD_FORMAT,359 trace_set_err_out(libtrace,TRACE_ERR_BAD_FORMAT, 361 360 "Unknown output format (%s)",scan); 362 361 return 0; … … 381 380 } 382 381 } else { 383 trace_set_err (TRACE_ERR_NO_INIT_OUT,382 trace_set_err_out(libtrace,TRACE_ERR_NO_INIT_OUT, 384 383 "Format does not support writing (%s)",scan); 385 free(libtrace); 386 return 0; 384 return libtrace; 387 385 } 388 386 … … 458 456 break; 459 457 case TRACE_OPTION_PROMISC: 460 trace_set_err( TRACE_ERR_OPTION_UNAVAIL,458 trace_set_err(libtrace,TRACE_ERR_OPTION_UNAVAIL, 461 459 "Promisc mode is not supported by this format module"); 462 460 return -1; 463 461 default: 464 trace_set_err( TRACE_ERR_UNKNOWN_OPTION,462 trace_set_err(libtrace,TRACE_ERR_UNKNOWN_OPTION, 465 463 "Unknown option %i", option); 466 464 return -1; … … 1291 1289 linkptr = trace_get_link(packet); 1292 1290 if (!linkptr) { 1293 trace_set_err(TRACE_ERR_BAD_PACKET,"Packet has no payload"); 1291 trace_set_err(packet->trace, 1292 TRACE_ERR_BAD_PACKET,"Packet has no payload"); 1294 1293 return -1; 1295 1294 } … … 1304 1303 1, 0)) { 1305 1304 pcap_close(pcap); 1306 trace_set_err( TRACE_ERR_BAD_PACKET,1305 trace_set_err(packet->trace,TRACE_ERR_BAD_PACKET, 1307 1306 "Packet has no payload"); 1308 1307 return -1; … … 1563 1562 if((uridata = strchr(uri,':')) == NULL) { 1564 1563 /* badly formed URI - needs a : */ 1565 trace_set_err(TRACE_ERR_URI_NOCOLON,"Format missing");1566 1564 return 0; 1567 1565 } … … 1569 1567 if ((uridata - uri) > URI_PROTO_LINE) { 1570 1568 /* badly formed URI - uri type is too long */ 1571 trace_set_err(TRACE_ERR_URI_LONG,"Format too long");1572 1569 return 0; 1573 1570 } … … 1581 1578 } 1582 1579 1583 enum base_format_t trace_get_format(struct libtrace_packet_t *packet) { 1580 enum base_format_t trace_get_format(struct libtrace_packet_t *packet) 1581 { 1584 1582 assert(packet); 1585 1583 … … 1587 1585 } 1588 1586 1589 /** Update the libtrace error 1590 * @param errcode either an Econstant from libc, or a LIBTRACE_ERROR 1591 * @param msg a plaintext error message 1592 * @internal 1593 */ 1594 void trace_set_err(int errcode,const char *msg,...) 1587 libtrace_err_t trace_get_err(libtrace_t *trace) 1595 1588 { 1596 char buf[256];1597 va_list va;1598 va_start(va,msg);1599 trace_err.err_num=errcode;1600 if (errcode>0) { 1601 vsnprintf(buf,sizeof(buf),msg,va); 1602 snprintf(trace_err.problem,sizeof(trace_err.problem), 1603 "%s: %s",buf,strerror(errno)); 1604 } else {1605 vsnprintf(trace_err.problem,sizeof(trace_err.problem),msg,va);1606 }1607 va_end(va);1608 } 1589 libtrace_err_t err = trace->err; 1590 trace->err.err_num = 0; /* "OK" */ 1591 trace->err.problem[0]='\0'; 1592 return err; 1593 } 1594 1595 libtrace_err_t trace_get_err_output(libtrace_out_t *trace) 1596 { 1597 libtrace_err_t err = trace->err; 1598 trace->err.err_num = 0; /* "OK" */ 1599 trace->err.problem[0]='\0'; 1600 return err; 1601 }
Note: See TracChangeset
for help on using the changeset viewer.