-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.cc
More file actions
33 lines (30 loc) · 878 Bytes
/
utils.cc
File metadata and controls
33 lines (30 loc) · 878 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/* Name: Thao Nguyen
Case Network ID: ttn60
The filename: utils.cc
Date created: Oct 28, 2025
Description: Implementation of utility functions.
*/
#include "utils.h"
#include <sstream>
#include <iomanip>
std::string dotted_quad(uint32_t ip) {
return std::to_string((ip >> 24) & 0xFF) + "." +
std::to_string((ip >> 16) & 0xFF) + "." +
std::to_string((ip >> 8) & 0xFF) + "." +
std::to_string(ip & 0xFF);
}
std::string format_ts(timev time) {
std::ostringstream oss;
oss << time.tv_sec << '.'
<< std::setw(6) << std::setfill('0') << time.tv_usec;
return oss.str();
}
timev deduct_tv(timev tv, timev deduct_by) {
int32_t sec = tv.tv_sec - deduct_by.tv_sec;
int32_t usec = tv.tv_usec - deduct_by.tv_usec;
if (usec < 0) {
sec -= 1;
usec += 1000000;
}
return timev{sec, usec};
}