diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2022-06-03 11:24:02 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2022-06-06 09:52:52 +0200 |
commit | 84dbb3fd83ef7d7e5b2ea02be1f492974384256c (patch) | |
tree | 8b709e5d9f164c9b8297a08dc328bd9c92e01d83 /src/libsystemd-network/test-ipv4ll-manual.c | |
parent | b547241728487c0dca22780241b04964f2eb37af (diff) | |
download | systemd-84dbb3fd83ef7d7e5b2ea02be1f492974384256c.tar.gz |
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.
Diffstat (limited to 'src/libsystemd-network/test-ipv4ll-manual.c')
-rw-r--r-- | src/libsystemd-network/test-ipv4ll-manual.c | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/src/libsystemd-network/test-ipv4ll-manual.c b/src/libsystemd-network/test-ipv4ll-manual.c index 3fea894f30..e79758c5f5 100644 --- a/src/libsystemd-network/test-ipv4ll-manual.c +++ b/src/libsystemd-network/test-ipv4ll-manual.c @@ -19,23 +19,20 @@ #include "util.h" static void ll_handler(sd_ipv4ll *ll, int event, void *userdata) { - _cleanup_free_ char *address = NULL; - struct in_addr addr = {}; - assert_se(ll); - if (sd_ipv4ll_get_address(ll, &addr) >= 0) - assert_se(in_addr_to_string(AF_INET, (const union in_addr_union*) &addr, &address) >= 0); + struct in_addr addr; + const char *pretty = sd_ipv4ll_get_address(ll, &addr) >= 0 ? IN4_ADDR_TO_STRING(&addr) : NULL; switch (event) { case SD_IPV4LL_EVENT_BIND: - log_info("bound %s", strna(address)); + log_info("bound %s", strna(pretty)); break; case SD_IPV4LL_EVENT_CONFLICT: - log_info("conflict on %s", strna(address)); + log_info("conflict on %s", strna(pretty)); break; case SD_IPV4LL_EVENT_STOP: - log_error("the client was stopped with address %s", strna(address)); + log_error("the client was stopped with address %s", strna(pretty)); break; default: assert_not_reached(); |