1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-01-12 09:17:44 +03:00

tree-wide: convert inet_ntop() calls to anonymous-buffer macros

This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2022-06-04 17:01:06 +02:00
parent c71384a9ee
commit 071e522eec
6 changed files with 19 additions and 35 deletions

View File

@ -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,

View File

@ -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;
}

View File

@ -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);

View File

@ -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)

View File

@ -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, &lt) >= 0);
log_info("Lifetime: %" PRIu32, lt);

View File

@ -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);