nice rendering of IPs

This commit is contained in:
Doug Hoyte
2023-02-07 11:58:17 -05:00
parent 67331a6e6f
commit 79dcceaee0
3 changed files with 28 additions and 9 deletions

17
src/misc.cpp Normal file
View 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);
}