1 | /* |
---|
2 | * This file is part of libtrace |
---|
3 | * |
---|
4 | * Copyright (c) 2004 The University of Waikato, Hamilton, New Zealand. |
---|
5 | * Authors: Daniel Lawson |
---|
6 | * Perry Lorier |
---|
7 | * |
---|
8 | * All rights reserved. |
---|
9 | * |
---|
10 | * This code has been developed by the University of Waikato WAND |
---|
11 | * research group. For further information please see http://www.wand.net.nz/ |
---|
12 | * |
---|
13 | * libtrace is free software; you can redistribute it and/or modify |
---|
14 | * it under the terms of the GNU General Public License as published by |
---|
15 | * the Free Software Foundation; either version 2 of the License, or |
---|
16 | * (at your option) any later version. |
---|
17 | * |
---|
18 | * libtrace is distributed in the hope that it will be useful, |
---|
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
21 | * GNU General Public License for more details. |
---|
22 | * |
---|
23 | * You should have received a copy of the GNU General Public License |
---|
24 | * along with libtrace; if not, write to the Free Software |
---|
25 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
26 | * |
---|
27 | * $Id$ |
---|
28 | * |
---|
29 | */ |
---|
30 | |
---|
31 | |
---|
32 | /* @file |
---|
33 | * |
---|
34 | * @brief Trace file processing library |
---|
35 | * |
---|
36 | * @author Daniel Lawson |
---|
37 | * @author Perry Lorier |
---|
38 | * |
---|
39 | * @internal |
---|
40 | */ |
---|
41 | #define _GNU_SOURCE |
---|
42 | #include "common.h" |
---|
43 | #include "config.h" |
---|
44 | #include <assert.h> |
---|
45 | #include <errno.h> |
---|
46 | #include <fcntl.h> |
---|
47 | #include <netdb.h> |
---|
48 | #include <stdio.h> |
---|
49 | #include <stdlib.h> |
---|
50 | #include <string.h> |
---|
51 | #include <sys/stat.h> |
---|
52 | #include <sys/types.h> |
---|
53 | #include <stdarg.h> |
---|
54 | |
---|
55 | #ifdef HAVE_LIMITS_H |
---|
56 | # include <limits.h> |
---|
57 | #endif |
---|
58 | |
---|
59 | #ifdef HAVE_SYS_LIMITS_H |
---|
60 | # include <sys/limits.h> |
---|
61 | #endif |
---|
62 | |
---|
63 | #include <sys/socket.h> |
---|
64 | #include <sys/un.h> |
---|
65 | #include <sys/mman.h> |
---|
66 | #include <unistd.h> |
---|
67 | |
---|
68 | #ifdef HAVE_NET_IF_ARP_H |
---|
69 | # include <net/if_arp.h> |
---|
70 | #endif |
---|
71 | |
---|
72 | #ifdef HAVE_NET_IF_H |
---|
73 | # include <net/if.h> |
---|
74 | #endif |
---|
75 | |
---|
76 | #ifdef HAVE_NETINET_IN_H |
---|
77 | # include <netinet/in.h> |
---|
78 | #endif |
---|
79 | |
---|
80 | #ifdef HAVE_NET_ETHERNET_H |
---|
81 | # include <net/ethernet.h> |
---|
82 | #endif |
---|
83 | |
---|
84 | #ifdef HAVE_NETINET_IF_ETHER_H |
---|
85 | # include <netinet/if_ether.h> |
---|
86 | #endif |
---|
87 | |
---|
88 | #include <time.h> |
---|
89 | #include <sys/ioctl.h> |
---|
90 | |
---|
91 | #ifdef HAVE_INTTYPES_H |
---|
92 | # include <inttypes.h> |
---|
93 | #else |
---|
94 | # error "Can't find inttypes.h - this needs to be fixed" |
---|
95 | #endif |
---|
96 | |
---|
97 | #ifdef HAVE_STDDEF_H |
---|
98 | # include <stddef.h> |
---|
99 | #else |
---|
100 | # error "Can't find stddef.h - do you define ptrdiff_t elsewhere?" |
---|
101 | #endif |
---|
102 | |
---|
103 | #include "libtrace.h" |
---|
104 | #include "fifo.h" |
---|
105 | #include "libtrace_int.h" |
---|
106 | #include "parse_cmd.h" |
---|
107 | |
---|
108 | #if HAVE_PCAP_BPF_H |
---|
109 | # include <pcap-bpf.h> |
---|
110 | #else |
---|
111 | # ifdef HAVE_NET_BPF_H |
---|
112 | # include <net/bpf.h> |
---|
113 | # endif |
---|
114 | #endif |
---|
115 | |
---|
116 | #include "libtrace_int.h" |
---|
117 | #include "format_helper.h" |
---|
118 | #include "rt_protocol.h" |
---|
119 | #include <err.h> |
---|
120 | |
---|
121 | #define MAXOPTS 1024 |
---|
122 | |
---|
123 | |
---|
124 | struct trace_err_t trace_err; |
---|
125 | |
---|
126 | struct libtrace_format_t **format_list = 0; |
---|
127 | int format_size = 0; |
---|
128 | int nformats = 0; |
---|
129 | |
---|
130 | /* strncpy is not assured to copy the final \0, so we |
---|
131 | * will use our own one that does |
---|
132 | */ |
---|
133 | static void xstrncpy(char *dest, const char *src, size_t n) |
---|
134 | { |
---|
135 | strncpy(dest,src,n); |
---|
136 | dest[n]='\0'; |
---|
137 | } |
---|
138 | |
---|
139 | static char *xstrndup(const char *src,size_t n) |
---|
140 | { |
---|
141 | char *ret=malloc(n+1); |
---|
142 | xstrncpy(ret,src,n); |
---|
143 | return ret; |
---|
144 | } |
---|
145 | |
---|
146 | void register_format(struct libtrace_format_t *f) { |
---|
147 | if (format_list == 0) { |
---|
148 | format_size = 10; |
---|
149 | format_list = malloc( |
---|
150 | sizeof(struct libtrace_format_t *) * |
---|
151 | format_size |
---|
152 | ); |
---|
153 | } else if (format_size == nformats) { |
---|
154 | format_size = format_size + 10; |
---|
155 | format_list = realloc(format_list, |
---|
156 | sizeof(struct libtrace_format_t *) * |
---|
157 | format_size); |
---|
158 | } |
---|
159 | format_list[nformats] = f; |
---|
160 | nformats++; |
---|
161 | } |
---|
162 | |
---|
163 | /* Prints help information for libtrace |
---|
164 | * |
---|
165 | * Function prints out some basic help information regarding libtrace, |
---|
166 | * and then prints out the help() function registered with each input module |
---|
167 | */ |
---|
168 | void trace_help() { |
---|
169 | int i = 0; |
---|
170 | printf("libtrace %s\n",PACKAGE_VERSION); |
---|
171 | for (i = 0; i < nformats; i++) { |
---|
172 | if (format_list[i]->help) { |
---|
173 | format_list[i]->help(); |
---|
174 | } |
---|
175 | } |
---|
176 | } |
---|
177 | |
---|
178 | #define RP_BUFSIZE 65536 |
---|
179 | #define URI_PROTO_LINE 16 |
---|
180 | |
---|
181 | /* Gets the name of the output format for a given output trace. |
---|
182 | * |
---|
183 | * @params libtrace the output trace to get the name of the format for |
---|
184 | * @returns callee-owned null-terminated char* containing the output format |
---|
185 | * |
---|
186 | */ |
---|
187 | SIMPLE_FUNCTION |
---|
188 | char *trace_get_output_format(const struct libtrace_out_t *libtrace) { |
---|
189 | char * format = libtrace->format->name; |
---|
190 | |
---|
191 | return format; |
---|
192 | } |
---|
193 | |
---|
194 | /* Create a trace file from a URI |
---|
195 | * |
---|
196 | * @params char * containing a valid libtrace URI |
---|
197 | * @returns opaque pointer to a libtrace_t |
---|
198 | * |
---|
199 | * Valid URI's are: |
---|
200 | * erf:/path/to/erf/file |
---|
201 | * erf:/path/to/erf/file.gz |
---|
202 | * erf:/path/to/rtclient/socket |
---|
203 | * erf:- (stdin) |
---|
204 | * dag:/dev/dagcard |
---|
205 | * pcapint:pcapinterface (eg: pcapint:eth0) |
---|
206 | * pcap:/path/to/pcap/file |
---|
207 | * pcap:- |
---|
208 | * rtclient:hostname |
---|
209 | * rtclient:hostname:port |
---|
210 | * wag:- |
---|
211 | * wag:/path/to/wag/file |
---|
212 | * wag:/path/to/wag/file.gz |
---|
213 | * wag:/path/to/wag/socket |
---|
214 | * |
---|
215 | * If an error occured when attempting to open a trace, NULL is returned |
---|
216 | * and an error is output to stdout. |
---|
217 | */ |
---|
218 | struct libtrace_t *trace_create(const char *uri) { |
---|
219 | struct libtrace_t *libtrace = malloc(sizeof(struct libtrace_t)); |
---|
220 | char *scan = 0; |
---|
221 | const char *uridata = 0; |
---|
222 | int i = 0; |
---|
223 | |
---|
224 | trace_err.err_num = TRACE_ERR_NOERROR; |
---|
225 | libtrace->format=NULL; |
---|
226 | |
---|
227 | /* parse the URI to determine what sort of event we are dealing with */ |
---|
228 | if ((uridata = trace_parse_uri(uri, &scan)) == 0) { |
---|
229 | trace_set_err(libtrace,TRACE_ERR_BAD_FORMAT,"Bad uri format"); |
---|
230 | return libtrace; |
---|
231 | } |
---|
232 | |
---|
233 | libtrace->event.tdelta = 0.0; |
---|
234 | libtrace->filter = NULL; |
---|
235 | libtrace->snaplen = 0; |
---|
236 | |
---|
237 | for (i = 0; i < nformats; i++) { |
---|
238 | if (strlen(scan) == strlen(format_list[i]->name) && |
---|
239 | strncasecmp(scan, |
---|
240 | format_list[i]->name, |
---|
241 | strlen(scan)) == 0) { |
---|
242 | libtrace->format=format_list[i]; |
---|
243 | break; |
---|
244 | } |
---|
245 | } |
---|
246 | if (libtrace->format == 0) { |
---|
247 | trace_set_err(libtrace, TRACE_ERR_BAD_FORMAT, |
---|
248 | "Unknown format (%s)",scan); |
---|
249 | return 0; |
---|
250 | } |
---|
251 | |
---|
252 | libtrace->uridata = strdup(uridata); |
---|
253 | /* libtrace->format now contains the type of uri |
---|
254 | * libtrace->uridata contains the appropriate data for this |
---|
255 | */ |
---|
256 | |
---|
257 | if (libtrace->format->init_input) { |
---|
258 | if (!libtrace->format->init_input(libtrace)) { |
---|
259 | /* init_input should call trace_set_err to set |
---|
260 | * the error message |
---|
261 | */ |
---|
262 | return libtrace; |
---|
263 | } |
---|
264 | } else { |
---|
265 | trace_set_err(libtrace,TRACE_ERR_NO_INIT, |
---|
266 | "Format does not support input (%s)",scan); |
---|
267 | return libtrace; |
---|
268 | } |
---|
269 | |
---|
270 | |
---|
271 | libtrace->fifo = create_tracefifo(1048576); |
---|
272 | assert(libtrace->fifo); |
---|
273 | free(scan); |
---|
274 | libtrace->started=false; |
---|
275 | trace_set_err(libtrace,0,""); |
---|
276 | return libtrace; |
---|
277 | } |
---|
278 | |
---|
279 | /* Creates a "dummy" trace file that has only the format type set. |
---|
280 | * |
---|
281 | * @returns opaque pointer to a (sparsely initialised) libtrace_t |
---|
282 | * |
---|
283 | * IMPORTANT: Do not attempt to call trace_read_packet or other such functions |
---|
284 | * with the dummy trace. Its intended purpose is to act as a packet->trace for |
---|
285 | * libtrace_packet_t's that are not associated with a libtrace_t structure. |
---|
286 | */ |
---|
287 | struct libtrace_t * trace_create_dead (const char *uri) { |
---|
288 | struct libtrace_t *libtrace = malloc(sizeof(struct libtrace_t)); |
---|
289 | char *scan = calloc(sizeof(char),URI_PROTO_LINE); |
---|
290 | char *uridata; |
---|
291 | int i; |
---|
292 | |
---|
293 | trace_err.err_num = TRACE_ERR_NOERROR; |
---|
294 | |
---|
295 | if((uridata = strchr(uri,':')) == NULL) { |
---|
296 | xstrncpy(scan, uri, strlen(uri)); |
---|
297 | } else { |
---|
298 | xstrncpy(scan,uri, (uridata - uri)); |
---|
299 | } |
---|
300 | |
---|
301 | libtrace->format = 0; |
---|
302 | |
---|
303 | for (i = 0; i < nformats; i++) { |
---|
304 | if (strlen(scan) == strlen(format_list[i]->name) && |
---|
305 | !strncasecmp(scan, |
---|
306 | format_list[i]->name, |
---|
307 | strlen(scan))) { |
---|
308 | libtrace->format=format_list[i]; |
---|
309 | break; |
---|
310 | } |
---|
311 | } |
---|
312 | if (libtrace->format == 0) { |
---|
313 | trace_set_err(libtrace,TRACE_ERR_BAD_FORMAT, |
---|
314 | "Unknown format (%s)",scan); |
---|
315 | return 0; |
---|
316 | } |
---|
317 | |
---|
318 | free(scan); |
---|
319 | return libtrace; |
---|
320 | |
---|
321 | } |
---|
322 | |
---|
323 | /* Creates a trace output file from a URI. |
---|
324 | * |
---|
325 | * @param uri the uri string describing the output format and destination |
---|
326 | * @returns opaque pointer to a libtrace_output_t |
---|
327 | * |
---|
328 | * If an error occured when attempting to open the output trace, NULL is |
---|
329 | * returned and trace_errno is set. |
---|
330 | */ |
---|
331 | |
---|
332 | libtrace_out_t *trace_create_output(const char *uri) { |
---|
333 | struct libtrace_out_t *libtrace = malloc(sizeof(struct libtrace_out_t)); |
---|
334 | |
---|
335 | char *scan = 0; |
---|
336 | const char *uridata = 0; |
---|
337 | int i; |
---|
338 | |
---|
339 | trace_err.err_num = TRACE_ERR_NOERROR; |
---|
340 | /* parse the URI to determine what sort of event we are dealing with */ |
---|
341 | |
---|
342 | if ((uridata = trace_parse_uri(uri, &scan)) == 0) { |
---|
343 | trace_set_err_out(libtrace,TRACE_ERR_BAD_FORMAT,"Bad uri format"); |
---|
344 | return libtrace; |
---|
345 | } |
---|
346 | |
---|
347 | |
---|
348 | libtrace->format = 0; |
---|
349 | for (i = 0; i < nformats; i++) { |
---|
350 | if (strlen(scan) == strlen(format_list[i]->name) && |
---|
351 | !strncasecmp(scan, |
---|
352 | format_list[i]->name, |
---|
353 | strlen(scan))) { |
---|
354 | libtrace->format=format_list[i]; |
---|
355 | break; |
---|
356 | } |
---|
357 | } |
---|
358 | if (libtrace->format == 0) { |
---|
359 | trace_set_err_out(libtrace,TRACE_ERR_BAD_FORMAT, |
---|
360 | "Unknown output format (%s)",scan); |
---|
361 | return 0; |
---|
362 | } |
---|
363 | libtrace->uridata = strdup(uridata); |
---|
364 | |
---|
365 | |
---|
366 | /* libtrace->format now contains the type of uri |
---|
367 | * libtrace->uridata contains the appropriate data for this |
---|
368 | */ |
---|
369 | |
---|
370 | if (libtrace->format->init_output) { |
---|
371 | /* 0 on success, -1 on failure */ |
---|
372 | switch(libtrace->format->init_output(libtrace)) { |
---|
373 | case -1: /* failure */ |
---|
374 | free(libtrace); |
---|
375 | return 0; |
---|
376 | case 0: /* success */ |
---|
377 | break; |
---|
378 | default: |
---|
379 | assert(!"init_output() should return -1 for failure, or 0 for success"); |
---|
380 | } |
---|
381 | } else { |
---|
382 | trace_set_err_out(libtrace,TRACE_ERR_NO_INIT_OUT, |
---|
383 | "Format does not support writing (%s)",scan); |
---|
384 | return libtrace; |
---|
385 | } |
---|
386 | |
---|
387 | |
---|
388 | free(scan); |
---|
389 | libtrace->started=false; |
---|
390 | return libtrace; |
---|
391 | } |
---|
392 | |
---|
393 | /* Start a trace |
---|
394 | * @param libtrace the input trace to start |
---|
395 | * @returns 0 on success |
---|
396 | * |
---|
397 | * This does the work associated with actually starting up |
---|
398 | * the trace. it may fail. |
---|
399 | */ |
---|
400 | int trace_start(struct libtrace_t *libtrace) |
---|
401 | { |
---|
402 | assert(libtrace); |
---|
403 | if (libtrace->format->start_input) { |
---|
404 | int ret=libtrace->format->start_input(libtrace); |
---|
405 | if (ret < 0) { |
---|
406 | return ret; |
---|
407 | } |
---|
408 | } |
---|
409 | |
---|
410 | libtrace->started=true; |
---|
411 | return 0; |
---|
412 | } |
---|
413 | |
---|
414 | int trace_start_output(libtrace_out_t *libtrace) |
---|
415 | { |
---|
416 | assert(libtrace); |
---|
417 | if (libtrace->format->start_output) { |
---|
418 | int ret=libtrace->format->start_output(libtrace); |
---|
419 | if (ret < 0) { |
---|
420 | return ret; |
---|
421 | } |
---|
422 | } |
---|
423 | |
---|
424 | libtrace->started=false; |
---|
425 | return 0; |
---|
426 | } |
---|
427 | |
---|
428 | int trace_pause(libtrace_t *libtrace) |
---|
429 | { |
---|
430 | assert(libtrace); |
---|
431 | assert(libtrace->started && "BUG: Called trace_pause without calling trace_start first"); |
---|
432 | if (libtrace->format->pause_input) |
---|
433 | libtrace->format->pause_input(libtrace); |
---|
434 | libtrace->started=false; |
---|
435 | return 0; |
---|
436 | } |
---|
437 | |
---|
438 | int trace_config(libtrace_t *libtrace, |
---|
439 | trace_option_t option, |
---|
440 | void *value) |
---|
441 | { |
---|
442 | int ret; |
---|
443 | if (libtrace->format->config_input) { |
---|
444 | ret=libtrace->format->config_input(libtrace,option,value); |
---|
445 | if (ret==0) |
---|
446 | return 0; |
---|
447 | } |
---|
448 | switch(option) { |
---|
449 | case TRACE_OPTION_SNAPLEN: |
---|
450 | libtrace->snaplen=*(int*)value; |
---|
451 | break; |
---|
452 | case TRACE_OPTION_FILTER: |
---|
453 | libtrace->filter=value; |
---|
454 | break; |
---|
455 | case TRACE_OPTION_PROMISC: |
---|
456 | trace_set_err(libtrace,TRACE_ERR_OPTION_UNAVAIL, |
---|
457 | "Promisc mode is not supported by this format module"); |
---|
458 | return -1; |
---|
459 | default: |
---|
460 | trace_set_err(libtrace,TRACE_ERR_UNKNOWN_OPTION, |
---|
461 | "Unknown option %i", option); |
---|
462 | return -1; |
---|
463 | } |
---|
464 | return 0; |
---|
465 | } |
---|
466 | |
---|
467 | /* Parses an output options string and calls the appropriate function to deal with output options. |
---|
468 | * |
---|
469 | * @param libtrace the output trace object to apply the options to |
---|
470 | * @param options the options string |
---|
471 | * @returns -1 if option configuration failed, 0 otherwise |
---|
472 | * |
---|
473 | * @author Shane Alcock |
---|
474 | */ |
---|
475 | int trace_config_output(struct libtrace_out_t *libtrace, |
---|
476 | trace_option_output_t option, |
---|
477 | void *value) { |
---|
478 | if (libtrace->format->config_output) { |
---|
479 | return libtrace->format->config_output(libtrace, option, value); |
---|
480 | } |
---|
481 | return -1; |
---|
482 | } |
---|
483 | |
---|
484 | /* Close a trace file, freeing up any resources it may have been using |
---|
485 | * |
---|
486 | */ |
---|
487 | void trace_destroy(struct libtrace_t *libtrace) { |
---|
488 | assert(libtrace); |
---|
489 | libtrace->format->fin_input(libtrace); |
---|
490 | /* need to free things! */ |
---|
491 | free(libtrace->uridata); |
---|
492 | destroy_tracefifo(libtrace->fifo); |
---|
493 | free(libtrace); |
---|
494 | } |
---|
495 | |
---|
496 | |
---|
497 | void trace_destroy_dead(struct libtrace_t *libtrace) { |
---|
498 | assert(libtrace); |
---|
499 | free(libtrace); |
---|
500 | } |
---|
501 | /* Close an output trace file, freeing up any resources it may have been using |
---|
502 | * |
---|
503 | * @param libtrace the output trace file to be destroyed |
---|
504 | * |
---|
505 | * @author Shane Alcock |
---|
506 | * */ |
---|
507 | void trace_destroy_output(struct libtrace_out_t *libtrace) { |
---|
508 | assert(libtrace); |
---|
509 | libtrace->format->fin_output(libtrace); |
---|
510 | free(libtrace->uridata); |
---|
511 | free(libtrace); |
---|
512 | } |
---|
513 | |
---|
514 | libtrace_packet_t *trace_create_packet() { |
---|
515 | libtrace_packet_t *packet = calloc(1,sizeof(libtrace_packet_t)); |
---|
516 | packet->buf_control=TRACE_CTRL_PACKET; |
---|
517 | return packet; |
---|
518 | } |
---|
519 | |
---|
520 | libtrace_packet_t *trace_copy_packet(const libtrace_packet_t *packet) { |
---|
521 | libtrace_packet_t *dest = malloc(sizeof(libtrace_packet_t)); |
---|
522 | dest->trace=packet->trace; |
---|
523 | dest->buffer=malloc( |
---|
524 | trace_get_framing_length(packet) |
---|
525 | +trace_get_capture_length(packet)); |
---|
526 | dest->header=dest->buffer; |
---|
527 | dest->payload=(void*) |
---|
528 | ((char*)dest->buffer+trace_get_framing_length(packet)); |
---|
529 | dest->size=packet->size; |
---|
530 | dest->type=packet->type; |
---|
531 | dest->buf_control=TRACE_CTRL_PACKET; |
---|
532 | memcpy(dest->header,packet->header,trace_get_framing_length(packet)); |
---|
533 | memcpy(dest->payload,packet->payload,trace_get_capture_length(packet)); |
---|
534 | } |
---|
535 | |
---|
536 | /** Destroy a packet object |
---|
537 | * |
---|
538 | * sideeffect: sets packet to NULL |
---|
539 | */ |
---|
540 | void trace_destroy_packet(struct libtrace_packet_t **packet) { |
---|
541 | if ((*packet)->buf_control == TRACE_CTRL_PACKET) { |
---|
542 | free((*packet)->buffer); |
---|
543 | } |
---|
544 | free((*packet)); |
---|
545 | packet = NULL; |
---|
546 | } |
---|
547 | |
---|
548 | /* Read one packet from the trace into buffer |
---|
549 | * |
---|
550 | * @param libtrace the libtrace opaque pointer |
---|
551 | * @param packet the packet opaque pointer |
---|
552 | * @returns 0 on EOF, negative value on error |
---|
553 | * |
---|
554 | */ |
---|
555 | int trace_read_packet(libtrace_t *libtrace, libtrace_packet_t *packet) { |
---|
556 | |
---|
557 | assert(libtrace && "You called trace_read_packet() with a NULL libtrace parameter!\n"); |
---|
558 | assert(libtrace->started && "BUG: You must call libtrace_start() before trace_read_packet()\n"); |
---|
559 | assert(packet); |
---|
560 | assert((packet->buf_control==TRACE_CTRL_PACKET || packet->buf_control==TRACE_CTRL_EXTERNAL)&& |
---|
561 | "BUG: You must allocate a packet using packet_create()"); |
---|
562 | |
---|
563 | /* Store the trace we are reading from into the packet opaque |
---|
564 | * structure */ |
---|
565 | packet->trace = libtrace; |
---|
566 | |
---|
567 | |
---|
568 | if (libtrace->format->read_packet) { |
---|
569 | do { |
---|
570 | packet->size=libtrace->format->read_packet(libtrace,packet); |
---|
571 | if (packet->size==-1 || packet->size==0) |
---|
572 | return packet->size; |
---|
573 | if (libtrace->filter) { |
---|
574 | /* If the filter doesn't match, read another |
---|
575 | * packet |
---|
576 | */ |
---|
577 | if (!trace_bpf_filter(libtrace->filter,packet)){ |
---|
578 | continue; |
---|
579 | } |
---|
580 | } |
---|
581 | if (libtrace->snaplen>0) { |
---|
582 | /* Snap the packet */ |
---|
583 | trace_set_capture_length(packet, |
---|
584 | libtrace->snaplen); |
---|
585 | } |
---|
586 | |
---|
587 | return packet->size; |
---|
588 | } while(1); |
---|
589 | } |
---|
590 | packet->size=-1; |
---|
591 | return -1; |
---|
592 | } |
---|
593 | |
---|
594 | /* Writes a packet to the specified output |
---|
595 | * |
---|
596 | * @param libtrace describes the output format, destination, etc. |
---|
597 | * @param packet the packet to be written out |
---|
598 | * @returns the number of bytes written, -1 if write failed |
---|
599 | * |
---|
600 | * @author Shane Alcock |
---|
601 | * */ |
---|
602 | int trace_write_packet(struct libtrace_out_t *libtrace, const struct libtrace_packet_t *packet) { |
---|
603 | assert(libtrace); |
---|
604 | assert(packet); |
---|
605 | /* Verify the packet is valid */ |
---|
606 | assert(packet->size<65536); |
---|
607 | assert(packet->size>0); |
---|
608 | |
---|
609 | if (libtrace->format->write_packet) { |
---|
610 | return libtrace->format->write_packet(libtrace, packet); |
---|
611 | } |
---|
612 | return -1; |
---|
613 | } |
---|
614 | |
---|
615 | /* get a pointer to the link layer |
---|
616 | * @param packet a pointer to a libtrace_packet structure |
---|
617 | * |
---|
618 | * @returns a pointer to the link layer, or NULL if there is no link layer |
---|
619 | * |
---|
620 | * @note you should call trace_get_link_type() to find out what type of link layer this is |
---|
621 | */ |
---|
622 | void *trace_get_link(const struct libtrace_packet_t *packet) { |
---|
623 | return (void *)packet->payload; |
---|
624 | } |
---|
625 | |
---|
626 | /* |
---|
627 | typedef struct legacy_framing { |
---|
628 | uint64_t ts; |
---|
629 | uint32_t crc; |
---|
630 | uint32_t header; |
---|
631 | uint32_t data[12]; // pad to 64 bytes |
---|
632 | } legacy_framing_t; |
---|
633 | */ |
---|
634 | |
---|
635 | /* get a pointer to the IP header (if any) |
---|
636 | * @param packet a pointer to a libtrace_packet structure |
---|
637 | * |
---|
638 | * @returns a pointer to the IP header, or NULL if there is not an IP packet |
---|
639 | */ |
---|
640 | struct libtrace_ip *trace_get_ip(const struct libtrace_packet_t *packet) { |
---|
641 | struct libtrace_ip *ipptr = 0; |
---|
642 | |
---|
643 | switch(trace_get_link_type(packet)) { |
---|
644 | case TRACE_TYPE_80211_PRISM: |
---|
645 | { |
---|
646 | struct ieee_802_11_header *wifi = |
---|
647 | (void*)( |
---|
648 | (char*)trace_get_link(packet)+144); |
---|
649 | if (!wifi) { |
---|
650 | ipptr = NULL; |
---|
651 | break; |
---|
652 | } |
---|
653 | |
---|
654 | /* Data packet? */ |
---|
655 | if (wifi->type != 2) { |
---|
656 | ipptr = NULL; |
---|
657 | } |
---|
658 | else { |
---|
659 | struct ieee_802_11_payload *eth = |
---|
660 | (void*)((char*)wifi+sizeof(struct ieee_802_11_header)); |
---|
661 | ipptr = NULL; |
---|
662 | |
---|
663 | if (ntohs(eth->type) == 0x0800) { |
---|
664 | ipptr=(void*) |
---|
665 | ((char*)eth + sizeof(*eth)); |
---|
666 | } else if (ntohs(eth->type) == 0x8100) { |
---|
667 | struct libtrace_8021q *vlanhdr = |
---|
668 | (struct libtrace_8021q *)eth; |
---|
669 | if (ntohs(vlanhdr->vlan_ether_type) |
---|
670 | == 0x0800) { |
---|
671 | ipptr=(void*)( |
---|
672 | (char*)eth+sizeof(*vlanhdr)); |
---|
673 | } |
---|
674 | } |
---|
675 | } |
---|
676 | } |
---|
677 | break; |
---|
678 | case TRACE_TYPE_80211: |
---|
679 | { |
---|
680 | |
---|
681 | struct ieee_802_11_header *wifi = trace_get_link(packet); |
---|
682 | if (!wifi) { |
---|
683 | ipptr = NULL; |
---|
684 | break; |
---|
685 | } |
---|
686 | |
---|
687 | /* Data packet? */ |
---|
688 | if (wifi->type != 2) { |
---|
689 | ipptr = NULL; |
---|
690 | } |
---|
691 | else { |
---|
692 | struct ieee_802_11_payload *eth = |
---|
693 | (void*)((char*)wifi+sizeof(struct ieee_802_11_header)); |
---|
694 | ipptr = NULL; |
---|
695 | |
---|
696 | if (ntohs(eth->type) == 0x0800) { |
---|
697 | ipptr=(void*)((char*)eth + sizeof(*eth)); |
---|
698 | } else if (ntohs(eth->type) == 0x8100) { |
---|
699 | struct libtrace_8021q *vlanhdr = |
---|
700 | (struct libtrace_8021q *)eth; |
---|
701 | if (ntohs(vlanhdr->vlan_ether_type) |
---|
702 | == 0x0800) { |
---|
703 | ipptr=(void*)((char*)eth + |
---|
704 | sizeof(*vlanhdr)); |
---|
705 | } |
---|
706 | } |
---|
707 | } |
---|
708 | } |
---|
709 | break; |
---|
710 | case TRACE_TYPE_ETH: |
---|
711 | case TRACE_TYPE_LEGACY_ETH: |
---|
712 | { |
---|
713 | struct libtrace_ether *eth = |
---|
714 | trace_get_link(packet); |
---|
715 | if (!eth) { |
---|
716 | ipptr = NULL; |
---|
717 | break; |
---|
718 | } |
---|
719 | ipptr = NULL; |
---|
720 | |
---|
721 | if (ntohs(eth->ether_type)==0x0800) { |
---|
722 | ipptr = (void*)((char *)eth + sizeof(*eth)); |
---|
723 | } else if (ntohs(eth->ether_type) == 0x8100) { |
---|
724 | struct libtrace_8021q *vlanhdr = |
---|
725 | (struct libtrace_8021q *)eth; |
---|
726 | if (ntohs(vlanhdr->vlan_ether_type) |
---|
727 | == 0x0800) { |
---|
728 | ipptr = (void*)((char *)eth + |
---|
729 | sizeof(*vlanhdr)); |
---|
730 | } |
---|
731 | } |
---|
732 | break; |
---|
733 | } |
---|
734 | case TRACE_TYPE_NONE: |
---|
735 | ipptr = trace_get_link(packet); |
---|
736 | break; |
---|
737 | case TRACE_TYPE_LINUX_SLL: |
---|
738 | { |
---|
739 | struct trace_sll_header_t *sll; |
---|
740 | |
---|
741 | sll = trace_get_link(packet); |
---|
742 | if (!sll) { |
---|
743 | ipptr = NULL; |
---|
744 | break; |
---|
745 | } |
---|
746 | if (ntohs(sll->protocol)!=0x0800) { |
---|
747 | ipptr = NULL; |
---|
748 | } |
---|
749 | else { |
---|
750 | ipptr = (void*)((char*)sll+ |
---|
751 | sizeof(*sll)); |
---|
752 | } |
---|
753 | } |
---|
754 | break; |
---|
755 | case TRACE_TYPE_PFLOG: |
---|
756 | { |
---|
757 | struct trace_pflog_header_t *pflog; |
---|
758 | pflog = trace_get_link(packet); |
---|
759 | if (!pflog) { |
---|
760 | ipptr = NULL; |
---|
761 | break; |
---|
762 | } |
---|
763 | if (pflog->af != AF_INET) { |
---|
764 | ipptr = NULL; |
---|
765 | } else { |
---|
766 | ipptr = (void*)((char*)pflog+ |
---|
767 | sizeof(*pflog)); |
---|
768 | } |
---|
769 | } |
---|
770 | break; |
---|
771 | case TRACE_TYPE_LEGACY_POS: |
---|
772 | { |
---|
773 | /* 64 byte capture. */ |
---|
774 | struct libtrace_pos *pos = |
---|
775 | trace_get_link(packet); |
---|
776 | if (ntohs(pos->ether_type) == 0x0800) { |
---|
777 | ipptr=(void*)((char *)pos+sizeof(*pos)); |
---|
778 | } else { |
---|
779 | ipptr=NULL; |
---|
780 | } |
---|
781 | break; |
---|
782 | |
---|
783 | } |
---|
784 | case TRACE_TYPE_LEGACY_ATM: |
---|
785 | case TRACE_TYPE_ATM: |
---|
786 | { |
---|
787 | /* 64 byte capture. */ |
---|
788 | struct libtrace_llcsnap *llc = |
---|
789 | trace_get_link(packet); |
---|
790 | |
---|
791 | /* advance the llc ptr +4 into the link layer. |
---|
792 | * need to check what is in these 4 bytes. |
---|
793 | * don't have time! |
---|
794 | */ |
---|
795 | llc = (void*)((char *)llc + 4); |
---|
796 | if (ntohs(llc->type) == 0x0800) { |
---|
797 | ipptr=(void*)((char*)llc+sizeof(*llc)); |
---|
798 | } else { |
---|
799 | ipptr = NULL; |
---|
800 | } |
---|
801 | break; |
---|
802 | } |
---|
803 | default: |
---|
804 | fprintf(stderr,"Don't understand link layer type %i in trace_get_ip()\n", |
---|
805 | trace_get_link_type(packet)); |
---|
806 | ipptr=NULL; |
---|
807 | break; |
---|
808 | } |
---|
809 | |
---|
810 | return ipptr; |
---|
811 | } |
---|
812 | |
---|
813 | #define SW_IP_OFFMASK 0xff1f |
---|
814 | |
---|
815 | /* Gets a pointer to the transport layer header (if any) |
---|
816 | * @param packet a pointer to a libtrace_packet structure |
---|
817 | * |
---|
818 | * @returns a pointer to the transport layer header, or NULL if there is no header |
---|
819 | */ |
---|
820 | void *trace_get_transport(const struct libtrace_packet_t *packet) { |
---|
821 | void *trans_ptr = 0; |
---|
822 | struct libtrace_ip *ipptr = 0; |
---|
823 | |
---|
824 | if (!(ipptr = trace_get_ip(packet))) { |
---|
825 | return 0; |
---|
826 | } |
---|
827 | |
---|
828 | if ((ipptr->ip_off & SW_IP_OFFMASK) == 0) { |
---|
829 | trans_ptr = (void *)((ptrdiff_t)ipptr + (ipptr->ip_hl * 4)); |
---|
830 | } |
---|
831 | return trans_ptr; |
---|
832 | } |
---|
833 | |
---|
834 | /* Gets a pointer to the transport layer header (if any) given a pointer to the |
---|
835 | * IP header |
---|
836 | * @param ip The IP Header |
---|
837 | * @param[out] skipped An output variable of the number of bytes skipped |
---|
838 | * |
---|
839 | * @returns a pointer to the transport layer header, or NULL if there is no header |
---|
840 | * |
---|
841 | * Skipped can be NULL, in which case it will be ignored |
---|
842 | */ |
---|
843 | void *trace_get_transport_from_ip(const libtrace_ip_t *ip, int *skipped) { |
---|
844 | void *trans_ptr = 0; |
---|
845 | |
---|
846 | if ((ip->ip_off & SW_IP_OFFMASK) == 0) { |
---|
847 | trans_ptr = (void *)((ptrdiff_t)ip + (ip->ip_hl * 4)); |
---|
848 | } |
---|
849 | |
---|
850 | if (skipped) |
---|
851 | *skipped = (ip->ip_hl*4); |
---|
852 | |
---|
853 | return trans_ptr; |
---|
854 | } |
---|
855 | |
---|
856 | /* get a pointer to the TCP header (if any) |
---|
857 | * @param packet a pointer to a libtrace_packet structure |
---|
858 | * |
---|
859 | * @returns a pointer to the TCP header, or NULL if there is not a TCP packet |
---|
860 | */ |
---|
861 | libtrace_tcp_t *trace_get_tcp(const libtrace_packet_t *packet) { |
---|
862 | struct libtrace_tcp *tcpptr = 0; |
---|
863 | struct libtrace_ip *ipptr = 0; |
---|
864 | |
---|
865 | if(!(ipptr = trace_get_ip(packet))) { |
---|
866 | return 0; |
---|
867 | } |
---|
868 | if (ipptr->ip_p == 6) { |
---|
869 | tcpptr = (struct libtrace_tcp *)trace_get_transport_from_ip(ipptr, 0); |
---|
870 | } |
---|
871 | return tcpptr; |
---|
872 | } |
---|
873 | |
---|
874 | /* get a pointer to the TCP header (if any) given a pointer to the IP header |
---|
875 | * @param ip The IP header |
---|
876 | * @param[out] skipped An output variable of the number of bytes skipped |
---|
877 | * |
---|
878 | * @returns a pointer to the TCP header, or NULL if this is not a TCP packet |
---|
879 | * |
---|
880 | * Skipped can be NULL, in which case it will be ignored by the program. |
---|
881 | */ |
---|
882 | libtrace_tcp_t *trace_get_tcp_from_ip(const libtrace_ip_t *ip, int *skipped) |
---|
883 | { |
---|
884 | struct libtrace_tcp *tcpptr = 0; |
---|
885 | |
---|
886 | if (ip->ip_p == 6) { |
---|
887 | tcpptr = (struct libtrace_tcp *)trace_get_transport_from_ip(ip, skipped); |
---|
888 | } |
---|
889 | |
---|
890 | return tcpptr; |
---|
891 | } |
---|
892 | |
---|
893 | /* get a pointer to the UDP header (if any) |
---|
894 | * @param packet a pointer to a libtrace_packet structure |
---|
895 | * |
---|
896 | * @returns a pointer to the UDP header, or NULL if this is not a UDP packet |
---|
897 | */ |
---|
898 | struct libtrace_udp *trace_get_udp(const struct libtrace_packet_t *packet) { |
---|
899 | struct libtrace_udp *udpptr = 0; |
---|
900 | struct libtrace_ip *ipptr = 0; |
---|
901 | |
---|
902 | if(!(ipptr = trace_get_ip(packet))) { |
---|
903 | return 0; |
---|
904 | } |
---|
905 | if (ipptr->ip_p == 17) { |
---|
906 | udpptr = (struct libtrace_udp *)trace_get_transport_from_ip(ipptr, 0); |
---|
907 | } |
---|
908 | |
---|
909 | return udpptr; |
---|
910 | } |
---|
911 | |
---|
912 | /* get a pointer to the UDP header (if any) given a pointer to the IP header |
---|
913 | * @param ip The IP header |
---|
914 | * @param[out] skipped An output variable of the number of bytes skipped |
---|
915 | * |
---|
916 | * @returns a pointer to the UDP header, or NULL if this is not a UDP packet |
---|
917 | * |
---|
918 | * Skipped can be NULL, in which case it will be ignored by the program. |
---|
919 | */ |
---|
920 | struct libtrace_udp *trace_get_udp_from_ip(const struct libtrace_ip *ip, int *skipped) |
---|
921 | { |
---|
922 | struct libtrace_udp *udpptr = 0; |
---|
923 | |
---|
924 | if (ip->ip_p == 17) { |
---|
925 | udpptr = (struct libtrace_udp *)trace_get_transport_from_ip(ip, skipped); |
---|
926 | } |
---|
927 | |
---|
928 | return udpptr; |
---|
929 | } |
---|
930 | |
---|
931 | |
---|
932 | /* get a pointer to the ICMP header (if any) |
---|
933 | * @param packet a pointer to a libtrace_packet structure |
---|
934 | * |
---|
935 | * @returns a pointer to the ICMP header, or NULL if this is not a ICMP packet |
---|
936 | */ |
---|
937 | struct libtrace_icmp *trace_get_icmp(const struct libtrace_packet_t *packet) { |
---|
938 | struct libtrace_icmp *icmpptr = 0; |
---|
939 | struct libtrace_ip *ipptr = 0; |
---|
940 | |
---|
941 | if(!(ipptr = trace_get_ip(packet))) { |
---|
942 | return 0; |
---|
943 | } |
---|
944 | if (ipptr->ip_p == 1){ |
---|
945 | icmpptr = (struct libtrace_icmp *)trace_get_transport_from_ip(ipptr, 0); |
---|
946 | } |
---|
947 | return icmpptr; |
---|
948 | } |
---|
949 | |
---|
950 | /* get a pointer to the ICMP header (if any) given a pointer to the IP header |
---|
951 | * @param ip The IP header |
---|
952 | * @param[out] skipped An output variable of the number of bytes skipped |
---|
953 | * |
---|
954 | * @returns a pointer to the ICMP header, or NULL if this is not a ICMP packet |
---|
955 | * |
---|
956 | * Skipped can be NULL, in which case it will be ignored by the program. |
---|
957 | */ |
---|
958 | struct libtrace_icmp *trace_get_icmp_from_ip(const struct libtrace_ip *ip, int *skipped) |
---|
959 | { |
---|
960 | struct libtrace_icmp *icmpptr = 0; |
---|
961 | |
---|
962 | if (ip->ip_p == 1) { |
---|
963 | icmpptr = (struct libtrace_icmp *)trace_get_transport_from_ip(ip, skipped); |
---|
964 | } |
---|
965 | |
---|
966 | return icmpptr; |
---|
967 | } |
---|
968 | /* parse an ip or tcp option |
---|
969 | * @param[in,out] ptr the pointer to the current option |
---|
970 | * @param[in,out] len the length of the remaining buffer |
---|
971 | * @param[out] type the type of the option |
---|
972 | * @param[out] optlen the length of the option |
---|
973 | * @param[out] data the data of the option |
---|
974 | * |
---|
975 | * @returns bool true if there is another option (and the fields are filled in) |
---|
976 | * or false if this was the last option. |
---|
977 | * |
---|
978 | * This updates ptr to point to the next option after this one, and updates |
---|
979 | * len to be the number of bytes remaining in the options area. Type is updated |
---|
980 | * to be the code of this option, and data points to the data of this option, |
---|
981 | * with optlen saying how many bytes there are. |
---|
982 | * |
---|
983 | * @note Beware of fragmented packets. |
---|
984 | * @author Perry Lorier |
---|
985 | */ |
---|
986 | int trace_get_next_option(unsigned char **ptr,int *len, |
---|
987 | unsigned char *type, |
---|
988 | unsigned char *optlen, |
---|
989 | unsigned char **data) |
---|
990 | { |
---|
991 | if (*len<=0) |
---|
992 | return 0; |
---|
993 | *type=**ptr; |
---|
994 | switch(*type) { |
---|
995 | case 0: /* End of options */ |
---|
996 | return 0; |
---|
997 | case 1: /* Pad */ |
---|
998 | (*ptr)++; |
---|
999 | (*len)--; |
---|
1000 | return 1; |
---|
1001 | default: |
---|
1002 | *optlen = *(*ptr+1); |
---|
1003 | if (*optlen<2) |
---|
1004 | return 0; /* I have no idea wtf is going on |
---|
1005 | * with these packets |
---|
1006 | */ |
---|
1007 | (*len)-=*optlen; |
---|
1008 | (*data)=(*ptr+2); |
---|
1009 | (*ptr)+=*optlen; |
---|
1010 | if (*len<0) |
---|
1011 | return 0; |
---|
1012 | return 1; |
---|
1013 | } |
---|
1014 | assert(0); |
---|
1015 | } |
---|
1016 | |
---|
1017 | |
---|
1018 | /* Get the current time in DAG time format |
---|
1019 | * @param packet a pointer to a libtrace_packet structure |
---|
1020 | * @returns a 64 bit timestamp in DAG ERF format (upper 32 bits are the seconds |
---|
1021 | * past 1970-01-01, the lower 32bits are partial seconds) |
---|
1022 | * @author Daniel Lawson |
---|
1023 | */ |
---|
1024 | uint64_t trace_get_erf_timestamp(const libtrace_packet_t *packet) { |
---|
1025 | uint64_t timestamp = 0; |
---|
1026 | double seconds = 0.0; |
---|
1027 | struct timeval ts; |
---|
1028 | |
---|
1029 | assert(packet->size>0 && packet->size<65536); |
---|
1030 | |
---|
1031 | if (packet->trace->format->get_erf_timestamp) { |
---|
1032 | /* timestamp -> timestamp */ |
---|
1033 | timestamp = packet->trace->format->get_erf_timestamp(packet); |
---|
1034 | } else if (packet->trace->format->get_timeval) { |
---|
1035 | /* timeval -> timestamp */ |
---|
1036 | ts = packet->trace->format->get_timeval(packet); |
---|
1037 | timestamp = ((((uint64_t)ts.tv_sec) << 32) + \ |
---|
1038 | (((uint64_t)ts.tv_usec * UINT_MAX)/1000000)); |
---|
1039 | } else if (packet->trace->format->get_seconds) { |
---|
1040 | /* seconds -> timestamp */ |
---|
1041 | seconds = packet->trace->format->get_seconds(packet); |
---|
1042 | timestamp = ((uint64_t)((uint32_t)seconds) << 32) + \ |
---|
1043 | (( seconds - (uint32_t)seconds ) * UINT_MAX); |
---|
1044 | } |
---|
1045 | return timestamp; |
---|
1046 | } |
---|
1047 | |
---|
1048 | /* Get the current time in struct timeval |
---|
1049 | * @param packet a pointer to a libtrace_packet structure |
---|
1050 | * |
---|
1051 | * @returns time that this packet was seen in a struct timeval |
---|
1052 | * @author Daniel Lawson |
---|
1053 | * @author Perry Lorier |
---|
1054 | */ |
---|
1055 | struct timeval trace_get_timeval(const libtrace_packet_t *packet) { |
---|
1056 | struct timeval tv; |
---|
1057 | uint64_t ts = 0; |
---|
1058 | double seconds = 0.0; |
---|
1059 | assert(packet->size>0 && packet->size<65536); |
---|
1060 | if (packet->trace->format->get_timeval) { |
---|
1061 | /* timeval -> timeval */ |
---|
1062 | tv = packet->trace->format->get_timeval(packet); |
---|
1063 | } else if (packet->trace->format->get_erf_timestamp) { |
---|
1064 | /* timestamp -> timeval */ |
---|
1065 | ts = packet->trace->format->get_erf_timestamp(packet); |
---|
1066 | #if __BYTE_ORDER == __BIG_ENDIAN |
---|
1067 | tv.tv_sec = ts & 0xFFFFFFFF; |
---|
1068 | #elif __BYTE_ORDER == __LITTLE_ENDIAN |
---|
1069 | tv.tv_sec = ts >> 32; |
---|
1070 | #else |
---|
1071 | #error "What on earth are you running this on?" |
---|
1072 | #endif |
---|
1073 | tv.tv_usec = ((ts&0xFFFFFFFF)*1000000)>>32; |
---|
1074 | if (tv.tv_usec >= 1000000) { |
---|
1075 | tv.tv_usec -= 1000000; |
---|
1076 | tv.tv_sec += 1; |
---|
1077 | } |
---|
1078 | } else if (packet->trace->format->get_seconds) { |
---|
1079 | /* seconds -> timeval */ |
---|
1080 | seconds = packet->trace->format->get_seconds(packet); |
---|
1081 | tv.tv_sec = (uint32_t)seconds; |
---|
1082 | tv.tv_usec = (uint32_t)(((seconds - tv.tv_sec) * 1000000)/UINT_MAX); |
---|
1083 | } |
---|
1084 | |
---|
1085 | return tv; |
---|
1086 | } |
---|
1087 | |
---|
1088 | /* Get the current time in floating point seconds |
---|
1089 | * @param packet a pointer to a libtrace_packet structure |
---|
1090 | * @returns time that this packet was seen in 64bit floating point seconds |
---|
1091 | * @author Perry Lorier |
---|
1092 | */ |
---|
1093 | double trace_get_seconds(const struct libtrace_packet_t *packet) { |
---|
1094 | double seconds = 0.0; |
---|
1095 | uint64_t ts = 0; |
---|
1096 | struct timeval tv; |
---|
1097 | |
---|
1098 | assert(packet->size>0 && packet->size<65536); |
---|
1099 | |
---|
1100 | if (packet->trace->format->get_seconds) { |
---|
1101 | /* seconds->seconds */ |
---|
1102 | seconds = packet->trace->format->get_seconds(packet); |
---|
1103 | } else if (packet->trace->format->get_erf_timestamp) { |
---|
1104 | /* timestamp -> seconds */ |
---|
1105 | ts = packet->trace->format->get_erf_timestamp(packet); |
---|
1106 | seconds = (ts>>32) + ((ts & UINT_MAX)*1.0 / UINT_MAX); |
---|
1107 | } else if (packet->trace->format->get_timeval) { |
---|
1108 | /* timeval -> seconds */ |
---|
1109 | tv = packet->trace->format->get_timeval(packet); |
---|
1110 | seconds = tv.tv_sec + ((tv.tv_usec * UINT_MAX * 1.0)/1000000); |
---|
1111 | } |
---|
1112 | |
---|
1113 | return seconds; |
---|
1114 | } |
---|
1115 | |
---|
1116 | int trace_get_capture_length(const struct libtrace_packet_t *packet) { |
---|
1117 | |
---|
1118 | assert(packet->size>0 && packet->size<65536); |
---|
1119 | |
---|
1120 | if (packet->trace->format->get_capture_length) { |
---|
1121 | return packet->trace->format->get_capture_length(packet); |
---|
1122 | } |
---|
1123 | return -1; |
---|
1124 | } |
---|
1125 | |
---|
1126 | /* Get the size of the packet as it was seen on the wire. |
---|
1127 | * @param packet a pointer to a libtrace_packet structure |
---|
1128 | * |
---|
1129 | * @returns the size of the packet as it was on the wire. |
---|
1130 | * @author Perry Lorier |
---|
1131 | * @author Daniel Lawson |
---|
1132 | * @note Due to the trace being a header capture, or anonymisation this may |
---|
1133 | * not be the same as the Capture Len. |
---|
1134 | */ |
---|
1135 | int trace_get_wire_length(const struct libtrace_packet_t *packet){ |
---|
1136 | assert(packet->size>0 && packet->size<65536); |
---|
1137 | |
---|
1138 | if (packet->trace->format->get_wire_length) { |
---|
1139 | return packet->trace->format->get_wire_length(packet); |
---|
1140 | } |
---|
1141 | return -1; |
---|
1142 | |
---|
1143 | } |
---|
1144 | |
---|
1145 | /* Get the length of the capture framing headers. |
---|
1146 | * @param packet the packet opaque pointer |
---|
1147 | * @returns the size of the packet as it was on the wire. |
---|
1148 | * @author Perry Lorier |
---|
1149 | * @author Daniel Lawson |
---|
1150 | * @note this length corresponds to the difference between the size of a |
---|
1151 | * captured packet in memory, and the captured length of the packet |
---|
1152 | */ |
---|
1153 | SIMPLE_FUNCTION |
---|
1154 | int trace_get_framing_length(const libtrace_packet_t *packet) { |
---|
1155 | if (packet->trace->format->get_framing_length) { |
---|
1156 | return packet->trace->format->get_framing_length(packet); |
---|
1157 | } |
---|
1158 | return -1; |
---|
1159 | } |
---|
1160 | |
---|
1161 | |
---|
1162 | /* Get the type of the link layer |
---|
1163 | * @param packet a pointer to a libtrace_packet structure |
---|
1164 | * @returns libtrace_linktype_t |
---|
1165 | * @author Perry Lorier |
---|
1166 | * @author Daniel Lawson |
---|
1167 | */ |
---|
1168 | libtrace_linktype_t trace_get_link_type(const libtrace_packet_t *packet ) { |
---|
1169 | if (packet->trace->format->get_link_type) { |
---|
1170 | return packet->trace->format->get_link_type(packet); |
---|
1171 | } |
---|
1172 | return -1; |
---|
1173 | } |
---|
1174 | |
---|
1175 | /* Get the source MAC addres |
---|
1176 | * @param packet a pointer to a libtrace_packet structure |
---|
1177 | * @returns a pointer to the source mac, (or NULL if there is no source MAC) |
---|
1178 | * @author Perry Lorier |
---|
1179 | */ |
---|
1180 | uint8_t *trace_get_source_mac(const struct libtrace_packet_t *packet) { |
---|
1181 | void *link = trace_get_link(packet); |
---|
1182 | struct ieee_802_11_header *wifi = link; |
---|
1183 | struct libtrace_ether *ethptr = link; |
---|
1184 | if (!link) |
---|
1185 | return NULL; |
---|
1186 | switch (trace_get_link_type(packet)) { |
---|
1187 | case TRACE_TYPE_80211: |
---|
1188 | return (uint8_t*)&wifi->mac2; |
---|
1189 | case TRACE_TYPE_ETH: |
---|
1190 | return (uint8_t*)ðptr->ether_shost; |
---|
1191 | default: |
---|
1192 | fprintf(stderr,"Not implemented\n"); |
---|
1193 | assert(0); |
---|
1194 | } |
---|
1195 | } |
---|
1196 | |
---|
1197 | /* Get the destination MAC addres |
---|
1198 | * @param packet a libtrace_packet pointer |
---|
1199 | * @returns a pointer to the destination mac, (or NULL if there is no |
---|
1200 | * destination MAC) |
---|
1201 | * @author Perry Lorier |
---|
1202 | */ |
---|
1203 | uint8_t *trace_get_destination_mac(const struct libtrace_packet_t *packet) { |
---|
1204 | void *link = trace_get_link(packet); |
---|
1205 | struct ieee_802_11_header *wifi = link; |
---|
1206 | struct libtrace_ether *ethptr = link; |
---|
1207 | if (!link) |
---|
1208 | return NULL; |
---|
1209 | switch (trace_get_link_type(packet)) { |
---|
1210 | case TRACE_TYPE_80211: |
---|
1211 | return (uint8_t*)&wifi->mac1; |
---|
1212 | case TRACE_TYPE_ETH: |
---|
1213 | return (uint8_t*)ðptr->ether_dhost; |
---|
1214 | default: |
---|
1215 | fprintf(stderr,"Not implemented\n"); |
---|
1216 | assert(0); |
---|
1217 | } |
---|
1218 | } |
---|
1219 | |
---|
1220 | |
---|
1221 | /* process a libtrace event |
---|
1222 | * @param trace the libtrace opaque pointer |
---|
1223 | * @param packet the libtrace_packet opaque pointer |
---|
1224 | * @returns |
---|
1225 | * TRACE_EVENT_IOWAIT Waiting on I/O on fd |
---|
1226 | * TRACE_EVENT_SLEEP Next event in seconds |
---|
1227 | * TRACE_EVENT_PACKET Packet arrived in buffer with size size |
---|
1228 | * TRACE_EVENT_TERMINATE Trace terminated (perhaps with an error condition) |
---|
1229 | * FIXME currently keeps a copy of the packet inside the trace pointer, |
---|
1230 | * which in turn is stored inside the new packet object... |
---|
1231 | * @author Perry Lorier |
---|
1232 | */ |
---|
1233 | struct libtrace_eventobj_t trace_event(struct libtrace_t *trace, |
---|
1234 | struct libtrace_packet_t *packet) { |
---|
1235 | struct libtrace_eventobj_t event = {0,0,0.0,0}; |
---|
1236 | |
---|
1237 | if (!trace) { |
---|
1238 | fprintf(stderr,"You called trace_event() with a NULL trace object!\n"); |
---|
1239 | } |
---|
1240 | assert(trace); |
---|
1241 | assert(packet); |
---|
1242 | |
---|
1243 | /* Store the trace we are reading from into the packet opaque |
---|
1244 | * structure */ |
---|
1245 | packet->trace = trace; |
---|
1246 | |
---|
1247 | if (packet->trace->format->trace_event) { |
---|
1248 | return packet->trace->format->trace_event(trace,packet); |
---|
1249 | } else { |
---|
1250 | return event; |
---|
1251 | } |
---|
1252 | |
---|
1253 | } |
---|
1254 | |
---|
1255 | /* setup a BPF filter |
---|
1256 | * @param filterstring a char * containing the bpf filter string |
---|
1257 | * @returns opaque pointer pointer to a libtrace_filter_t object |
---|
1258 | * @author Daniel Lawson |
---|
1259 | */ |
---|
1260 | struct libtrace_filter_t *trace_bpf_setfilter(const char *filterstring) { |
---|
1261 | #if HAVE_BPF |
---|
1262 | struct libtrace_filter_t *filter = malloc(sizeof(struct libtrace_filter_t)); |
---|
1263 | filter->filterstring = strdup(filterstring); |
---|
1264 | filter->flag = 0; |
---|
1265 | return filter; |
---|
1266 | #else |
---|
1267 | fprintf(stderr,"This version of libtrace does not have bpf filter support\n"); |
---|
1268 | return 0; |
---|
1269 | #endif |
---|
1270 | } |
---|
1271 | |
---|
1272 | /* compile a bpf filter, now we know what trace it's on |
---|
1273 | * @internal |
---|
1274 | * |
---|
1275 | * @returns -1 on error, 0 on success |
---|
1276 | */ |
---|
1277 | int trace_bpf_compile(libtrace_filter_t *filter, |
---|
1278 | const libtrace_packet_t *packet ) { |
---|
1279 | #if HAVE_BPF |
---|
1280 | void *linkptr = 0; |
---|
1281 | assert(filter); |
---|
1282 | |
---|
1283 | /* If this isn't a real packet, then fail */ |
---|
1284 | linkptr = trace_get_link(packet); |
---|
1285 | if (!linkptr) { |
---|
1286 | trace_set_err(packet->trace, |
---|
1287 | TRACE_ERR_BAD_PACKET,"Packet has no payload"); |
---|
1288 | return -1; |
---|
1289 | } |
---|
1290 | |
---|
1291 | if (filter->filterstring && ! filter->flag) { |
---|
1292 | pcap_t *pcap; |
---|
1293 | pcap=(pcap_t *)pcap_open_dead( |
---|
1294 | libtrace_to_pcap_dlt(trace_get_link_type(packet)), |
---|
1295 | 1500); |
---|
1296 | /* build filter */ |
---|
1297 | if (pcap_compile( pcap, &filter->filter, filter->filterstring, |
---|
1298 | 1, 0)) { |
---|
1299 | pcap_close(pcap); |
---|
1300 | trace_set_err(packet->trace,TRACE_ERR_BAD_PACKET, |
---|
1301 | "Packet has no payload"); |
---|
1302 | return -1; |
---|
1303 | } |
---|
1304 | pcap_close(pcap); |
---|
1305 | filter->flag=1; |
---|
1306 | } |
---|
1307 | return 0; |
---|
1308 | #else |
---|
1309 | assert(!"This should never be called when BPF not enabled"); |
---|
1310 | #endif |
---|
1311 | } |
---|
1312 | |
---|
1313 | int trace_bpf_filter(struct libtrace_filter_t *filter, |
---|
1314 | const struct libtrace_packet_t *packet) { |
---|
1315 | #if HAVE_BPF |
---|
1316 | void *linkptr = 0; |
---|
1317 | int clen = 0; |
---|
1318 | assert(filter); |
---|
1319 | assert(packet); |
---|
1320 | linkptr = trace_get_link(packet); |
---|
1321 | if (!linkptr) { |
---|
1322 | return 0; |
---|
1323 | } |
---|
1324 | |
---|
1325 | /* We need to compile it now, because before we didn't know what the |
---|
1326 | * link type was |
---|
1327 | */ |
---|
1328 | if (trace_bpf_compile(filter,packet)==-1) |
---|
1329 | return -1; |
---|
1330 | |
---|
1331 | clen = trace_get_capture_length(packet); |
---|
1332 | |
---|
1333 | assert(filter->flag); |
---|
1334 | return bpf_filter(filter->filter.bf_insns, linkptr, clen, clen); |
---|
1335 | #else |
---|
1336 | fprintf(stderr,"This version of libtrace does not have bpf filter support\n"); |
---|
1337 | return 0; |
---|
1338 | #endif |
---|
1339 | } |
---|
1340 | |
---|
1341 | /* Set the direction flag, if it has one |
---|
1342 | * @param packet the packet opaque pointer |
---|
1343 | * @param direction the new direction (0,1,2,3) |
---|
1344 | * @returns a signed value containing the direction flag, or -1 if this is not supported |
---|
1345 | * @author Daniel Lawson |
---|
1346 | */ |
---|
1347 | int8_t trace_set_direction(struct libtrace_packet_t *packet, int8_t direction) { |
---|
1348 | assert(packet); |
---|
1349 | assert(packet->size>0 && packet->size<65536); |
---|
1350 | if (packet->trace->format->set_direction) { |
---|
1351 | return packet->trace->format->set_direction(packet,direction); |
---|
1352 | } |
---|
1353 | return -1; |
---|
1354 | } |
---|
1355 | |
---|
1356 | /* Get the direction flag, if it has one |
---|
1357 | * @param packet a pointer to a libtrace_packet structure |
---|
1358 | * @returns a signed value containing the direction flag, or -1 if this is not supported |
---|
1359 | * The direction is defined as 0 for packets originating locally (ie, outbound) |
---|
1360 | * and 1 for packets originating remotely (ie, inbound). |
---|
1361 | * Other values are possible, which might be overloaded to mean special things |
---|
1362 | * for a special trace. |
---|
1363 | * @author Daniel Lawson |
---|
1364 | */ |
---|
1365 | int8_t trace_get_direction(const struct libtrace_packet_t *packet) { |
---|
1366 | assert(packet); |
---|
1367 | assert(packet->size>0 && packet->size<65536); |
---|
1368 | if (packet->trace->format->get_direction) { |
---|
1369 | return packet->trace->format->get_direction(packet); |
---|
1370 | } |
---|
1371 | return -1; |
---|
1372 | } |
---|
1373 | |
---|
1374 | struct ports_t { |
---|
1375 | uint16_t src; |
---|
1376 | uint16_t dst; |
---|
1377 | }; |
---|
1378 | |
---|
1379 | /* Return the client port |
---|
1380 | */ |
---|
1381 | uint16_t trace_get_source_port(const struct libtrace_packet_t *packet) |
---|
1382 | { |
---|
1383 | struct libtrace_ip *ip = trace_get_ip(packet); |
---|
1384 | struct ports_t *port; |
---|
1385 | if (6 != ip->ip_p |
---|
1386 | && 17 != ip->ip_p) |
---|
1387 | return 0; |
---|
1388 | if (0 != (ip->ip_off & SW_IP_OFFMASK)) |
---|
1389 | return 0; |
---|
1390 | |
---|
1391 | port = (struct ports_t *)((ptrdiff_t)ip + (ip->ip_hl * 4)); |
---|
1392 | |
---|
1393 | return ntohs(port->src); |
---|
1394 | } |
---|
1395 | |
---|
1396 | /* Same as get_source_port except use the destination port */ |
---|
1397 | uint16_t trace_get_destination_port(const struct libtrace_packet_t *packet) |
---|
1398 | { |
---|
1399 | struct libtrace_ip *ip = trace_get_ip(packet); |
---|
1400 | struct ports_t *port; |
---|
1401 | |
---|
1402 | if (6 != ip->ip_p |
---|
1403 | && 17 != ip->ip_p) |
---|
1404 | return 0; |
---|
1405 | |
---|
1406 | if (0 != (ip->ip_off & SW_IP_OFFMASK)) |
---|
1407 | return 0; |
---|
1408 | |
---|
1409 | port = (struct ports_t *)((ptrdiff_t)ip + (ip->ip_hl * 4)); |
---|
1410 | |
---|
1411 | return ntohs(port->dst); |
---|
1412 | } |
---|
1413 | |
---|
1414 | #define ROOT_SERVER(x) ((x) < 512) |
---|
1415 | #define ROOT_CLIENT(x) ((512 <= (x)) && ((x) < 1024)) |
---|
1416 | #define NONROOT_SERVER(x) ((x) >= 5000) |
---|
1417 | #define NONROOT_CLIENT(x) ((1024 <= (x)) && ((x) < 5000)) |
---|
1418 | #define DYNAMIC(x) ((49152 < (x)) && ((x) < 65535)) |
---|
1419 | #define SERVER(x) ROOT_SERVER(x) || NONROOT_SERVER(x) |
---|
1420 | #define CLIENT(x) ROOT_CLIENT(x) || NONROOT_CLIENT(x) |
---|
1421 | |
---|
1422 | /* Attempt to deduce the 'server' port |
---|
1423 | * @param protocol the IP protocol (eg, 6 or 17 for TCP or UDP) |
---|
1424 | * @param source the TCP or UDP source port |
---|
1425 | * @param dest the TCP or UDP destination port |
---|
1426 | * @returns a hint as to which port is the server port |
---|
1427 | * @author Daniel Lawson |
---|
1428 | */ |
---|
1429 | int8_t trace_get_server_port(uint8_t protocol __attribute__((unused)), uint16_t source, uint16_t dest) { |
---|
1430 | /* |
---|
1431 | * * If the ports are equal, return DEST |
---|
1432 | * * Check for well-known ports in the given protocol |
---|
1433 | * * Root server ports: 0 - 511 |
---|
1434 | * * Root client ports: 512 - 1023 |
---|
1435 | * * non-root client ports: 1024 - 4999 |
---|
1436 | * * non-root server ports: 5000+ |
---|
1437 | * * Check for static ranges: 1024 - 49151 |
---|
1438 | * * Check for dynamic ranges: 49152 - 65535 |
---|
1439 | * * flip a coin. |
---|
1440 | */ |
---|
1441 | |
---|
1442 | /* equal */ |
---|
1443 | if (source == dest) |
---|
1444 | return USE_DEST; |
---|
1445 | |
---|
1446 | /* root server port, 0 - 511 */ |
---|
1447 | if (ROOT_SERVER(source) && ROOT_SERVER(dest)) { |
---|
1448 | if (source < dest) |
---|
1449 | return USE_SOURCE; |
---|
1450 | return USE_DEST; |
---|
1451 | } |
---|
1452 | |
---|
1453 | if (ROOT_SERVER(source) && !ROOT_SERVER(dest)) |
---|
1454 | return USE_SOURCE; |
---|
1455 | if (!ROOT_SERVER(source) && ROOT_SERVER(dest)) |
---|
1456 | return USE_DEST; |
---|
1457 | |
---|
1458 | /* non-root server */ |
---|
1459 | if (NONROOT_SERVER(source) && NONROOT_SERVER(dest)) { |
---|
1460 | if (source < dest) |
---|
1461 | return USE_SOURCE; |
---|
1462 | return USE_DEST; |
---|
1463 | } |
---|
1464 | if (NONROOT_SERVER(source) && !NONROOT_SERVER(dest)) |
---|
1465 | return USE_SOURCE; |
---|
1466 | if (!NONROOT_SERVER(source) && NONROOT_SERVER(dest)) |
---|
1467 | return USE_DEST; |
---|
1468 | |
---|
1469 | /* root client */ |
---|
1470 | if (ROOT_CLIENT(source) && ROOT_CLIENT(dest)) { |
---|
1471 | if (source < dest) |
---|
1472 | return USE_SOURCE; |
---|
1473 | return USE_DEST; |
---|
1474 | } |
---|
1475 | if (ROOT_CLIENT(source) && !ROOT_CLIENT(dest)) { |
---|
1476 | /* prefer root-client over nonroot-client */ |
---|
1477 | if (NONROOT_CLIENT(dest)) |
---|
1478 | return USE_SOURCE; |
---|
1479 | return USE_DEST; |
---|
1480 | } |
---|
1481 | if (!ROOT_CLIENT(source) && ROOT_CLIENT(dest)) { |
---|
1482 | /* prefer root-client over nonroot-client */ |
---|
1483 | if (NONROOT_CLIENT(source)) |
---|
1484 | return USE_DEST; |
---|
1485 | return USE_SOURCE; |
---|
1486 | } |
---|
1487 | |
---|
1488 | /* nonroot client */ |
---|
1489 | if (NONROOT_CLIENT(source) && NONROOT_CLIENT(dest)) { |
---|
1490 | if (source < dest) |
---|
1491 | return USE_SOURCE; |
---|
1492 | return USE_DEST; |
---|
1493 | } |
---|
1494 | if (NONROOT_CLIENT(source) && !NONROOT_CLIENT(dest)) |
---|
1495 | return USE_DEST; |
---|
1496 | if (!NONROOT_CLIENT(source) && NONROOT_CLIENT(dest)) |
---|
1497 | return USE_SOURCE; |
---|
1498 | |
---|
1499 | /* dynamic range */ |
---|
1500 | if (DYNAMIC(source) && DYNAMIC(dest)) |
---|
1501 | if (source < dest) |
---|
1502 | return USE_SOURCE; |
---|
1503 | return USE_DEST; |
---|
1504 | if (DYNAMIC(source) && !DYNAMIC(dest)) |
---|
1505 | return USE_DEST; |
---|
1506 | if (!DYNAMIC(source) && DYNAMIC(dest)) |
---|
1507 | return USE_SOURCE; |
---|
1508 | /* |
---|
1509 | if (SERVER(source) && CLIENT(dest)) |
---|
1510 | return USE_SOURCE; |
---|
1511 | |
---|
1512 | if (SERVER(dest) && CLIENT(source)) |
---|
1513 | return USE_DEST; |
---|
1514 | if (ROOT_SERVER(source) && !ROOT_SERVER(dest)) |
---|
1515 | return USE_SOURCE; |
---|
1516 | if (ROOT_SERVER(dest) && !ROOT_SERVER(source)) |
---|
1517 | return USE_DEST; |
---|
1518 | */ |
---|
1519 | /* failing that test... */ |
---|
1520 | if (source < dest) { |
---|
1521 | return USE_SOURCE; |
---|
1522 | } |
---|
1523 | return USE_DEST; |
---|
1524 | |
---|
1525 | } |
---|
1526 | |
---|
1527 | /* Truncate the packet at the suggested length |
---|
1528 | * @param packet the packet opaque pointer |
---|
1529 | * @param size the new length of the packet |
---|
1530 | * @returns the new size of the packet |
---|
1531 | * @note size and the return size refer to the network-level payload of the |
---|
1532 | * packet, and do not include any capture headers. For example, to truncate a |
---|
1533 | * packet after the IP header, set size to sizeof(ethernet_header) + |
---|
1534 | * sizeof(ip_header) |
---|
1535 | * @note If the original network-level payload is smaller than size, then the |
---|
1536 | * original size is returned and the packet is left unchanged. |
---|
1537 | * @author Daniel Lawson |
---|
1538 | */ |
---|
1539 | size_t trace_set_capture_length(struct libtrace_packet_t *packet, size_t size) { |
---|
1540 | assert(packet); |
---|
1541 | assert(packet->size>0 && packet->size<65536); |
---|
1542 | |
---|
1543 | if (packet->trace->format->set_capture_length) { |
---|
1544 | int caplen=packet->trace->format->set_capture_length(packet,size); |
---|
1545 | if (caplen!=-1) { |
---|
1546 | packet->size=trace_get_framing_length(packet)+caplen; |
---|
1547 | } |
---|
1548 | return caplen; |
---|
1549 | } |
---|
1550 | |
---|
1551 | return -1; |
---|
1552 | } |
---|
1553 | |
---|
1554 | const char * trace_parse_uri(const char *uri, char **format) { |
---|
1555 | const char *uridata = 0; |
---|
1556 | |
---|
1557 | if((uridata = strchr(uri,':')) == NULL) { |
---|
1558 | /* badly formed URI - needs a : */ |
---|
1559 | return 0; |
---|
1560 | } |
---|
1561 | |
---|
1562 | if ((uridata - uri) > URI_PROTO_LINE) { |
---|
1563 | /* badly formed URI - uri type is too long */ |
---|
1564 | return 0; |
---|
1565 | } |
---|
1566 | |
---|
1567 | *format=xstrndup(uri, (uridata - uri)); |
---|
1568 | |
---|
1569 | /* push uridata past the delimiter */ |
---|
1570 | uridata++; |
---|
1571 | |
---|
1572 | return uridata; |
---|
1573 | } |
---|
1574 | |
---|
1575 | enum base_format_t trace_get_format(struct libtrace_packet_t *packet) |
---|
1576 | { |
---|
1577 | assert(packet); |
---|
1578 | |
---|
1579 | return packet->trace->format->type; |
---|
1580 | } |
---|
1581 | |
---|
1582 | libtrace_err_t trace_get_err(libtrace_t *trace) |
---|
1583 | { |
---|
1584 | libtrace_err_t err = trace->err; |
---|
1585 | trace->err.err_num = 0; /* "OK" */ |
---|
1586 | trace->err.problem[0]='\0'; |
---|
1587 | return err; |
---|
1588 | } |
---|
1589 | |
---|
1590 | libtrace_err_t trace_get_err_output(libtrace_out_t *trace) |
---|
1591 | { |
---|
1592 | libtrace_err_t err = trace->err; |
---|
1593 | trace->err.err_num = 0; /* "OK" */ |
---|
1594 | trace->err.problem[0]='\0'; |
---|
1595 | return err; |
---|
1596 | } |
---|