Commit a51c09dc authored by Thomas Haller's avatar Thomas Haller

all: don't use static buffer for nm_utils_inet*_ntop()

While nm_utils_inet*_ntop() accepts a %NULL buffer to fallback
to a static buffer, don't do that.

I find the possibility of using a static buffer here error prone
and something that should be avoided. There is of course the downside,
that in some cases it requires an additional line of code to allocate
the buffer on the stack as auto-variable.
parent 898f7a56
......@@ -1173,7 +1173,7 @@ nm_utils_ip4_dns_from_variant (GVariant *value)
dns = g_new (char *, length + 1);
for (i = 0; i < length; i++)
dns[i] = g_strdup (nm_utils_inet4_ntop (array[i], NULL));
dns[i] = nm_utils_inet4_ntop_dup (array[i]);
dns[i] = NULL;
return dns;
......@@ -1271,7 +1271,7 @@ nm_utils_ip4_addresses_from_variant (GVariant *value, char **out_gateway)
g_ptr_array_add (addresses, addr);
if (addr_array[2] && out_gateway && !*out_gateway)
*out_gateway = g_strdup (nm_utils_inet4_ntop (addr_array[2], NULL));
*out_gateway = nm_utils_inet4_ntop_dup (addr_array[2]);
} else {
g_warning ("Ignoring invalid IP4 address: %s", error->message);
g_clear_error (&error);
......@@ -1493,7 +1493,7 @@ nm_utils_ip6_dns_from_variant (GVariant *value)
continue;
}
dns[i++] = g_strdup (nm_utils_inet6_ntop (ip, NULL));
dns[i++] = nm_utils_inet6_ntop_dup (ip);
g_variant_unref (ip_var);
}
dns[i] = NULL;
......@@ -1612,7 +1612,7 @@ nm_utils_ip6_addresses_from_variant (GVariant *value, char **out_gateway)
goto next;
}
if (!IN6_IS_ADDR_UNSPECIFIED (gateway_bytes))
*out_gateway = g_strdup (nm_utils_inet6_ntop (gateway_bytes, NULL));
*out_gateway = nm_utils_inet6_ntop_dup (gateway_bytes);
}
} else {
g_warning ("Ignoring invalid IP6 address: %s", error->message);
......
......@@ -5084,7 +5084,7 @@ test_setting_ip4_gateway (void)
GVariantBuilder addrs_builder;
GError *error = NULL;
g_assert_cmpstr (nm_utils_inet4_ntop (addr_vals_0[0], NULL), ==, "192.168.1.10");
nmtst_assert_ip4_address (addr_vals_0[0], "192.168.1.10");
/* When serializing on the daemon side, ipv4.gateway is copied to the first
* entry of ipv4.addresses
......@@ -5126,7 +5126,7 @@ test_setting_ip4_gateway (void)
addr_array = g_variant_get_fixed_array (addr_var, &length, sizeof (guint32));
g_assert_cmpint (length, ==, 3);
g_assert_cmpstr (nm_utils_inet4_ntop (addr_array[2], NULL), ==, "192.168.1.1");
nmtst_assert_ip4_address (addr_array[2], "192.168.1.1");
g_variant_unref (addr_var);
}
g_variant_unref (value);
......@@ -5233,7 +5233,7 @@ test_setting_ip6_gateway (void)
gateway_bytes = g_variant_get_fixed_array (gateway_var, &length, 1);
g_assert_cmpint (length, ==, 16);
g_assert_cmpstr (nm_utils_inet6_ntop ((struct in6_addr *) gateway_bytes, NULL), ==, "abcd::1");
nmtst_assert_ip6_address ((struct in6_addr *) gateway_bytes, "abcd::1");
g_variant_unref (gateway_var);
}
g_variant_unref (value);
......
......@@ -230,11 +230,12 @@ acd_probe_add (NMAcdManager *self,
{
NAcdProbeConfig *probe_config;
int r;
char sbuf[NM_UTILS_INET_ADDRSTRLEN];
r = n_acd_probe_config_new (&probe_config);
if (r) {
_LOGW ("could not create probe config for %s on interface '%s': %s",
nm_utils_inet4_ntop (info->address, NULL),
nm_utils_inet4_ntop (info->address, sbuf),
nm_platform_link_get_name (NM_PLATFORM_GET, self->ifindex),
acd_error_to_string (r));
return FALSE;
......@@ -246,7 +247,7 @@ acd_probe_add (NMAcdManager *self,
r = n_acd_probe (self->acd, &info->probe, probe_config);
if (r) {
_LOGW ("could not start probe for %s on interface '%s': %s",
nm_utils_inet4_ntop (info->address, NULL),
nm_utils_inet4_ntop (info->address, sbuf),
nm_platform_link_get_name (NM_PLATFORM_GET, self->ifindex),
acd_error_to_string (r));
n_acd_probe_config_free (probe_config);
......@@ -381,6 +382,8 @@ nm_acd_manager_announce_addresses (NMAcdManager *self)
acd_probe_add (self, info, 0);
self->state = STATE_ANNOUNCING;
} else if (self->state == STATE_ANNOUNCING) {
char sbuf[NM_UTILS_INET_ADDRSTRLEN];
g_hash_table_iter_init (&iter, self->addresses);
while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &info)) {
if (info->duplicate)
......@@ -388,11 +391,11 @@ nm_acd_manager_announce_addresses (NMAcdManager *self)
r = n_acd_probe_announce (info->probe, N_ACD_DEFEND_ONCE);
if (r) {
_LOGW ("couldn't announce address %s on interface '%s': %s",
nm_utils_inet4_ntop (info->address, NULL),
nm_utils_inet4_ntop (info->address, sbuf),
nm_platform_link_get_name (NM_PLATFORM_GET, self->ifindex),
acd_error_to_string (r));
} else
_LOGD ("announcing address %s", nm_utils_inet4_ntop (info->address, NULL));
_LOGD ("announcing address %s", nm_utils_inet4_ntop (info->address, sbuf));
}
}
}
......
......@@ -329,28 +329,28 @@ clear:
if (!address_equal_pn (AF_INET, priv->local, &local4)) {
g_clear_pointer (&priv->local, g_free);
if (local4)
priv->local = g_strdup (nm_utils_inet4_ntop (local4, NULL));
priv->local = nm_utils_inet4_ntop_dup (local4);
_notify (self, PROP_LOCAL);
}
if (!address_equal_pn (AF_INET, priv->remote, &remote4)) {
g_clear_pointer (&priv->remote, g_free);
if (remote4)
priv->remote = g_strdup (nm_utils_inet4_ntop (remote4, NULL));
priv->remote = nm_utils_inet4_ntop_dup (remote4);
_notify (self, PROP_REMOTE);
}
} else {
if (!address_equal_pn (AF_INET6, priv->local, &local6)) {
g_clear_pointer (&priv->local, g_free);
if (memcmp (&local6, &in6addr_any, sizeof (in6addr_any)))
priv->local = g_strdup (nm_utils_inet6_ntop (&local6, NULL));
priv->local = nm_utils_inet6_ntop_dup (&local6);
_notify (self, PROP_LOCAL);
}
if (!address_equal_pn (AF_INET6, priv->remote, &remote6)) {
g_clear_pointer (&priv->remote, g_free);
if (memcmp (&remote6, &in6addr_any, sizeof (in6addr_any)))
priv->remote = g_strdup (nm_utils_inet6_ntop (&remote6, NULL));
priv->remote = nm_utils_inet6_ntop_dup (&remote6);
_notify (self, PROP_REMOTE);
}
}
......
......@@ -34,6 +34,7 @@
#include "settings/nm-settings.h"
#include "nm-act-request.h"
#include "nm-ip4-config.h"
#include "nm-core-internal.h"
#include "nm-device-logging.h"
_LOG_DECLARE_SELF(NMDeviceVxlan);
......@@ -386,6 +387,7 @@ update_connection (NMDevice *device, NMConnection *connection)
{
NMDeviceVxlanPrivate *priv = NM_DEVICE_VXLAN_GET_PRIVATE ((NMDeviceVxlan *) device);
NMSettingVxlan *s_vxlan = nm_connection_get_setting_vxlan (connection);
char sbuf[NM_UTILS_INET_ADDRSTRLEN];
if (!s_vxlan) {
s_vxlan = (NMSettingVxlan *) nm_setting_vxlan_new ();
......@@ -404,11 +406,11 @@ update_connection (NMDevice *device, NMConnection *connection)
if (!address_matches (nm_setting_vxlan_get_remote (s_vxlan), priv->props.group, &priv->props.group6)) {
if (priv->props.group) {
g_object_set (s_vxlan, NM_SETTING_VXLAN_REMOTE,
nm_utils_inet4_ntop (priv->props.group, NULL),
nm_utils_inet4_ntop (priv->props.group, sbuf),
NULL);
} else {
g_object_set (s_vxlan, NM_SETTING_VXLAN_REMOTE,
nm_utils_inet6_ntop (&priv->props.group6, NULL),
nm_utils_inet6_ntop (&priv->props.group6, sbuf),
NULL);
}
}
......@@ -416,11 +418,11 @@ update_connection (NMDevice *device, NMConnection *connection)
if (!address_matches (nm_setting_vxlan_get_local (s_vxlan), priv->props.local, &priv->props.local6)) {
if (priv->props.local) {
g_object_set (s_vxlan, NM_SETTING_VXLAN_LOCAL,
nm_utils_inet4_ntop (priv->props.local, NULL),
nm_utils_inet4_ntop (priv->props.local, sbuf),
NULL);
} else if (memcmp (&priv->props.local6, &in6addr_any, sizeof (in6addr_any))) {
g_object_set (s_vxlan, NM_SETTING_VXLAN_LOCAL,
nm_utils_inet6_ntop (&priv->props.local6, NULL),
nm_utils_inet6_ntop (&priv->props.local6, sbuf),
NULL);
}
}
......@@ -510,15 +512,15 @@ get_property (GObject *object, guint prop_id,
break;
case PROP_GROUP:
if (priv->props.group)
g_value_set_string (value, nm_utils_inet4_ntop (priv->props.group, NULL));
g_value_take_string (value, nm_utils_inet4_ntop_dup (priv->props.group));
else if (!IN6_IS_ADDR_UNSPECIFIED (&priv->props.group6))
g_value_set_string (value, nm_utils_inet6_ntop (&priv->props.group6, NULL));
g_value_take_string (value, nm_utils_inet6_ntop_dup (&priv->props.group6));
break;
case PROP_LOCAL:
if (priv->props.local)
g_value_set_string (value, nm_utils_inet4_ntop (priv->props.local, NULL));
g_value_take_string (value, nm_utils_inet4_ntop_dup (priv->props.local));
else if (!IN6_IS_ADDR_UNSPECIFIED (&priv->props.local6))
g_value_set_string (value, nm_utils_inet6_ntop (&priv->props.local6, NULL));
g_value_take_string (value, nm_utils_inet6_ntop_dup (&priv->props.local6));
break;
case PROP_TOS:
g_value_set_uchar (value, priv->props.tos);
......
......@@ -5475,10 +5475,13 @@ nm_device_generate_connection (NMDevice *self,
nm_connection_add_setting (connection, nm_setting_proxy_new ());
pllink = nm_platform_link_get (nm_device_get_platform (self), priv->ifindex);
if (pllink && pllink->inet6_token.id) {
if ( pllink
&& pllink->inet6_token.id) {
char sbuf[NM_UTILS_INET_ADDRSTRLEN];
g_object_set (s_ip6,
NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE, NM_IN6_ADDR_GEN_MODE_EUI64,
NM_SETTING_IP6_CONFIG_TOKEN, nm_utils_inet6_interface_identifier_to_token (pllink->inet6_token, NULL),
NM_SETTING_IP6_CONFIG_TOKEN, nm_utils_inet6_interface_identifier_to_token (pllink->inet6_token, sbuf),
NULL);
}
}
......@@ -6641,13 +6644,15 @@ acd_manager_probe_terminated (NMAcdManager *acd_manager, gpointer user_data)
for (i = 0; data->configs && data->configs[i]; i++) {
nm_ip_config_iter_ip4_address_for_each (&ipconf_iter, data->configs[i], &address) {
char sbuf[NM_UTILS_INET_ADDRSTRLEN];
result = nm_acd_manager_check_address (acd_manager, address->address);
success &= result;
_NMLOG (result ? LOGL_DEBUG : LOGL_WARN,
LOGD_DEVICE,
"IPv4 DAD result: address %s is %s",
nm_utils_inet4_ntop (address->address, NULL),
nm_utils_inet4_ntop (address->address, sbuf),
result ? "unique" : "duplicate");
}
}
......@@ -8678,6 +8683,7 @@ nm_device_use_ip6_subnet (NMDevice *self, const NMPlatformIP6Address *subnet)
{
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
NMPlatformIP6Address address = *subnet;
char sbuf[NM_UTILS_INET_ADDRSTRLEN];
if (!applied_config_get_current (&priv->ac_ip6_config))
applied_config_init_new (&priv->ac_ip6_config, self, AF_INET6);
......@@ -8687,7 +8693,7 @@ nm_device_use_ip6_subnet (NMDevice *self, const NMPlatformIP6Address *subnet)
applied_config_add_address (&priv->ac_ip6_config, NM_PLATFORM_IP_ADDRESS_CAST (&address));
_LOGD (LOGD_IP6, "ipv6-pd: using %s address (preferred for %u seconds)",
nm_utils_inet6_ntop (&address.address, NULL),
nm_utils_inet6_ntop (&address.address, sbuf),
subnet->preferred);
/* This also updates the ndisc if there are actual changes. */
......@@ -8806,6 +8812,7 @@ check_and_add_ipv6ll_addr (NMDevice *self)
NMSettingIP6Config *s_ip6 = NULL;
GError *error = NULL;
const char *addr_type;
char sbuf[NM_UTILS_INET_ADDRSTRLEN];
if (!priv->ipv6ll_handle)
return;
......@@ -8866,7 +8873,8 @@ check_and_add_ipv6ll_addr (NMDevice *self)
addr_type = "EUI-64";
}
_LOGD (LOGD_IP6, "linklocal6: generated %s IPv6LL address %s", addr_type, nm_utils_inet6_ntop (&lladdr, NULL));
_LOGD (LOGD_IP6, "linklocal6: generated %s IPv6LL address %s",
addr_type, nm_utils_inet6_ntop (&lladdr, sbuf));
priv->ipv6ll_has = TRUE;
priv->ipv6ll_addr = lladdr;
ip_config_merge_and_apply (self, AF_INET6, TRUE);
......@@ -14435,7 +14443,7 @@ find_dhcp4_address (NMDevice *self)
nm_ip_config_iter_ip4_address_for_each (&ipconf_iter, priv->ip_config_4, &a) {
if (a->addr_source == NM_IP_CONFIG_SOURCE_DHCP)
return g_strdup (nm_utils_inet4_ntop (a->address, NULL));
return nm_utils_inet4_ntop_dup (a->address);
}
return NULL;
}
......
......@@ -154,6 +154,7 @@ again:
for (i = 0; info->addresses[i]; i++) {
gboolean val;
char sbuf[NM_UTILS_INET_ADDRSTRLEN];
val = nm_acd_manager_check_address (manager, info->addresses[i]);
if (val == info->expected_result[i])
......@@ -168,7 +169,7 @@ again:
}
g_error ("expected check for address #%d (%s) to %s, but it didn't",
i, nm_utils_inet4_ntop (info->addresses[i], NULL),
i, nm_utils_inet4_ntop (info->addresses[i], sbuf),
info->expected_result[i] ? "detect no duplicated" : "detect a duplicate");
}
......
......@@ -232,7 +232,8 @@ lease_to_ip4_config (NMDedupMultiIndex *multi_idx,
NMIP4Config *ip4_config = NULL;
struct in_addr tmp_addr;
const struct in_addr *addr_list;
char buf[INET_ADDRSTRLEN];
char addr_str[NM_UTILS_INET_ADDRSTRLEN];
char addr_str2[NM_UTILS_INET_ADDRSTRLEN];
const char *s;
guint32 lifetime = 0, i;
NMPlatformIP4Address address;
......@@ -258,9 +259,9 @@ lease_to_ip4_config (NMDedupMultiIndex *multi_idx,
memset (&address, 0, sizeof (address));
address.address = tmp_addr.s_addr;
address.peer_address = tmp_addr.s_addr;
s = nm_utils_inet4_ntop (tmp_addr.s_addr, NULL);
LOG_LEASE (LOGD_DHCP4, "address %s", s);
add_option (options, dhcp4_requests, DHCP_OPTION_IP_ADDRESS, s);
nm_utils_inet4_ntop (tmp_addr.s_addr, addr_str);
LOG_LEASE (LOGD_DHCP4, "address %s", addr_str);
add_option (options, dhcp4_requests, DHCP_OPTION_IP_ADDRESS, addr_str);
/* Prefix/netmask */
sd_dhcp_lease_get_netmask (lease, &tmp_addr);
......@@ -269,7 +270,7 @@ lease_to_ip4_config (NMDedupMultiIndex *multi_idx,
add_option (options,
dhcp4_requests,
SD_DHCP_OPTION_SUBNET_MASK,
nm_utils_inet4_ntop (tmp_addr.s_addr, NULL));
nm_utils_inet4_ntop (tmp_addr.s_addr, addr_str));
/* Lease time */
sd_dhcp_lease_get_lifetime (lease, &lifetime);
......@@ -292,7 +293,7 @@ lease_to_ip4_config (NMDedupMultiIndex *multi_idx,
for (i = 0; i < num; i++) {
if (addr_list[i].s_addr) {
nm_ip4_config_add_nameserver (ip4_config, addr_list[i].s_addr);
s = nm_utils_inet4_ntop (addr_list[i].s_addr, NULL);
s = nm_utils_inet4_ntop (addr_list[i].s_addr, addr_str);
LOG_LEASE (LOGD_DHCP4, "nameserver '%s'", s);
g_string_append_printf (str, "%s%s", str->len ? " " : "", s);
}
......@@ -366,8 +367,8 @@ lease_to_ip4_config (NMDedupMultiIndex *multi_idx,
route.table_coerced = nm_platform_route_table_coerce (route_table);
nm_ip4_config_add_route (ip4_config, &route, NULL);
s = nm_utils_inet4_ntop (route.network, buf);
gw_str = nm_utils_inet4_ntop (route.gateway, NULL);
s = nm_utils_inet4_ntop (route.network, addr_str);
gw_str = nm_utils_inet4_ntop (route.gateway, addr_str2);
LOG_LEASE (LOGD_DHCP4, "static route %s/%d gw %s", s, route.plen, gw_str);
g_string_append_printf (str, "%s%s/%d %s", str->len ? " " : "", s, route.plen, gw_str);
......@@ -377,7 +378,7 @@ lease_to_ip4_config (NMDedupMultiIndex *multi_idx,
gateway_has = TRUE;
gateway = route.gateway;
s = nm_utils_inet4_ntop (route.gateway, NULL);
s = nm_utils_inet4_ntop (route.gateway, addr_str);
LOG_LEASE (LOGD_DHCP4, "gateway %s", s);
add_option (options, dhcp4_requests, SD_DHCP_OPTION_ROUTER, s);
}
......@@ -398,7 +399,7 @@ lease_to_ip4_config (NMDedupMultiIndex *multi_idx,
if (r == 0) {
gateway_has = TRUE;
gateway = tmp_addr.s_addr;
s = nm_utils_inet4_ntop (tmp_addr.s_addr, NULL);
s = nm_utils_inet4_ntop (tmp_addr.s_addr, addr_str);
LOG_LEASE (LOGD_DHCP4, "gateway %s", s);
add_option (options, dhcp4_requests, SD_DHCP_OPTION_ROUTER, s);
}
......@@ -428,7 +429,7 @@ lease_to_ip4_config (NMDedupMultiIndex *multi_idx,
if (num > 0) {
nm_gstring_prepare (&str);
for (i = 0; i < num; i++) {
s = nm_utils_inet4_ntop (addr_list[i].s_addr, buf);
s = nm_utils_inet4_ntop (addr_list[i].s_addr, addr_str);
LOG_LEASE (LOGD_DHCP4, "ntp server '%s'", s);
g_string_append_printf (str, "%s%s", str->len ? " " : "", s);
}
......@@ -726,7 +727,7 @@ lease_to_ip6_config (NMDedupMultiIndex *multi_idx,
struct in6_addr tmp_addr, *dns;
uint32_t lft_pref, lft_valid;
NMIP6Config *ip6_config;
const char *addr_str;
char addr_str[NM_UTILS_INET_ADDRSTRLEN];
char **domains;
nm_auto_free_gstring GString *str = NULL;
int num, i;
......@@ -751,8 +752,10 @@ lease_to_ip6_config (NMDedupMultiIndex *multi_idx,
nm_ip6_config_add_address (ip6_config, &address);
addr_str = nm_utils_inet6_ntop (&tmp_addr, NULL);
g_string_append_printf (str, "%s%s", str->len ? " " : "", addr_str);
nm_utils_inet6_ntop (&tmp_addr, addr_str);
if (str->len)
g_string_append_c (str, ' ');
g_string_append (str, addr_str);
LOG_LEASE (LOGD_DHCP6,
"address %s",
......@@ -777,8 +780,10 @@ lease_to_ip6_config (NMDedupMultiIndex *multi_idx,
nm_gstring_prepare (&str);
for (i = 0; i < num; i++) {
nm_ip6_config_add_nameserver (ip6_config, &dns[i]);
addr_str = nm_utils_inet6_ntop (&dns[i], NULL);
g_string_append_printf (str, "%s%s", str->len ? " " : "", addr_str);
nm_utils_inet6_ntop (&dns[i], addr_str);
if (str->len)
g_string_append_c (str, ' ');
g_string_append (str, addr_str);
LOG_LEASE (LOGD_DHCP6, "nameserver %s", addr_str);
}
add_option (options, dhcp6_requests, SD_DHCP6_OPTION_DNS_SERVERS, str->str);
......
......@@ -197,7 +197,8 @@ ip4_process_dhclient_rfc3442_routes (const char *iface,
/* gateway passed as classless static route */
*gwaddr = route.gateway;
} else {
char addr[INET_ADDRSTRLEN];
char b1[INET_ADDRSTRLEN];
char b2[INET_ADDRSTRLEN];
/* normal route */
route.rt_source = NM_IP_CONFIG_SOURCE_DHCP;
......@@ -206,8 +207,9 @@ ip4_process_dhclient_rfc3442_routes (const char *iface,
nm_ip4_config_add_route (ip4_config, &route, NULL);
_LOG2I (LOGD_DHCP4, iface, " classless static route %s/%d gw %s",
nm_utils_inet4_ntop (route.network, addr), route.plen,
nm_utils_inet4_ntop (route.gateway, NULL));
nm_utils_inet4_ntop (route.network, b1),
route.plen,
nm_utils_inet4_ntop (route.gateway, b2));
}
}
......@@ -408,6 +410,7 @@ nm_dhcp_utils_ip4_config_from_options (NMDedupMultiIndex *multi_idx,
gboolean gateway_has = FALSE;
guint32 gateway = 0;
guint8 plen = 0;
char sbuf[NM_UTILS_INET_ADDRSTRLEN];
g_return_val_if_fail (options != NULL, NULL);
......@@ -439,7 +442,7 @@ nm_dhcp_utils_ip4_config_from_options (NMDedupMultiIndex *multi_idx,
process_classful_routes (iface, options, route_table, route_metric, ip4_config);
if (gateway) {
_LOG2I (LOGD_DHCP4, iface, " gateway %s", nm_utils_inet4_ntop (gateway, NULL));
_LOG2I (LOGD_DHCP4, iface, " gateway %s", nm_utils_inet4_ntop (gateway, sbuf));
gateway_has = TRUE;
} else {
/* If the gateway wasn't provided as a classless static route with a
......
......@@ -965,7 +965,9 @@ nm_ndisc_dad_failed (NMNDisc *ndisc, const struct in6_addr *address, gboolean em
NMNDiscAddress *item = &g_array_index (rdata->addresses, NMNDiscAddress, i);
if (IN6_ARE_ADDR_EQUAL (&item->address, address)) {
_LOGD ("DAD failed for discovered address %s", nm_utils_inet6_ntop (address, NULL));
char sbuf[NM_UTILS_INET_ADDRSTRLEN];
_LOGD ("DAD failed for discovered address %s", nm_utils_inet6_ntop (address, sbuf));
changed = TRUE;
if (!complete_address (ndisc, item)) {
g_array_remove_index (rdata->addresses, i);
......@@ -1056,10 +1058,11 @@ _config_changed_log (NMNDisc *ndisc, NMNDiscConfigMap changed)
}
for (i = 0; i < rdata->routes->len; i++) {
NMNDiscRoute *route = &g_array_index (rdata->routes, NMNDiscRoute, i);
char sbuf[NM_UTILS_INET_ADDRSTRLEN];
inet_ntop (AF_INET6, &route->network, addrstr, sizeof (addrstr));
_LOGD (" route %s/%u via %s pref %s exp %s", addrstr, (guint) route->plen,
nm_utils_inet6_ntop (&route->gateway, NULL),
nm_utils_inet6_ntop (&route->gateway, sbuf),
nm_icmpv6_router_pref_to_string (route->preference, str_pref, sizeof (str_pref)),
get_exp (str_exp, now_ns, route));
}
......
......@@ -3045,14 +3045,12 @@ nm_utils_ipv6_interface_identifier_get_from_token (NMUtilsIPv6IfaceId *iid,
/**
* nm_utils_inet6_interface_identifier_to_token:
* @iid: %NMUtilsIPv6IfaceId interface identifier
* @buf: the destination buffer or %NULL
* @buf: the destination buffer of at least %NM_UTILS_INET_ADDRSTRLEN
* bytes.
*
* Converts the interface identifier to a string token.
* If the destination buffer it set, set it is used to store the
* resulting token, otherwise an internal static buffer is used.
* The buffer needs to be %NM_UTILS_INET_ADDRSTRLEN characters long.
*
* Returns: a statically allocated array. Do not g_free().
* Returns: the input buffer filled with the id as string.
*/
const char *
nm_utils_inet6_interface_identifier_to_token (NMUtilsIPv6IfaceId iid, char *buf)
......
......@@ -1051,6 +1051,7 @@ nm_ip4_config_create_setting (const NMIP4Config *self)
NMDedupMultiIter ipconf_iter;
const NMPlatformIP4Address *address;
const NMPlatformIP4Route *route;
char sbuf[NM_UTILS_INET_ADDRSTRLEN];
s_ip4 = NM_SETTING_IP_CONFIG (nm_setting_ip4_config_new ());
......@@ -1095,7 +1096,7 @@ nm_ip4_config_create_setting (const NMIP4Config *self)
g_object_set (s_ip4,
NM_SETTING_IP_CONFIG_GATEWAY,
nm_utils_inet4_ntop (NMP_OBJECT_CAST_IP4_ROUTE (priv->best_default_route)->gateway,
NULL),
sbuf),
NULL);
}
......@@ -1130,7 +1131,7 @@ nm_ip4_config_create_setting (const NMIP4Config *self)
for (i = 0; i < nnameservers; i++) {
guint32 nameserver = nm_ip4_config_get_nameserver (self, i);
nm_setting_ip_config_add_dns (s_ip4, nm_utils_inet4_ntop (nameserver, NULL));
nm_setting_ip_config_add_dns (s_ip4, nm_utils_inet4_ntop (nameserver, sbuf));
}
for (i = 0; i < nsearches; i++) {
const char *search = nm_ip4_config_get_search (self, i);
......@@ -2039,9 +2040,11 @@ nm_ip_config_dump (const NMIPConfig *self,
}
for (i = 0; i < nm_ip_config_get_num_nameservers (self); i++) {
char buf[NM_UTILS_INET_ADDRSTRLEN];
ptr = nm_ip_config_get_nameserver (self, i);
nm_log (level, domain, NULL, NULL, " dns : %s",
nm_utils_inet_ntop (addr_family, ptr, NULL));
nm_utils_inet_ntop (addr_family, ptr, buf));
}
for (i = 0; i < nm_ip_config_get_num_domains (self); i++)
......@@ -3024,6 +3027,7 @@ get_property (GObject *object, guint prop_id,
const NMPlatformIP4Route *route;
GVariantBuilder builder_data, builder_legacy;
guint i;
char addr_str[NM_UTILS_INET_ADDRSTRLEN];
switch (prop_id) {
case PROP_IFINDEX:
......@@ -3061,14 +3065,14 @@ get_property (GObject *object, guint prop_id,
g_variant_builder_init (&addr_builder, G_VARIANT_TYPE ("a{sv}"));
g_variant_builder_add (&addr_builder, "{sv}",
"address",
g_variant_new_string (nm_utils_inet4_ntop (address->address, NULL)));
g_variant_new_string (nm_utils_inet4_ntop (address->address, addr_str)));
g_variant_builder_add (&addr_builder, "{sv}",
"prefix",
g_variant_new_uint32 (address->plen));
if (address->peer_address != address->address) {
g_variant_builder_add (&addr_builder, "{sv}",
"peer",
g_variant_new_string (nm_utils_inet4_ntop (address->peer_address, NULL)));
g_variant_new_string (nm_utils_inet4_ntop (address->peer_address, addr_str)));
}
if (*address->label) {
......@@ -3123,14 +3127,14 @@ out_addresses_cached:
g_variant_builder_init (&route_builder, G_VARIANT_TYPE ("a{sv}"));
g_variant_builder_add (&route_builder, "{sv}",
"dest",
g_variant_new_string (nm_utils_inet4_ntop (route->network, NULL)));
g_variant_new_string (nm_utils_inet4_ntop (route->network, addr_str)));
g_variant_builder_add (&route_builder, "{sv}",
"prefix",
g_variant_new_uint32 (route->plen));
if (route->gateway) {
g_variant_builder_add (&route_builder, "{sv}",
"next-hop",
g_variant_new_string (nm_utils_inet4_ntop (route->gateway, NULL)));
g_variant_new_string (nm_utils_inet4_ntop (route->gateway, addr_str)));
}
g_variant_builder_add (&route_builder, "{sv}",
"metric",
......@@ -3172,9 +3176,8 @@ out_routes_cached:
break;
case PROP_GATEWAY:
if (priv->best_default_route) {
g_value_set_string (value,
nm_utils_inet4_ntop (NMP_OBJECT_CAST_IP4_ROUTE (priv->best_default_route)->gateway,
NULL));
g_value_take_string (value,
nm_utils_inet4_ntop_dup (NMP_OBJECT_CAST_IP4_ROUTE (priv->best_default_route)->gateway));
} else
g_value_set_string (value, NULL);
break;
......@@ -3183,7 +3186,6 @@ out_routes_cached:
for (i = 0; i < priv->nameservers->len; i++) {
GVariantBuilder nested_builder;
char addr_str[NM_UTILS_INET_ADDRSTRLEN];
nm_utils_inet4_ntop (g_array_index (priv->nameservers, in_addr_t, i),
addr_str);
......@@ -3220,8 +3222,6 @@ out_routes_cached:
case PROP_WINS_SERVER_DATA:
g_variant_builder_init (&builder_data, G_VARIANT_TYPE ("as"));
for (i = 0; i < priv->wins->len; i++) {
char addr_str[NM_UTILS_INET_ADDRSTRLEN];
g_variant_builder_add (&builder_data,
"s",
nm_utils_inet4_ntop (g_array_index (priv->wins, in_addr_t, i),
......
......@@ -713,6 +713,7 @@ nm_ip6_config_create_setting (const NMIP6Config *self)
NMSettingIPConfig *s_ip6;
guint nnameservers, nsearches, noptions;
const char *method = NULL;
char sbuf[NM_UTILS_INET_ADDRSTRLEN];
int i;
NMDedupMultiIter ipconf_iter;
const NMPlatformIP6Address *address;
......@@ -765,7 +766,7 @@ nm_ip6_config_create_setting (const NMIP6Config *self)
g_object_set (s_ip6,
NM_SETTING_IP_CONFIG_GATEWAY,
nm_utils_inet6_ntop (&NMP_OBJECT_CAST_IP6_ROUTE (priv->best_default_route)->gateway,
NULL),
sbuf),
NULL);
}
......@@ -804,7 +805,7 @@ nm_ip6_config_create_setting (const NMIP6Config *self)
for (i = 0; i < nnameservers; i++) {
const struct in6_addr *nameserver = nm_ip6_config_get_nameserver (self, i);
nm_setting_ip_config_add_dns (s_ip6, nm_utils_inet6_ntop (nameserver, NULL));
nm_setting_ip_config_add_dns (s_ip6, nm_utils_inet6_ntop (nameserver, sbuf));
}
for (i = 0; i < nsearches; i++) {
const char *search = nm_ip6_config_get_search (self, i);
......@@ -2473,6 +2474,7 @@ get_property (GObject *object, guint prop_id,
NMDedupMultiIter ipconf_iter;
const NMPlatformIP6Route *route;
GVariantBuilder builder_data, builder_legacy;
char sbuf[NM_UTILS_INET_ADDRSTRLEN];
switch (prop_id) {
case PROP_IFINDEX:
......@@ -2509,7 +2511,7 @@ get_property (GObject *object, guint prop_id,
g_variant_builder_init (&addr_builder, G_VARIANT_TYPE ("a{sv}"));
g_variant_builder_add (&addr_builder, "{sv}",
"address",
g_variant_new_string (nm_utils_inet6_ntop (&address->address, NULL)));
g_variant_new_string (nm_utils_inet6_ntop (&address->address, sbuf)));
g_variant_builder_add (&addr_builder, "{sv}",
"prefix",
g_variant_new_uint32 (address->plen));
......@@ -2517,7 +2519,7 @@ get_property (GObject *object, guint prop_id,
&& !IN6_ARE_ADDR_EQUAL (&address->peer_address, &address->address)) {
g_variant_builder_add (&addr_builder, "{sv}",
"peer",
g_variant_new_string (nm_utils_inet6_ntop (&address->peer_address, NULL)));
g_variant_new_string (nm_utils_inet6_ntop (&address->peer_address, sbuf)));
}
g_variant_builder_add (&builder_data, "a{sv}", &addr_builder);
......@@ -2562,14 +2564,14 @@ out_addresses_cached:
g_variant_builder_init (&route_builder, G_VARIANT_TYPE ("a{sv}"));
g_variant_builder_add (&route_builder, "{sv}",
"dest",
g_variant_new_string (nm_utils_inet6_ntop (&route->network, NULL)));
g_variant_new_string (nm_utils_inet6_ntop (&route->network, sbuf)));
g_variant_builder_add (&route_builder, "{sv}",
"prefix",
g_variant_new_uint32 (route->plen));
if (!IN6_IS_ADDR_UNSPECIFIED (&route->gateway)) {
g_variant_builder_add (&route_builder, "{sv}",
"next-hop",
g_variant_new_string (nm_utils_inet6_ntop (&route->gateway, NULL)));
g_variant_new_string (nm_utils_inet6_ntop (&route->gateway, sbuf)));
}
g_variant_builder_add (&route_builder, "{sv}",
......@@ -2607,9 +2609,8 @@ out_routes_cached:
break;
case PROP_GATEWAY:
if (priv->best_default_route) {
g_value_set_string (value,
nm_utils_inet6_ntop (&NMP_OBJECT_CAST_IP6_ROUTE (priv->best_default_route)->gateway,
NULL));
g_value_take_string (value,
nm_utils_inet6_ntop_dup (&NMP_OBJECT_CAST_IP6_ROUTE (priv->best_default_route)->gateway));
} else
g_value_set_string (value, NULL);
break;
......
......@@ -173,6 +173,7 @@ get_ip4_domains (GPtrArray *domains, NMIP4Config *ip4)
const NMPlatformIP4Address *address;
const NMPlatformIP4Route *routes;
guint i;
char sbuf[NM_UTILS_INET_ADDRSTRLEN];
/* Extract searches */
for (i = 0; i < nm_ip4_config_get_num_searches (ip4); i++)
......@@ -186,7 +187,7 @@ get_ip4_domains (GPtrArray *domains, NMIP4Config *ip4)
nm_ip_config_iter_ip4_address_for_each (&ipconf_iter, ip4, &address) {
cidr = g_strdup_printf ("%s/%u",
nm_utils_inet4_ntop (address->address, NULL),
nm_utils_inet4_ntop (address->address, sbuf),
address->plen);
g_ptr_array_add (domains, cidr);
}
......@@ -195,7 +196,7 @@ get_ip4_domains (GPtrArray *domains, NMIP4Config *ip4)
if (NM_PLATFORM_IP_ROUTE_IS_DEFAULT (routes))
continue;
cidr = g_strdup_printf ("%s/%u",
nm_utils_inet4_ntop (routes->network, NULL),
nm_utils_inet4_ntop (routes->network, sbuf),
routes->plen);
g_ptr_array_add (domains, cidr);
}
......@@ -209,6 +210,7 @@ get_ip6_domains (GPtrArray *domains, NMIP6Config *ip6)
const NMPlatformIP6Address *address;
const NMPlatformIP6Route *routes;
guint i;
char sbuf[NM_UTILS_INET_ADDRSTRLEN];
/* Extract searches */
for (i = 0; i < nm_ip6_config_get_num_searches (ip6); i++)
......@@ -221,7 +223,7 @@ get_ip6_domains (GPtrArray *domains, NMIP6Config *ip6)
/* Add addresses and routes in CIDR form */
nm_ip_config_iter_ip6_address_for_each (&ipconf_iter, ip6, &address) {
cidr = g_strdup_printf ("%s/%u",
nm_utils_inet6_ntop (&address->address, NULL),
nm_utils_inet6_ntop (&address->address, sbuf),
</