make IPBUFFER_MAXSIZE an enum constant

... instead of a macro constant(which made the code less readable!)

Supposedly it also doesn't use run-time storage.
This commit is contained in:
correabuscar 2022-11-04 10:44:22 +01:00
parent 96a22b4078
commit bad9bbc160
1 changed files with 1 additions and 10 deletions

View File

@ -1391,11 +1391,7 @@ namespace Net {
}
int family = 0;
static_assert(INET6_ADDRSTRLEN >= INET_ADDRSTRLEN); // 46 >= 16, compile-time assurance.
#if defined(IPBUFFER_MAXSIZE)
#error Overwriting a previous macro with the same name: IPBUFFER_MAXSIZE, this means you likely need to rename this one here!
#else
#define IPBUFFER_MAXSIZE (INET6_ADDRSTRLEN) // manually using the known biggest value, guarded by the above static_assert
#endif
enum { IPBUFFER_MAXSIZE = INET6_ADDRSTRLEN }; // manually using the known biggest value, guarded by the above static_assert
char ip[IPBUFFER_MAXSIZE];
interfaces.clear();
string ipv4, ipv6;
@ -1442,11 +1438,6 @@ namespace Net {
}
} //else, ignoring family==AF_PACKET (see man 3 getifaddrs) which is the first one in the `for` loop.
}
#if defined(IPBUFFER_MAXSIZE)
#undef IPBUFFER_MAXSIZE
#else
#error whoa, the programmer forgot something, eg. was this renamed?
#endif
//? Get total recieved and transmitted bytes + device address if no ip was found
for (const auto& iface : interfaces) {