Skip to content

Commit 4e0cf0a

Browse files
committed
Added new function for variable-length IE IPFIX export
1 parent 30cfb48 commit 4e0cf0a

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

include/ipfixprobe/utils.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ namespace ipxp {
5858
void parse_range(const std::string &arg, std::string &from, std::string &to, const std::string &delim = "-");
5959
bool str2bool(std::string str);
6060
void trim_str(std::string &str);
61+
uint32_t variable2ipfix_buffer(uint8_t* buffer2write, uint8_t* buffer2read, uint16_t len);
6162

6263
template<typename T> constexpr
6364
T const& max(const T &a, const T &b) {

utils.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* \file utils.cpp
33
* \brief Utility functions source
44
* \author Jiri Havranek <[email protected]>
5+
* \author Karel Hynek <[email protected]>
56
* \date 2021
67
*/
78
/*
@@ -43,6 +44,8 @@
4344

4445
#include <string>
4546
#include <utility>
47+
#include <cstring>
48+
#include <arpa/inet.h>
4649

4750
#include <ipfixprobe/utils.hpp>
4851

@@ -105,4 +108,19 @@ uint64_t pntoh64(const void *p)
105108
return buffer;
106109
}
107110

111+
112+
uint32_t variable2ipfix_buffer(uint8_t* buffer2write, uint8_t* buffer2read, uint16_t len)
113+
{
114+
uint32_t ptr = 0;
115+
if (len >= 255) {
116+
buffer2write[ptr++] = 255;
117+
*(uint16_t *)(buffer2write + ptr) = ntohs(len);
118+
ptr += sizeof(uint16_t);
119+
} else {
120+
buffer2write[ptr++] = len;
121+
}
122+
std::memcpy(buffer2write + ptr, buffer2read, len);
123+
return ptr + len;
124+
}
125+
108126
}

0 commit comments

Comments
 (0)