basic/in-addr-util: add IN_ADDR_TO_STRING

Since we don't need the error value, and the buffer is allocated with a fixed
size, the whole logic provided by in_addr_to_string() becomes unnecessary, so
it's enough to wrap inet_ntop() directly.

inet_ntop() can only fail with ENOSPC. But we specify a buffer that is supposed
to be large enough, so this should never fail. A bunch of tests of this are added.
This allows all the wrappers like strna(), strnull(), strempty() to be dropped.

The guard of 'if (DEBUG_LOGGING)' can be dropped from around log_debug(),
because log_debug() implements the check outside of the function call. But
log_link_debug() does not, so it we need it to avoid unnecessary evaluation of
the formatting.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2022-06-06 09:52:52 +02:00
parent b547241728
commit 84dbb3fd83
23 changed files with 98 additions and 134 deletions
+1 -6
View File
@@ -141,14 +141,9 @@ int expose_port_execute(sd_netlink *rtnl, FirewallContext **fw_ctx, ExposePort *
if (in_addr_equal(af, exposed, &new_exposed))
return 0;
if (DEBUG_LOGGING) {
_cleanup_free_ char *pretty = NULL;
in_addr_to_string(af, &new_exposed, &pretty);
log_debug("New container IP is %s.", strna(pretty));
}
log_debug("New container IP is %s.", IN_ADDR_TO_STRING(af, &new_exposed));
LIST_FOREACH(ports, p, l) {
r = fw_add_local_dnat(fw_ctx,
true,
af,