Skip to content

Commit 334bda5

Browse files
committed
utils - add function that convert struct timeval to microseconds
1 parent 8c3ee86 commit 334bda5

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

include/ipfixprobe/utils.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,5 +145,11 @@ T str2num(std::string str, typename std::enable_if<is_uint<T>()>::type * = nullp
145145
return static_cast<T>(tmp);
146146
}
147147

148+
/**
149+
* @brief Convert struct Timeval to microseconds
150+
*/
151+
uint64_t timeval2usec(const struct timeval& tv);
152+
148153
}
149-
#endif /* IPXP_UTILS_HPP */
154+
155+
#endif /* IPXP_UTILS_HPP */

utils.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,10 @@ uint32_t variable2ipfix_buffer(uint8_t* buffer2write, uint8_t* buffer2read, uint
132132
return ptr + len;
133133
}
134134

135-
} // namespace ipxp
135+
uint64_t timeval2usec(const struct timeval& tv)
136+
{
137+
constexpr size_t usec_in_sec = 1000000;
138+
return tv.tv_sec * usec_in_sec + tv.tv_usec;
139+
}
140+
141+
} // namespace ipxp

0 commit comments

Comments
 (0)