/src/PcapPlusPlus/Common++/header/TimespecTimeval.h
Line | Count | Source (jump to first uncovered line) |
1 | | /// these conversion macros are not defined on some of the platforms, including |
2 | | /// Windows |
3 | | #pragma once |
4 | | |
5 | | #ifdef _MSC_VER |
6 | | # include <winsock2.h> |
7 | | # include <time.h> |
8 | | #else |
9 | | # include <sys/time.h> |
10 | | #endif |
11 | | |
12 | | #ifndef TIMEVAL_TO_TIMESPEC |
13 | | # define TIMEVAL_TO_TIMESPEC(tv, ts) \ |
14 | | { \ |
15 | | (ts)->tv_sec = (tv)->tv_sec; \ |
16 | | (ts)->tv_nsec = (tv)->tv_usec * 1000; \ |
17 | | } |
18 | | #endif |
19 | | |
20 | | #ifndef TIMESPEC_TO_TIMEVAL |
21 | | # define TIMESPEC_TO_TIMEVAL(tv, ts) \ |
22 | | { \ |
23 | | (tv)->tv_sec = (ts)->tv_sec; \ |
24 | | (tv)->tv_usec = (ts)->tv_nsec / 1000; \ |
25 | | } |
26 | | #endif |
27 | | |
28 | | namespace pcpp |
29 | | { |
30 | | namespace internal |
31 | | { |
32 | | /// Converts a timeval structure to a timespec structure |
33 | | inline timespec toTimespec(timeval value) |
34 | 0 | { |
35 | 0 | timespec nsec_time = {}; |
36 | 0 | TIMEVAL_TO_TIMESPEC(&value, &nsec_time); |
37 | 0 | return nsec_time; |
38 | 0 | } |
39 | | |
40 | | /// Converts a timespec structure to a timeval structure |
41 | | inline timeval toTimeval(timespec value) |
42 | 1.64k | { |
43 | 1.64k | timeval tv = {}; |
44 | 1.64k | TIMESPEC_TO_TIMEVAL(&tv, &value); |
45 | 1.64k | return tv; |
46 | 1.64k | } |
47 | | } // namespace internal |
48 | | } // namespace pcpp |