mirror of
https://github.com/hoytech/strfry.git
synced 2025-06-19 17:37:43 +00:00
nice rendering of IPs
This commit is contained in:
17
src/misc.cpp
Normal file
17
src/misc.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include "golpe.h"
|
||||
|
||||
std::string renderIP(std::string_view ipBytes) {
|
||||
char buf[128];
|
||||
|
||||
if (ipBytes.size() == 4) {
|
||||
inet_ntop(AF_INET, ipBytes.data(), buf, sizeof(buf));
|
||||
} else if (ipBytes.size() == 16) {
|
||||
inet_ntop(AF_INET6, ipBytes.data(), buf, sizeof(buf));
|
||||
} else {
|
||||
throw herr("invalid size of ipBytes, unable to render IP");
|
||||
}
|
||||
|
||||
return std::string(buf);
|
||||
}
|
Reference in New Issue
Block a user