diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2022-06-04 17:01:06 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2022-06-06 09:52:52 +0200 |
commit | 071e522eec2d4f5f29ef929db4bf40af1860fdac (patch) | |
tree | 4915ed22fc9a2be9a99f4ebc9c2595b16724347c /src | |
parent | basic/in-addr-util: add IN_ADDR_PREFIX_TO_STRING (diff) | |
download | systemd-071e522eec2d4f5f29ef929db4bf40af1860fdac.tar.xz systemd-071e522eec2d4f5f29ef929db4bf40af1860fdac.zip |
tree-wide: convert inet_ntop() calls to anonymous-buffer macros
Diffstat (limited to 'src')
-rw-r--r-- | src/basic/socket-util.c | 4 | ||||
-rw-r--r-- | src/core/socket.c | 6 | ||||
-rw-r--r-- | src/libsystemd-network/network-internal.c | 15 | ||||
-rw-r--r-- | src/libsystemd-network/sd-dhcp-lease.c | 11 | ||||
-rw-r--r-- | src/libsystemd-network/test-ndisc-rs.c | 9 | ||||
-rw-r--r-- | src/machine/machinectl.c | 9 |
6 files changed, 19 insertions, 35 deletions
diff --git a/src/basic/socket-util.c b/src/basic/socket-util.c index bd6d329d94..4925fd093e 100644 --- a/src/basic/socket-util.c +++ b/src/basic/socket-util.c @@ -490,9 +490,7 @@ int sockaddr_pretty( if (r < 0) return -ENOMEM; } else { - char a[INET6_ADDRSTRLEN]; - - inet_ntop(AF_INET6, &sa->in6.sin6_addr, a, sizeof(a)); + const char *a = IN6_ADDR_TO_STRING(&sa->in6.sin6_addr); if (include_port) { if (asprintf(&p, diff --git a/src/core/socket.c b/src/core/socket.c index 0d96f1a933..af39553001 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -858,14 +858,12 @@ static int instance_from_socket(int fd, unsigned nr, char **instance) { be16toh(remote.in6.sin6_port)) < 0) return -ENOMEM; } else { - char a[INET6_ADDRSTRLEN], b[INET6_ADDRSTRLEN]; - if (asprintf(&r, "%u-%s:%u-%s:%u", nr, - inet_ntop(AF_INET6, &local.in6.sin6_addr, a, sizeof(a)), + IN6_ADDR_TO_STRING(&local.in6.sin6_addr), be16toh(local.in6.sin6_port), - inet_ntop(AF_INET6, &remote.in6.sin6_addr, b, sizeof(b)), + IN6_ADDR_TO_STRING(&remote.in6.sin6_addr), be16toh(remote.in6.sin6_port)) < 0) return -ENOMEM; } diff --git a/src/libsystemd-network/network-internal.c b/src/libsystemd-network/network-internal.c index bc7aec2f9d..cd32a7247a 100644 --- a/src/libsystemd-network/network-internal.c +++ b/src/libsystemd-network/network-internal.c @@ -28,14 +28,12 @@ size_t serialize_in_addrs(FILE *f, with_leading_space = &_space; for (size_t i = 0; i < size; i++) { - char sbuf[INET_ADDRSTRLEN]; - if (predicate && !predicate(&addresses[i])) continue; if (*with_leading_space) fputc(' ', f); - fputs(inet_ntop(AF_INET, &addresses[i], sbuf, sizeof(sbuf)), f); + fputs(IN4_ADDR_TO_STRING(&addresses[i]), f); count++; *with_leading_space = true; } @@ -89,11 +87,9 @@ void serialize_in6_addrs(FILE *f, const struct in6_addr *addresses, size_t size, with_leading_space = &_space; for (size_t i = 0; i < size; i++) { - char buffer[INET6_ADDRSTRLEN]; - if (*with_leading_space) fputc(' ', f); - fputs(inet_ntop(AF_INET6, addresses+i, buffer, sizeof(buffer)), f); + fputs(IN6_ADDR_TO_STRING(&addresses[i]), f); *with_leading_space = true; } } @@ -143,7 +139,6 @@ void serialize_dhcp_routes(FILE *f, const char *key, sd_dhcp_route **routes, siz fprintf(f, "%s=", key); for (size_t i = 0; i < size; i++) { - char sbuf[INET_ADDRSTRLEN]; struct in_addr dest, gw; uint8_t length; @@ -151,8 +146,10 @@ void serialize_dhcp_routes(FILE *f, const char *key, sd_dhcp_route **routes, siz assert_se(sd_dhcp_route_get_gateway(routes[i], &gw) >= 0); assert_se(sd_dhcp_route_get_destination_prefix_length(routes[i], &length) >= 0); - fprintf(f, "%s/%" PRIu8, inet_ntop(AF_INET, &dest, sbuf, sizeof sbuf), length); - fprintf(f, ",%s%s", inet_ntop(AF_INET, &gw, sbuf, sizeof sbuf), i < size - 1 ? " ": ""); + fprintf(f, "%s,%s%s", + IN4_ADDR_PREFIX_TO_STRING(&dest, length), + IN4_ADDR_TO_STRING(&gw), + i < size - 1 ? " ": ""); } fputs("\n", f); diff --git a/src/libsystemd-network/sd-dhcp-lease.c b/src/libsystemd-network/sd-dhcp-lease.c index 8de7c671df..acc57ce53a 100644 --- a/src/libsystemd-network/sd-dhcp-lease.c +++ b/src/libsystemd-network/sd-dhcp-lease.c @@ -967,7 +967,6 @@ int dhcp_lease_save(sd_dhcp_lease *lease, const char *lease_file) { const struct in_addr *addresses; const void *client_id, *data; size_t client_id_len, data_len; - char sbuf[INET_ADDRSTRLEN]; const char *string; uint16_t mtu; _cleanup_free_ sd_dhcp_route **routes = NULL; @@ -989,11 +988,11 @@ int dhcp_lease_save(sd_dhcp_lease *lease, const char *lease_file) { r = sd_dhcp_lease_get_address(lease, &address); if (r >= 0) - fprintf(f, "ADDRESS=%s\n", inet_ntop(AF_INET, &address, sbuf, sizeof(sbuf))); + fprintf(f, "ADDRESS=%s\n", IN4_ADDR_TO_STRING(&address)); r = sd_dhcp_lease_get_netmask(lease, &address); if (r >= 0) - fprintf(f, "NETMASK=%s\n", inet_ntop(AF_INET, &address, sbuf, sizeof(sbuf))); + fprintf(f, "NETMASK=%s\n", IN4_ADDR_TO_STRING(&address)); r = sd_dhcp_lease_get_router(lease, &addresses); if (r > 0) { @@ -1004,15 +1003,15 @@ int dhcp_lease_save(sd_dhcp_lease *lease, const char *lease_file) { r = sd_dhcp_lease_get_server_identifier(lease, &address); if (r >= 0) - fprintf(f, "SERVER_ADDRESS=%s\n", inet_ntop(AF_INET, &address, sbuf, sizeof(sbuf))); + fprintf(f, "SERVER_ADDRESS=%s\n", IN4_ADDR_TO_STRING(&address)); r = sd_dhcp_lease_get_next_server(lease, &address); if (r >= 0) - fprintf(f, "NEXT_SERVER=%s\n", inet_ntop(AF_INET, &address, sbuf, sizeof(sbuf))); + fprintf(f, "NEXT_SERVER=%s\n", IN4_ADDR_TO_STRING(&address)); r = sd_dhcp_lease_get_broadcast(lease, &address); if (r >= 0) - fprintf(f, "BROADCAST=%s\n", inet_ntop(AF_INET, &address, sbuf, sizeof(sbuf))); + fprintf(f, "BROADCAST=%s\n", IN4_ADDR_TO_STRING(&address)); r = sd_dhcp_lease_get_mtu(lease, &mtu); if (r >= 0) diff --git a/src/libsystemd-network/test-ndisc-rs.c b/src/libsystemd-network/test-ndisc-rs.c index 13db49ea4d..3c679f60b5 100644 --- a/src/libsystemd-network/test-ndisc-rs.c +++ b/src/libsystemd-network/test-ndisc-rs.c @@ -105,7 +105,6 @@ static void router_dump(sd_ndisc_router *rt) { unsigned prefix_len; uint8_t pfl; struct in6_addr a; - char buff[INET6_ADDRSTRLEN]; assert_se(sd_ndisc_router_prefix_get_valid_lifetime(rt, &lifetime_valid) >= 0); log_info("Valid Lifetime: %" PRIu32, lifetime_valid); @@ -122,7 +121,7 @@ static void router_dump(sd_ndisc_router *rt) { log_info("Prefix Length: %u", prefix_len); assert_se(sd_ndisc_router_prefix_get_address(rt, &a) >= 0); - log_info("Prefix: %s", inet_ntop(AF_INET6, &a, buff, sizeof(buff))); + log_info("Prefix: %s", IN6_ADDR_TO_STRING(&a)); break; } @@ -135,10 +134,8 @@ static void router_dump(sd_ndisc_router *rt) { n = sd_ndisc_router_rdnss_get_addresses(rt, &a); assert_se(n > 0); - for (i = 0; i < n; i++) { - char buff[INET6_ADDRSTRLEN]; - log_info("DNS: %s", inet_ntop(AF_INET6, a + i, buff, sizeof(buff))); - } + for (i = 0; i < n; i++) + log_info("DNS: %s", IN6_ADDR_TO_STRING(a + i)); assert_se(sd_ndisc_router_rdnss_get_lifetime(rt, <) >= 0); log_info("Lifetime: %" PRIu32, lt); diff --git a/src/machine/machinectl.c b/src/machine/machinectl.c index 64233b89c0..ac2a244967 100644 --- a/src/machine/machinectl.c +++ b/src/machine/machinectl.c @@ -192,7 +192,7 @@ static int call_get_addresses( int family; const void *a; size_t sz; - char buf_ifi[DECIMAL_STR_MAX(int) + 2], buffer[MAX(INET6_ADDRSTRLEN, INET_ADDRSTRLEN)]; + char buf_ifi[1 + DECIMAL_STR_MAX(int)] = ""; r = sd_bus_message_read(reply, "i", &family); if (r < 0) @@ -204,13 +204,8 @@ static int call_get_addresses( if (family == AF_INET6 && ifi > 0) xsprintf(buf_ifi, "%%%i", ifi); - else - strcpy(buf_ifi, ""); - if (!strextend(&addresses, - prefix, - inet_ntop(family, a, buffer, sizeof(buffer)), - buf_ifi)) + if (!strextend(&addresses, prefix, IN_ADDR_TO_STRING(family, a), buf_ifi)) return log_oom(); r = sd_bus_message_exit_container(reply); |