mirror of
https://github.com/mfontanini/libtins
synced 2026-01-26 03:51:35 +01:00
Move functions to parse /proc/net/routes into utils.cpp
This commit is contained in:
@@ -64,56 +64,6 @@ using Tins::Memory::InputMemoryStream;
|
||||
namespace Tins {
|
||||
namespace Internals {
|
||||
|
||||
bool from_hex(const string& str, uint32_t& result) {
|
||||
size_t i = 0;
|
||||
result = 0;
|
||||
while (i < str.size()) {
|
||||
uint8_t tmp;
|
||||
if (str[i] >= 'A' && str[i] <= 'F') {
|
||||
tmp = (str[i] - 'A' + 10);
|
||||
}
|
||||
else if (str[i] >= '0' && str[i] <= '9') {
|
||||
tmp = (str[i] - '0');
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
result = (result << 4) | tmp;
|
||||
i++;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool from_hex(const string& str, string& result) {
|
||||
result = "";
|
||||
for (size_t i = 0; i < str.size(); i+= 2) {
|
||||
uint8_t value = 0;
|
||||
for (size_t j = i; j < i + 2 && j < str.size(); ++j) {
|
||||
if (str[j] >= 'A' && str[j] <= 'F') {
|
||||
value = (value << 4) | (str[j] - 'A' + 10);
|
||||
}
|
||||
else if (str[j] >= 'a' && str[j] <= 'f') {
|
||||
value = (value << 4) | (str[j] - 'a' + 10);
|
||||
}
|
||||
else if (str[j] >= '0' && str[j] <= '9') {
|
||||
value = (value << 4) | (str[j] - '0');
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
result.push_back(value);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void skip_line(std::istream& input) {
|
||||
int c = 0;
|
||||
while (c != '\n' && input) {
|
||||
c = input.get();
|
||||
}
|
||||
}
|
||||
|
||||
Tins::PDU* pdu_from_flag(Constants::Ethernet::e flag,
|
||||
const uint8_t* buffer,
|
||||
uint32_t size,
|
||||
|
||||
Reference in New Issue
Block a user