]> The Tcpdump Group git mirrors - tcpslice/blob - tcpslice.h
Use TS_RAW_US_MAX_DIGITS in parse_time().
[tcpslice] / tcpslice.h
1 /*
2 * Copyright (c) 1993, 1995
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
16 * written permission.
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 */
21
22 #ifndef TCPSLICE_H
23 #define TCPSLICE_H
24
25 #include "compiler-tests.h"
26
27 #include "varattrs.h"
28
29 /*
30 * If we're compiling with Visual Studio, make sure we have at least
31 * VS 2015 or later, so we have sufficient C99 support.
32 *
33 * XXX - verify that we have at least C99 support on UN*Xes?
34 *
35 * What about MinGW or various DOS toolchains? We're currently assuming
36 * sufficient C99 support there.
37 */
38 #if defined(_MSC_VER)
39 /*
40 * Make sure we have VS 2015 or later.
41 */
42 #if _MSC_VER < 1900
43 #error "Building tcpslice requires VS 2015 or later"
44 #endif
45 #endif
46
47 /*
48 * Get the C99 types, and the PRI[doux]64 format strings, defined.
49 */
50 #ifdef HAVE_PCAP_PCAP_INTTYPES_H
51 /*
52 * We have pcap/pcap-inttypes.h; use that, as it'll do all the
53 * work, and won't cause problems if a file includes this file
54 * and later includes a pcap header file that also includes
55 * pcap/pcap-inttypes.h.
56 */
57 #include <pcap/pcap-inttypes.h>
58 #else
59 /*
60 * OK, we don't have pcap/pcap-inttypes.h, so we'll have to
61 * do the work ourselves, but at least we don't have to
62 * worry about other headers including it and causing
63 * clashes.
64 */
65
66 /*
67 * Include <inttypes.h> to get the integer types and PRI[doux]64 values
68 * defined.
69 *
70 * If the compiler is MSVC, we require VS 2015 or newer, so we
71 * have <inttypes.h> - and support for %zu in the formatted
72 * printing functions.
73 *
74 * If the compiler is MinGW, we assume we have <inttypes.h> - and
75 * support for %zu in the formatted printing functions.
76 *
77 * If the target is UN*X, we assume we have a C99-or-later development
78 * environment, and thus have <inttypes.h> - and support for %zu in
79 * the formatted printing functions.
80 *
81 * If the target is MS-DOS, we assume we have <inttypes.h> - and support
82 * for %zu in the formatted printing functions.
83 */
84 #include <inttypes.h>
85
86 #if defined(_MSC_VER)
87 /*
88 * Suppress definition of intN_t in bittypes.h, which might be included
89 * by <pcap/pcap.h> in older versions of WinPcap.
90 * (Yes, HAVE_U_INTn_T, as the definition guards are UN*X-oriented.)
91 */
92 #define HAVE_U_INT8_T
93 #define HAVE_U_INT16_T
94 #define HAVE_U_INT32_T
95 #define HAVE_U_INT64_T
96 #endif
97 #endif /* HAVE_PCAP_PCAP_INTTYPES_H */
98
99 #include <time.h>
100 #include <sys/types.h>
101 #include <sys/time.h>
102 #include <pcap.h>
103
104 #define IS_LEAP_YEAR(year) \
105 ((year) % 4 == 0 && ((year) % 100 != 0 || (year) % 400 == 0))
106
107 /*
108 * OpenBSD libpcap compensation: in struct pcap_pkthdr "ts" instead of struct
109 * timeval uses struct bpf_timeval, which declares members with the same names
110 * and a different type, which is a 32-bit unsigned, whilst on 64-bit systems
111 * struct timeval uses a 64-bit integer type.
112 */
113 #define TIMEVAL_FROM_PKTHDR_TS(dst, src) { \
114 (dst).tv_sec = (src).tv_sec; \
115 (dst).tv_usec = (src).tv_usec; \
116 }
117
118 extern const int days_in_month[];
119 time_t gwtm2secs( const struct tm *tm );
120
121 int sf_find_end( struct pcap *p, const struct timeval *first_timestamp,
122 struct timeval *last_timestamp );
123 int sf_timestamp_less_than( const struct timeval *t1, const struct timeval *t2 );
124 int sf_find_packet( struct pcap *p,
125 struct timeval *min_time, int64_t min_pos,
126 struct timeval *max_time, int64_t max_pos,
127 const struct timeval *desired_time );
128
129 int fseek64(FILE *p, const int64_t offset, const int whence);
130 int64_t ftell64(FILE *p);
131 extern char *timestamp_to_string(const struct timeval *timestamp);
132
133 void error(const char *fmt, ...);
134 void warning(const char *fmt, ...);
135
136 extern pcap_dumper_t *global_dumper;
137 #endif /* TCPSLICE_H */