Skip to content

Commit 4c9b2aa

Browse files
author
Damir Zainullin
committed
++
1 parent f75925a commit 4c9b2aa

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

include/ipfixprobe/utils.hpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,54 @@ std::string vec2str(const std::vector<T>& vec)
179179
*/
180180
void memcpy_le32toh(uint32_t* dest, const uint32_t* src);
181181

182+
constexpr static inline
183+
timeval operator+(const timeval& a, const timeval& b) noexcept
184+
{
185+
constexpr time_t USEC_IN_SEC = 1'000'000;
186+
187+
timeval result{};
188+
result.tv_sec = a.tv_sec + b.tv_sec;
189+
result.tv_usec = a.tv_usec + b.tv_usec;
190+
if (result.tv_usec >= USEC_IN_SEC) {
191+
result.tv_sec++;
192+
result.tv_usec -= USEC_IN_SEC;
193+
}
194+
return result;
195+
}
196+
197+
constexpr static inline
198+
timeval operator-(const timeval& a) noexcept
199+
{
200+
timeval result{};
201+
result.tv_sec = -a.tv_sec;
202+
result.tv_usec = -a.tv_usec;
203+
return result;
204+
}
205+
206+
constexpr static inline
207+
timeval operator-(const timeval& a, const timeval& b) noexcept
208+
{
209+
return a + (-b);
210+
}
211+
212+
constexpr static inline
213+
bool operator>(const timeval& a, const timeval& b) noexcept
214+
{
215+
return std::tie(a.tv_sec, a.tv_usec) > std::tie(b.tv_sec, b.tv_usec);
216+
}
217+
218+
constexpr static inline
219+
bool operator<(const timeval& a, const timeval& b) noexcept
220+
{
221+
return std::tie(a.tv_sec, a.tv_usec) < std::tie(b.tv_sec, b.tv_usec);
222+
}
223+
224+
constexpr static inline
225+
bool operator==(const timeval& a, const timeval& b) noexcept
226+
{
227+
return not (a < b) and not (b < a);
228+
}
229+
182230
} // namespace ipxp
183231

184232
#endif /* IPXP_UTILS_HPP */

process-plugin-api/packet.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
11
#pragma once
22

33
#include <cstdint>
4+
#include <sys/time.h>
5+
46
#include "directionalField.hpp"
57
#include "tcpFlags.hpp"
68

79
namespace ipxp
810
{
911

1012
struct Packet {
13+
timeval timestamp;
1114
uint8_t ipTtl;
1215
uint8_t ipFlags;
1316
uint16_t ipLength;
1417
uint16_t tcpWindow;
1518
uint64_t tcpOptions;
1619
uint32_t tcpMss;
1720
TcpFlags tcpFlags;
21+
22+
uint32_t actualLength;
23+
uint32_t receivedLength;
24+
1825
};
1926

2027
} // namespace ipxp

0 commit comments

Comments
 (0)