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