mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-10-01 21:46:42 +03:00
network: avoid inet_ntoa() in favor of inet_ntop()
inet_ntop() is not documented to be thread-safe, so it should not be used in the DHCP library. Arguably, glibc uses a thread local buffer, so indeed there is no problem with a suitable libc. Anyway, just avoid it.
This commit is contained in:
@@ -428,13 +428,15 @@ size_t serialize_in_addrs(FILE *f,
|
|||||||
count = 0;
|
count = 0;
|
||||||
|
|
||||||
for (i = 0; i < size; i++) {
|
for (i = 0; i < size; i++) {
|
||||||
|
char sbuf[INET_ADDRSTRLEN];
|
||||||
|
|
||||||
if (predicate && !predicate(&addresses[i]))
|
if (predicate && !predicate(&addresses[i]))
|
||||||
continue;
|
continue;
|
||||||
if (with_leading_space)
|
if (with_leading_space)
|
||||||
fputc(' ', f);
|
fputc(' ', f);
|
||||||
else
|
else
|
||||||
with_leading_space = true;
|
with_leading_space = true;
|
||||||
fputs(inet_ntoa(addresses[i]), f);
|
fputs(inet_ntop(AF_INET, &addresses[i], sbuf, sizeof(sbuf)), f);
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -541,6 +543,7 @@ void serialize_dhcp_routes(FILE *f, const char *key, sd_dhcp_route **routes, siz
|
|||||||
fprintf(f, "%s=", key);
|
fprintf(f, "%s=", key);
|
||||||
|
|
||||||
for (i = 0; i < size; i++) {
|
for (i = 0; i < size; i++) {
|
||||||
|
char sbuf[INET_ADDRSTRLEN];
|
||||||
struct in_addr dest, gw;
|
struct in_addr dest, gw;
|
||||||
uint8_t length;
|
uint8_t length;
|
||||||
|
|
||||||
@@ -548,8 +551,8 @@ 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_gateway(routes[i], &gw) >= 0);
|
||||||
assert_se(sd_dhcp_route_get_destination_prefix_length(routes[i], &length) >= 0);
|
assert_se(sd_dhcp_route_get_destination_prefix_length(routes[i], &length) >= 0);
|
||||||
|
|
||||||
fprintf(f, "%s/%" PRIu8, inet_ntoa(dest), length);
|
fprintf(f, "%s/%" PRIu8, inet_ntop(AF_INET, &dest, sbuf, sizeof(sbuf)), length);
|
||||||
fprintf(f, ",%s%s", inet_ntoa(gw), (i < (size - 1)) ? " ": "");
|
fprintf(f, ",%s%s", inet_ntop(AF_INET, &gw, sbuf, sizeof(sbuf)), (i < (size - 1)) ? " ": "");
|
||||||
}
|
}
|
||||||
|
|
||||||
fputs("\n", f);
|
fputs("\n", f);
|
||||||
|
@@ -814,6 +814,7 @@ int dhcp_lease_save(sd_dhcp_lease *lease, const char *lease_file) {
|
|||||||
const struct in_addr *addresses;
|
const struct in_addr *addresses;
|
||||||
const void *client_id, *data;
|
const void *client_id, *data;
|
||||||
size_t client_id_len, data_len;
|
size_t client_id_len, data_len;
|
||||||
|
char sbuf[INET_ADDRSTRLEN];
|
||||||
const char *string;
|
const char *string;
|
||||||
uint16_t mtu;
|
uint16_t mtu;
|
||||||
_cleanup_free_ sd_dhcp_route **routes = NULL;
|
_cleanup_free_ sd_dhcp_route **routes = NULL;
|
||||||
@@ -836,11 +837,11 @@ int dhcp_lease_save(sd_dhcp_lease *lease, const char *lease_file) {
|
|||||||
|
|
||||||
r = sd_dhcp_lease_get_address(lease, &address);
|
r = sd_dhcp_lease_get_address(lease, &address);
|
||||||
if (r >= 0)
|
if (r >= 0)
|
||||||
fprintf(f, "ADDRESS=%s\n", inet_ntoa(address));
|
fprintf(f, "ADDRESS=%s\n", inet_ntop(AF_INET, &address, sbuf, sizeof(sbuf)));
|
||||||
|
|
||||||
r = sd_dhcp_lease_get_netmask(lease, &address);
|
r = sd_dhcp_lease_get_netmask(lease, &address);
|
||||||
if (r >= 0)
|
if (r >= 0)
|
||||||
fprintf(f, "NETMASK=%s\n", inet_ntoa(address));
|
fprintf(f, "NETMASK=%s\n", inet_ntop(AF_INET, &address, sbuf, sizeof(sbuf)));
|
||||||
|
|
||||||
r = sd_dhcp_lease_get_router(lease, &addresses);
|
r = sd_dhcp_lease_get_router(lease, &addresses);
|
||||||
if (r > 0) {
|
if (r > 0) {
|
||||||
@@ -851,15 +852,15 @@ int dhcp_lease_save(sd_dhcp_lease *lease, const char *lease_file) {
|
|||||||
|
|
||||||
r = sd_dhcp_lease_get_server_identifier(lease, &address);
|
r = sd_dhcp_lease_get_server_identifier(lease, &address);
|
||||||
if (r >= 0)
|
if (r >= 0)
|
||||||
fprintf(f, "SERVER_ADDRESS=%s\n", inet_ntoa(address));
|
fprintf(f, "SERVER_ADDRESS=%s\n", inet_ntop(AF_INET, &address, sbuf, sizeof(sbuf)));
|
||||||
|
|
||||||
r = sd_dhcp_lease_get_next_server(lease, &address);
|
r = sd_dhcp_lease_get_next_server(lease, &address);
|
||||||
if (r >= 0)
|
if (r >= 0)
|
||||||
fprintf(f, "NEXT_SERVER=%s\n", inet_ntoa(address));
|
fprintf(f, "NEXT_SERVER=%s\n", inet_ntop(AF_INET, &address, sbuf, sizeof(sbuf)));
|
||||||
|
|
||||||
r = sd_dhcp_lease_get_broadcast(lease, &address);
|
r = sd_dhcp_lease_get_broadcast(lease, &address);
|
||||||
if (r >= 0)
|
if (r >= 0)
|
||||||
fprintf(f, "BROADCAST=%s\n", inet_ntoa(address));
|
fprintf(f, "BROADCAST=%s\n", inet_ntop(AF_INET, &address, sbuf, sizeof(sbuf)));
|
||||||
|
|
||||||
r = sd_dhcp_lease_get_mtu(lease, &mtu);
|
r = sd_dhcp_lease_get_mtu(lease, &mtu);
|
||||||
if (r >= 0)
|
if (r >= 0)
|
||||||
|
Reference in New Issue
Block a user