mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-26 18:10:08 +01:00
all: refactor to make use of nm_utils_inet[46]_ntop functions
https://bugzilla.gnome.org/show_bug.cgi?id=711684 Signed-off-by: Thomas Haller <thaller@redhat.com>
This commit is contained in:
parent
41f8114359
commit
6f2cfe263e
7 changed files with 75 additions and 215 deletions
|
|
@ -96,6 +96,8 @@ construct_ip4_items (GSList *items, GHashTable *ip4_config, const char *prefix)
|
|||
guint32 num, i;
|
||||
GString *tmp;
|
||||
GValue *val;
|
||||
char str_addr[INET_ADDRSTRLEN];
|
||||
char str_gw[INET_ADDRSTRLEN];
|
||||
|
||||
if (ip4_config == NULL)
|
||||
return items;
|
||||
|
|
@ -110,20 +112,11 @@ construct_ip4_items (GSList *items, GHashTable *ip4_config, const char *prefix)
|
|||
|
||||
for (iter = addresses, num = 0; iter; iter = g_slist_next (iter)) {
|
||||
NMIP4Address *addr = (NMIP4Address *) iter->data;
|
||||
char str_addr[INET_ADDRSTRLEN + 1];
|
||||
char str_gw[INET_ADDRSTRLEN + 1];
|
||||
guint32 tmp_addr;
|
||||
guint32 ip_prefix = nm_ip4_address_get_prefix (addr);
|
||||
char *addrtmp;
|
||||
|
||||
memset (str_addr, 0, sizeof (str_addr));
|
||||
tmp_addr = nm_ip4_address_get_address (addr);
|
||||
if (!inet_ntop (AF_INET, &tmp_addr, str_addr, sizeof (str_addr)))
|
||||
continue;
|
||||
|
||||
memset (str_gw, 0, sizeof (str_gw));
|
||||
tmp_addr = nm_ip4_address_get_gateway (addr);
|
||||
inet_ntop (AF_INET, &tmp_addr, str_gw, sizeof (str_gw));
|
||||
nm_utils_inet4_ntop (nm_ip4_address_get_address (addr), str_addr);
|
||||
nm_utils_inet4_ntop (nm_ip4_address_get_gateway (addr), str_gw);
|
||||
|
||||
addrtmp = g_strdup_printf ("%sIP4_ADDRESS_%d=%s/%d %s", prefix, num++, str_addr, ip_prefix, str_gw);
|
||||
items = g_slist_prepend (items, addrtmp);
|
||||
|
|
@ -145,16 +138,12 @@ construct_ip4_items (GSList *items, GHashTable *ip4_config, const char *prefix)
|
|||
g_string_append_printf (tmp, "%sIP4_NAMESERVERS=", prefix);
|
||||
for (i = 0; i < dns->len; i++) {
|
||||
guint32 addr;
|
||||
char buf[INET_ADDRSTRLEN + 1];
|
||||
|
||||
addr = g_array_index (dns, guint32, i);
|
||||
memset (buf, 0, sizeof (buf));
|
||||
if (inet_ntop (AF_INET, &addr, buf, sizeof (buf))) {
|
||||
if (!first)
|
||||
g_string_append_c (tmp, ' ');
|
||||
g_string_append (tmp, buf);
|
||||
first = FALSE;
|
||||
}
|
||||
if (!first)
|
||||
g_string_append_c (tmp, ' ');
|
||||
g_string_append (tmp, nm_utils_inet4_ntop (addr, NULL));
|
||||
first = FALSE;
|
||||
}
|
||||
items = g_slist_prepend (items, tmp->str);
|
||||
g_string_free (tmp, FALSE);
|
||||
|
|
@ -175,16 +164,12 @@ construct_ip4_items (GSList *items, GHashTable *ip4_config, const char *prefix)
|
|||
g_string_append_printf (tmp, "%sIP4_WINS_SERVERS=", prefix);
|
||||
for (i = 0; i < wins->len; i++) {
|
||||
guint32 addr;
|
||||
char buf[INET_ADDRSTRLEN + 1];
|
||||
|
||||
addr = g_array_index (wins, guint32, i);
|
||||
memset (buf, 0, sizeof (buf));
|
||||
if (inet_ntop (AF_INET, &addr, buf, sizeof (buf))) {
|
||||
if (!first)
|
||||
g_string_append_c (tmp, ' ');
|
||||
g_string_append (tmp, buf);
|
||||
first = FALSE;
|
||||
}
|
||||
if (!first)
|
||||
g_string_append_c (tmp, ' ');
|
||||
g_string_append (tmp, nm_utils_inet4_ntop (addr, NULL));
|
||||
first = FALSE;
|
||||
}
|
||||
items = g_slist_prepend (items, tmp->str);
|
||||
g_string_free (tmp, FALSE);
|
||||
|
|
@ -197,23 +182,14 @@ construct_ip4_items (GSList *items, GHashTable *ip4_config, const char *prefix)
|
|||
|
||||
for (iter = routes, num = 0; iter; iter = g_slist_next (iter)) {
|
||||
NMIP4Route *route = (NMIP4Route *) iter->data;
|
||||
char str_addr[INET_ADDRSTRLEN + 1];
|
||||
char str_nh[INET_ADDRSTRLEN + 1];
|
||||
guint32 tmp_addr;
|
||||
guint32 ip_prefix = nm_ip4_route_get_prefix (route);
|
||||
guint32 metric = nm_ip4_route_get_metric (route);
|
||||
char *routetmp;
|
||||
|
||||
memset (str_addr, 0, sizeof (str_addr));
|
||||
tmp_addr = nm_ip4_route_get_dest (route);
|
||||
if (!inet_ntop (AF_INET, &tmp_addr, str_addr, sizeof (str_addr)))
|
||||
continue;
|
||||
nm_utils_inet4_ntop (nm_ip4_route_get_dest (route), str_addr);
|
||||
nm_utils_inet4_ntop (nm_ip4_route_get_next_hop (route), str_gw);
|
||||
|
||||
memset (str_nh, 0, sizeof (str_nh));
|
||||
tmp_addr = nm_ip4_route_get_next_hop (route);
|
||||
inet_ntop (AF_INET, &tmp_addr, str_nh, sizeof (str_nh));
|
||||
|
||||
routetmp = g_strdup_printf ("%sIP4_ROUTE_%d=%s/%d %s %d", prefix, num++, str_addr, ip_prefix, str_nh, metric);
|
||||
routetmp = g_strdup_printf ("%sIP4_ROUTE_%d=%s/%d %s %d", prefix, num++, str_addr, ip_prefix, str_gw, metric);
|
||||
items = g_slist_prepend (items, routetmp);
|
||||
}
|
||||
items = g_slist_prepend (items, g_strdup_printf ("%sIP4_NUM_ROUTES=%d", prefix, num));
|
||||
|
|
@ -251,6 +227,8 @@ construct_ip6_items (GSList *items, GHashTable *ip6_config, const char *prefix)
|
|||
guint32 num;
|
||||
GString *tmp;
|
||||
GValue *val;
|
||||
char str_addr[INET6_ADDRSTRLEN];
|
||||
char str_gw[INET6_ADDRSTRLEN];
|
||||
|
||||
if (ip6_config == NULL)
|
||||
return items;
|
||||
|
|
@ -265,20 +243,11 @@ construct_ip6_items (GSList *items, GHashTable *ip6_config, const char *prefix)
|
|||
|
||||
for (iter = addresses, num = 0; iter; iter = g_slist_next (iter)) {
|
||||
NMIP6Address *addr = (NMIP6Address *) iter->data;
|
||||
char str_addr[INET6_ADDRSTRLEN + 1];
|
||||
char str_gw[INET6_ADDRSTRLEN + 1];
|
||||
const struct in6_addr *tmp_addr;
|
||||
guint32 ip_prefix = nm_ip6_address_get_prefix (addr);
|
||||
char *addrtmp;
|
||||
|
||||
memset (str_addr, 0, sizeof (str_addr));
|
||||
tmp_addr = nm_ip6_address_get_address (addr);
|
||||
if (!inet_ntop (AF_INET6, &tmp_addr, str_addr, sizeof (str_addr)))
|
||||
continue;
|
||||
|
||||
memset (str_gw, 0, sizeof (str_gw));
|
||||
tmp_addr = nm_ip6_address_get_gateway (addr);
|
||||
inet_ntop (AF_INET6, &tmp_addr, str_gw, sizeof (str_gw));
|
||||
nm_utils_inet6_ntop (nm_ip6_address_get_address (addr), str_addr);
|
||||
nm_utils_inet6_ntop (nm_ip6_address_get_gateway (addr), str_gw);
|
||||
|
||||
addrtmp = g_strdup_printf ("%sIP6_ADDRESS_%d=%s/%d %s", prefix, num++, str_addr, ip_prefix, str_gw);
|
||||
items = g_slist_prepend (items, addrtmp);
|
||||
|
|
@ -294,21 +263,18 @@ construct_ip6_items (GSList *items, GHashTable *ip6_config, const char *prefix)
|
|||
dns = nm_utils_ip6_dns_from_gvalue (val);
|
||||
|
||||
if (g_slist_length (dns)) {
|
||||
gboolean first = TRUE;
|
||||
|
||||
tmp = g_string_new (NULL);
|
||||
g_string_append_printf (tmp, "%sIP6_NAMESERVERS=", prefix);
|
||||
|
||||
for (iter = dns; iter; iter = g_slist_next (iter)) {
|
||||
const struct in6_addr *addr = iter->data;
|
||||
gboolean first = TRUE;
|
||||
char buf[INET6_ADDRSTRLEN + 1];
|
||||
|
||||
memset (buf, 0, sizeof (buf));
|
||||
if (inet_ntop (AF_INET6, addr, buf, sizeof (buf))) {
|
||||
if (!first)
|
||||
g_string_append_c (tmp, ' ');
|
||||
g_string_append (tmp, buf);
|
||||
first = FALSE;
|
||||
}
|
||||
if (!first)
|
||||
g_string_append_c (tmp, ' ');
|
||||
g_string_append (tmp, nm_utils_inet6_ntop (addr, NULL));
|
||||
first = FALSE;
|
||||
}
|
||||
|
||||
items = g_slist_prepend (items, tmp->str);
|
||||
|
|
@ -325,23 +291,14 @@ construct_ip6_items (GSList *items, GHashTable *ip6_config, const char *prefix)
|
|||
|
||||
for (iter = routes, num = 0; iter; iter = g_slist_next (iter)) {
|
||||
NMIP6Route *route = (NMIP6Route *) iter->data;
|
||||
char str_addr[INET6_ADDRSTRLEN + 1];
|
||||
char str_nh[INET6_ADDRSTRLEN + 1];
|
||||
const struct in6_addr *tmp_addr;
|
||||
guint32 ip_prefix = nm_ip6_route_get_prefix (route);
|
||||
guint32 metric = nm_ip6_route_get_metric (route);
|
||||
char *routetmp;
|
||||
|
||||
memset (str_addr, 0, sizeof (str_addr));
|
||||
tmp_addr = nm_ip6_route_get_dest (route);
|
||||
if (!inet_ntop (AF_INET6, &tmp_addr, str_addr, sizeof (str_addr)))
|
||||
continue;
|
||||
nm_utils_inet6_ntop (nm_ip6_route_get_dest (route), str_addr);
|
||||
nm_utils_inet6_ntop (nm_ip6_route_get_next_hop (route), str_gw);
|
||||
|
||||
memset (str_nh, 0, sizeof (str_nh));
|
||||
tmp_addr = nm_ip6_route_get_next_hop (route);
|
||||
inet_ntop (AF_INET6, &tmp_addr, str_nh, sizeof (str_nh));
|
||||
|
||||
routetmp = g_strdup_printf ("%sIP6_ROUTE_%d=%s/%d %s %d", prefix, num++, str_addr, ip_prefix, str_nh, metric);
|
||||
routetmp = g_strdup_printf ("%sIP6_ROUTE_%d=%s/%d %s %d", prefix, num++, str_addr, ip_prefix, str_gw, metric);
|
||||
items = g_slist_prepend (items, routetmp);
|
||||
}
|
||||
if (num)
|
||||
|
|
|
|||
|
|
@ -144,18 +144,13 @@ _nm_utils_convert_uint_array_to_string (const GValue *src_value, GValue *dest_va
|
|||
|
||||
printable = g_string_new (NULL);
|
||||
while (array && (i < array->len)) {
|
||||
char buf[INET_ADDRSTRLEN + 1];
|
||||
guint32 addr;
|
||||
|
||||
if (i > 0)
|
||||
g_string_append (printable, ", ");
|
||||
|
||||
memset (buf, 0, sizeof (buf));
|
||||
addr = g_array_index (array, guint32, i++);
|
||||
if (!inet_ntop (AF_INET, &addr, buf, INET_ADDRSTRLEN))
|
||||
g_warning ("%s: error converting IP4 address 0x%X",
|
||||
__func__, ntohl (addr));
|
||||
g_string_append (printable, buf);
|
||||
g_string_append (printable, nm_utils_inet4_ntop (addr, NULL));
|
||||
}
|
||||
|
||||
g_value_take_string (dest_value, g_string_free (printable, FALSE));
|
||||
|
|
@ -167,6 +162,7 @@ _nm_utils_convert_ip4_addr_route_struct_array_to_string (const GValue *src_value
|
|||
GPtrArray *ptr_array;
|
||||
GString *printable;
|
||||
guint i = 0;
|
||||
char buf[INET_ADDRSTRLEN];
|
||||
|
||||
g_return_if_fail (g_type_is_a (G_VALUE_TYPE (src_value), DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UINT));
|
||||
|
||||
|
|
@ -175,8 +171,6 @@ _nm_utils_convert_ip4_addr_route_struct_array_to_string (const GValue *src_value
|
|||
printable = g_string_new (NULL);
|
||||
while (ptr_array && (i < ptr_array->len)) {
|
||||
GArray *array;
|
||||
char buf[INET_ADDRSTRLEN + 1];
|
||||
guint32 addr;
|
||||
gboolean is_addr; /* array contains address x route */
|
||||
|
||||
if (i > 0)
|
||||
|
|
@ -190,11 +184,7 @@ _nm_utils_convert_ip4_addr_route_struct_array_to_string (const GValue *src_value
|
|||
}
|
||||
is_addr = (array->len < 4);
|
||||
|
||||
memset (buf, 0, sizeof (buf));
|
||||
addr = g_array_index (array, guint32, 0);
|
||||
if (!inet_ntop (AF_INET, &addr, buf, INET_ADDRSTRLEN))
|
||||
g_warning ("%s: error converting IP4 address 0x%X",
|
||||
__func__, ntohl (addr));
|
||||
nm_utils_inet4_ntop (g_array_index (array, guint32, 0), buf);
|
||||
if (is_addr)
|
||||
g_string_append_printf (printable, "ip = %s", buf);
|
||||
else
|
||||
|
|
@ -204,11 +194,7 @@ _nm_utils_convert_ip4_addr_route_struct_array_to_string (const GValue *src_value
|
|||
g_array_index (array, guint32, 1));
|
||||
|
||||
if (array->len > 2) {
|
||||
memset (buf, 0, sizeof (buf));
|
||||
addr = g_array_index (array, guint32, 2);
|
||||
if (!inet_ntop (AF_INET, &addr, buf, INET_ADDRSTRLEN))
|
||||
g_warning ("%s: error converting IP4 address 0x%X",
|
||||
__func__, ntohl (addr));
|
||||
nm_utils_inet4_ntop (g_array_index (array, guint32, 2), buf);
|
||||
if (is_addr)
|
||||
g_string_append_printf (printable, ", gw = %s", buf);
|
||||
else
|
||||
|
|
@ -309,23 +295,6 @@ _nm_utils_convert_byte_array_to_string (const GValue *src_value, GValue *dest_va
|
|||
g_value_take_string (dest_value, g_string_free (printable, FALSE));
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_nm_utils_inet6_ntop (struct in6_addr *addr, char *buf)
|
||||
{
|
||||
if (!inet_ntop (AF_INET6, addr, buf, INET6_ADDRSTRLEN)) {
|
||||
int i;
|
||||
GString *ip6_str = g_string_new (NULL);
|
||||
g_string_append_printf (ip6_str, "%02X", addr->s6_addr[0]);
|
||||
for (i = 1; i < 16; i++)
|
||||
g_string_append_printf (ip6_str, " %02X", addr->s6_addr[i]);
|
||||
g_warning ("%s: error converting IP6 address %s",
|
||||
__func__, ip6_str->str);
|
||||
g_string_free (ip6_str, TRUE);
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
_nm_utils_convert_ip6_dns_array_to_string (const GValue *src_value, GValue *dest_value)
|
||||
{
|
||||
|
|
@ -340,7 +309,6 @@ _nm_utils_convert_ip6_dns_array_to_string (const GValue *src_value, GValue *dest
|
|||
printable = g_string_new (NULL);
|
||||
while (ptr_array && (i < ptr_array->len)) {
|
||||
GByteArray *bytearray;
|
||||
char buf[INET6_ADDRSTRLEN];
|
||||
struct in6_addr *addr;
|
||||
|
||||
if (i > 0)
|
||||
|
|
@ -352,9 +320,7 @@ _nm_utils_convert_ip6_dns_array_to_string (const GValue *src_value, GValue *dest
|
|||
continue;
|
||||
}
|
||||
addr = (struct in6_addr *) bytearray->data;
|
||||
memset (buf, 0, sizeof (buf));
|
||||
_nm_utils_inet6_ntop (addr, buf);
|
||||
g_string_append (printable, buf);
|
||||
g_string_append (printable, nm_utils_inet6_ntop (addr, NULL));
|
||||
}
|
||||
|
||||
g_value_take_string (dest_value, g_string_free (printable, FALSE));
|
||||
|
|
@ -376,7 +342,6 @@ _nm_utils_convert_ip6_addr_struct_array_to_string (const GValue *src_value, GVal
|
|||
GValueArray *elements;
|
||||
GValue *tmp;
|
||||
GByteArray *ba_addr;
|
||||
char buf[INET6_ADDRSTRLEN];
|
||||
struct in6_addr *addr;
|
||||
guint32 prefix;
|
||||
|
||||
|
|
@ -401,9 +366,7 @@ _nm_utils_convert_ip6_addr_struct_array_to_string (const GValue *src_value, GVal
|
|||
continue;
|
||||
}
|
||||
addr = (struct in6_addr *) ba_addr->data;
|
||||
memset (buf, 0, sizeof (buf));
|
||||
_nm_utils_inet6_ntop (addr, buf);
|
||||
g_string_append_printf (printable, "ip = %s", buf);
|
||||
g_string_append_printf (printable, "ip = %s", nm_utils_inet6_ntop (addr, NULL));
|
||||
|
||||
/* Prefix */
|
||||
tmp = g_value_array_get_nth (elements, 1);
|
||||
|
|
@ -423,9 +386,7 @@ _nm_utils_convert_ip6_addr_struct_array_to_string (const GValue *src_value, GVal
|
|||
continue;
|
||||
}
|
||||
addr = (struct in6_addr *) ba_addr->data;
|
||||
memset (buf, 0, sizeof (buf));
|
||||
_nm_utils_inet6_ntop (addr, buf);
|
||||
g_string_append_printf (printable, "gw = %s", buf);
|
||||
g_string_append_printf (printable, "gw = %s", nm_utils_inet6_ntop (addr, NULL));
|
||||
g_string_append (printable, " }");
|
||||
}
|
||||
|
||||
|
|
@ -448,7 +409,6 @@ _nm_utils_convert_ip6_route_struct_array_to_string (const GValue *src_value, GVa
|
|||
GValueArray *elements;
|
||||
GValue *tmp;
|
||||
GByteArray *ba_addr;
|
||||
char buf[INET6_ADDRSTRLEN];
|
||||
struct in6_addr *addr;
|
||||
guint32 prefix, metric;
|
||||
|
||||
|
|
@ -474,9 +434,7 @@ _nm_utils_convert_ip6_route_struct_array_to_string (const GValue *src_value, GVa
|
|||
continue;
|
||||
}
|
||||
addr = (struct in6_addr *) ba_addr->data;
|
||||
memset (buf, 0, sizeof (buf));
|
||||
_nm_utils_inet6_ntop (addr, buf);
|
||||
g_string_append_printf (printable, "dst = %s", buf);
|
||||
g_string_append_printf (printable, "dst = %s", nm_utils_inet6_ntop (addr, NULL));
|
||||
|
||||
/* Prefix */
|
||||
tmp = g_value_array_get_nth (elements, 1);
|
||||
|
|
@ -496,9 +454,7 @@ _nm_utils_convert_ip6_route_struct_array_to_string (const GValue *src_value, GVa
|
|||
continue;
|
||||
}
|
||||
addr = (struct in6_addr *) ba_addr->data;
|
||||
memset (buf, 0, sizeof (buf));
|
||||
_nm_utils_inet6_ntop (addr, buf);
|
||||
g_string_append_printf (printable, "nh = %s", buf);
|
||||
g_string_append_printf (printable, "nh = %s", nm_utils_inet6_ntop (addr, NULL));
|
||||
g_string_append (printable, ", ");
|
||||
|
||||
/* Metric */
|
||||
|
|
|
|||
|
|
@ -965,16 +965,14 @@ ip4_process_dhclient_rfc3442_routes (const char *str,
|
|||
/* gateway passed as classless static route */
|
||||
*gwaddr = route.gateway;
|
||||
} else {
|
||||
char addr[INET_ADDRSTRLEN + 1];
|
||||
char nh[INET_ADDRSTRLEN + 1];
|
||||
char addr[INET_ADDRSTRLEN];
|
||||
|
||||
/* normal route */
|
||||
nm_ip4_config_add_route (ip4_config, &route);
|
||||
|
||||
inet_ntop (AF_INET, &route.network, addr, sizeof (addr));
|
||||
inet_ntop (AF_INET, &route.gateway, nh, sizeof (nh));
|
||||
nm_log_info (LOGD_DHCP4, " classless static route %s/%d gw %s",
|
||||
addr, route.plen, nh);
|
||||
nm_utils_inet4_ntop (route.network, addr), route.plen,
|
||||
nm_utils_inet4_ntop (route.gateway, NULL));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1180,10 +1178,7 @@ ip4_options_to_config (NMDHCPClient *self)
|
|||
process_classful_routes (priv->options, ip4_config);
|
||||
|
||||
if (gwaddr) {
|
||||
char buf[INET_ADDRSTRLEN + 1];
|
||||
|
||||
inet_ntop (AF_INET, &gwaddr, buf, sizeof (buf));
|
||||
nm_log_info (LOGD_DHCP4, " gateway %s", buf);
|
||||
nm_log_info (LOGD_DHCP4, " gateway %s", nm_utils_inet4_ntop (gwaddr, NULL));
|
||||
nm_ip4_config_set_gateway (ip4_config, gwaddr);
|
||||
} else {
|
||||
/* If the gateway wasn't provided as a classless static route with a
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@
|
|||
#include <glib/gi18n.h>
|
||||
|
||||
#include "nm-dns-dnsmasq.h"
|
||||
#include "nm-utils.h"
|
||||
#include "nm-logging.h"
|
||||
#include "nm-ip4-config.h"
|
||||
#include "nm-ip6-config.h"
|
||||
|
|
@ -71,7 +72,7 @@ find_dnsmasq (void)
|
|||
static gboolean
|
||||
add_ip4_config (GString *str, NMIP4Config *ip4, gboolean split)
|
||||
{
|
||||
char buf[INET_ADDRSTRLEN + 1];
|
||||
char buf[INET_ADDRSTRLEN];
|
||||
in_addr_t addr;
|
||||
int nnameservers, i_nameserver, n, i;
|
||||
gboolean added = FALSE;
|
||||
|
|
@ -86,9 +87,7 @@ add_ip4_config (GString *str, NMIP4Config *ip4, gboolean split)
|
|||
|
||||
for (i_nameserver = 0; i_nameserver < nnameservers; i_nameserver++) {
|
||||
addr = nm_ip4_config_get_nameserver (ip4, i_nameserver);
|
||||
memset (&buf[0], 0, sizeof (buf));
|
||||
if (!inet_ntop (AF_INET, &addr, buf, sizeof (buf)))
|
||||
return FALSE;
|
||||
nm_utils_inet4_ntop (addr, buf);
|
||||
|
||||
/* searches are preferred over domains */
|
||||
n = nm_ip4_config_get_num_searches (ip4);
|
||||
|
|
@ -126,10 +125,8 @@ add_ip4_config (GString *str, NMIP4Config *ip4, gboolean split)
|
|||
/* If no searches or domains, just add the namservers */
|
||||
if (!added) {
|
||||
for (i = 0; i < nnameservers; i++) {
|
||||
memset (&buf[0], 0, sizeof (buf));
|
||||
addr = nm_ip4_config_get_nameserver (ip4, i);
|
||||
if (inet_ntop (AF_INET, &addr, buf, sizeof (buf)))
|
||||
g_string_append_printf (str, "server=%s\n", buf);
|
||||
g_string_append_printf (str, "server=%s\n", nm_utils_inet4_ntop (addr, NULL));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -860,7 +860,6 @@ nm_ip4_config_dump (const NMIP4Config *config, const char *detail)
|
|||
{
|
||||
guint32 i, tmp;
|
||||
const char *str;
|
||||
char buf[INET_ADDRSTRLEN];
|
||||
|
||||
g_return_if_fail (config != NULL);
|
||||
|
||||
|
|
@ -876,14 +875,12 @@ nm_ip4_config_dump (const NMIP4Config *config, const char *detail)
|
|||
|
||||
/* default gateway */
|
||||
tmp = nm_ip4_config_get_gateway (config);
|
||||
if (inet_ntop (AF_INET, (void *) &tmp, buf, sizeof (buf)))
|
||||
g_message (" gw: %s", buf);
|
||||
g_message (" gw: %s", nm_utils_inet4_ntop (tmp, NULL));
|
||||
|
||||
/* nameservers */
|
||||
for (i = 0; i < nm_ip4_config_get_num_nameservers (config); i++) {
|
||||
tmp = nm_ip4_config_get_nameserver (config, i);
|
||||
if (inet_ntop (AF_INET, (void *) &tmp, buf, sizeof (buf)))
|
||||
g_message (" ns: %s", buf);
|
||||
g_message (" ns: %s", nm_utils_inet4_ntop (tmp, NULL));
|
||||
}
|
||||
|
||||
/* routes */
|
||||
|
|
@ -903,20 +900,16 @@ nm_ip4_config_dump (const NMIP4Config *config, const char *detail)
|
|||
|
||||
/* NIS */
|
||||
for (i = 0; i < nm_ip4_config_get_num_nis_servers (config); i++) {
|
||||
guint32 nis = nm_ip4_config_get_nis_server (config, i);
|
||||
|
||||
if (inet_ntop (AF_INET, (void *) &nis, buf, sizeof (buf)))
|
||||
g_message (" nis: %s", buf);
|
||||
tmp = nm_ip4_config_get_nis_server (config, i);
|
||||
g_message (" nis: %s", nm_utils_inet4_ntop (tmp, NULL));
|
||||
}
|
||||
|
||||
g_message (" nisdmn: %s", nm_ip4_config_get_nis_domain (config));
|
||||
|
||||
/* WINS */
|
||||
for (i = 0; i < nm_ip4_config_get_num_wins (config); i++) {
|
||||
guint32 wins = nm_ip4_config_get_wins (config, i);
|
||||
|
||||
if (inet_ntop (AF_INET, (void *) &wins, buf, sizeof (buf)))
|
||||
g_message (" wins: %s", buf);
|
||||
tmp = nm_ip4_config_get_wins (config, i);
|
||||
g_message (" wins: %s", nm_utils_inet4_ntop (tmp, NULL));
|
||||
}
|
||||
|
||||
g_message (" n-dflt: %d", nm_ip4_config_get_never_default (config));
|
||||
|
|
@ -1576,10 +1569,9 @@ get_property (GObject *object, guint prop_id,
|
|||
|
||||
switch (prop_id) {
|
||||
case PROP_GATEWAY:
|
||||
if (priv->gateway) {
|
||||
char addr_buf[INET_ADDRSTRLEN];
|
||||
g_value_set_string (value, inet_ntop (AF_INET, &priv->gateway, addr_buf, sizeof (addr_buf)));
|
||||
} else
|
||||
if (priv->gateway)
|
||||
g_value_set_string (value, nm_utils_inet4_ntop (priv->gateway, NULL));
|
||||
else
|
||||
g_value_set_string (value, NULL);
|
||||
break;
|
||||
case PROP_ADDRESSES:
|
||||
|
|
|
|||
|
|
@ -791,7 +791,6 @@ nm_ip6_config_dump (const NMIP6Config *config, const char *detail)
|
|||
const struct in6_addr *tmp;
|
||||
guint32 i;
|
||||
const char *str;
|
||||
char buf[INET6_ADDRSTRLEN];
|
||||
|
||||
g_return_if_fail (config != NULL);
|
||||
|
||||
|
|
@ -807,14 +806,13 @@ nm_ip6_config_dump (const NMIP6Config *config, const char *detail)
|
|||
|
||||
/* default gateway */
|
||||
tmp = nm_ip6_config_get_gateway (config);
|
||||
if (tmp && inet_ntop (AF_INET6, tmp, buf, sizeof (buf)))
|
||||
g_message (" gw: %s", buf);
|
||||
if (tmp)
|
||||
g_message (" gw: %s", nm_utils_inet6_ntop (tmp, NULL));
|
||||
|
||||
/* nameservers */
|
||||
for (i = 0; i < nm_ip6_config_get_num_nameservers (config); i++) {
|
||||
tmp = nm_ip6_config_get_nameserver (config, i);
|
||||
if (inet_ntop (AF_INET6, tmp, buf, sizeof (buf)))
|
||||
g_message (" ns: %s", buf);
|
||||
g_message (" ns: %s", nm_utils_inet6_ntop (tmp, NULL));
|
||||
}
|
||||
|
||||
/* routes */
|
||||
|
|
@ -1355,10 +1353,9 @@ get_property (GObject *object, guint prop_id,
|
|||
|
||||
switch (prop_id) {
|
||||
case PROP_GATEWAY:
|
||||
if (!IN6_IS_ADDR_UNSPECIFIED (&priv->gateway)) {
|
||||
char addr_buf[INET6_ADDRSTRLEN];
|
||||
g_value_set_string (value, inet_ntop (AF_INET6, &priv->gateway, addr_buf, sizeof (addr_buf)));
|
||||
} else
|
||||
if (!IN6_IS_ADDR_UNSPECIFIED (&priv->gateway))
|
||||
g_value_set_string (value, nm_utils_inet6_ntop (&priv->gateway, NULL));
|
||||
else
|
||||
g_value_set_string (value, NULL);
|
||||
break;
|
||||
case PROP_ADDRESSES:
|
||||
|
|
|
|||
|
|
@ -510,37 +510,6 @@ plugin_state_changed (DBusGProxy *proxy,
|
|||
}
|
||||
}
|
||||
|
||||
static char addr_to_string_buf[INET6_ADDRSTRLEN + 1];
|
||||
|
||||
static const char *
|
||||
ip_address_to_string (guint32 numeric)
|
||||
{
|
||||
guint32 temp_addr;
|
||||
|
||||
memset (&addr_to_string_buf, '\0', sizeof (addr_to_string_buf));
|
||||
temp_addr = numeric;
|
||||
|
||||
if (inet_ntop (AF_INET, &temp_addr, addr_to_string_buf, INET_ADDRSTRLEN)) {
|
||||
return addr_to_string_buf;
|
||||
} else {
|
||||
nm_log_warn (LOGD_VPN, "error converting IP4 address 0x%X",
|
||||
ntohl (temp_addr));
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static const char *
|
||||
ip6_address_to_string (const struct in6_addr *addr)
|
||||
{
|
||||
memset (addr_to_string_buf, '\0', sizeof (addr_to_string_buf));
|
||||
if (inet_ntop (AF_INET6, addr, addr_to_string_buf, INET6_ADDRSTRLEN)) {
|
||||
return addr_to_string_buf;
|
||||
} else {
|
||||
nm_log_warn (LOGD_VPN, "error converting IP6 address");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
print_vpn_config (NMVPNConnection *connection)
|
||||
{
|
||||
|
|
@ -549,13 +518,14 @@ print_vpn_config (NMVPNConnection *connection)
|
|||
const NMPlatformIP6Address *address6;
|
||||
char *dns_domain = NULL;
|
||||
guint32 num, i;
|
||||
char buf[NM_UTILS_INET_ADDRSTRLEN];
|
||||
|
||||
if (priv->ip4_external_gw) {
|
||||
nm_log_info (LOGD_VPN, "VPN Gateway: %s",
|
||||
ip_address_to_string (priv->ip4_external_gw));
|
||||
nm_utils_inet4_ntop (priv->ip4_external_gw, NULL));
|
||||
} else if (priv->ip6_external_gw) {
|
||||
nm_log_info (LOGD_VPN, "VPN Gateway: %s",
|
||||
ip6_address_to_string (priv->ip6_external_gw));
|
||||
nm_utils_inet6_ntop (priv->ip6_external_gw, NULL));
|
||||
}
|
||||
|
||||
nm_log_info (LOGD_VPN, "Tunnel Device: %s", priv->ip_iface);
|
||||
|
|
@ -566,22 +536,20 @@ print_vpn_config (NMVPNConnection *connection)
|
|||
address4 = nm_ip4_config_get_address (priv->ip4_config, 0);
|
||||
|
||||
if (priv->ip4_internal_gw)
|
||||
nm_log_info (LOGD_VPN, " Internal Gateway: %s", ip_address_to_string (priv->ip4_internal_gw));
|
||||
nm_log_info (LOGD_VPN, " Internal Address: %s", ip_address_to_string (address4->address));
|
||||
nm_log_info (LOGD_VPN, " Internal Gateway: %s", nm_utils_inet4_ntop (priv->ip4_internal_gw, NULL));
|
||||
nm_log_info (LOGD_VPN, " Internal Address: %s", nm_utils_inet4_ntop (address4->address, NULL));
|
||||
nm_log_info (LOGD_VPN, " Internal Prefix: %d", address4->plen);
|
||||
nm_log_info (LOGD_VPN, " Internal Point-to-Point Address: %s", ip_address_to_string (address4->peer_address));
|
||||
nm_log_info (LOGD_VPN, " Internal Point-to-Point Address: %s", nm_utils_inet4_ntop (address4->peer_address, NULL));
|
||||
nm_log_info (LOGD_VPN, " Maximum Segment Size (MSS): %d", nm_ip4_config_get_mss (priv->ip4_config));
|
||||
|
||||
num = nm_ip4_config_get_num_routes (priv->ip4_config);
|
||||
for (i = 0; i < num; i++) {
|
||||
const NMPlatformIP4Route *route = nm_ip4_config_get_route (priv->ip4_config, i);
|
||||
char *s = g_strdup (ip_address_to_string (route->gateway));
|
||||
|
||||
nm_log_info (LOGD_VPN, " Static Route: %s/%d Next Hop: %s",
|
||||
ip_address_to_string (route->network),
|
||||
nm_utils_inet4_ntop (route->network, NULL),
|
||||
route->plen,
|
||||
s);
|
||||
g_free (s);
|
||||
nm_utils_inet4_ntop (route->gateway, buf));
|
||||
}
|
||||
|
||||
nm_log_info (LOGD_VPN, " Forbid Default Route: %s",
|
||||
|
|
@ -590,7 +558,7 @@ print_vpn_config (NMVPNConnection *connection)
|
|||
num = nm_ip4_config_get_num_nameservers (priv->ip4_config);
|
||||
for (i = 0; i < num; i++) {
|
||||
nm_log_info (LOGD_VPN, " Internal DNS: %s",
|
||||
ip_address_to_string (nm_ip4_config_get_nameserver (priv->ip4_config, i)));
|
||||
nm_utils_inet4_ntop (nm_ip4_config_get_nameserver (priv->ip4_config, i), NULL));
|
||||
}
|
||||
|
||||
if (nm_ip4_config_get_num_domains (priv->ip4_config) > 0)
|
||||
|
|
@ -606,22 +574,20 @@ print_vpn_config (NMVPNConnection *connection)
|
|||
address6 = nm_ip6_config_get_address (priv->ip6_config, 0);
|
||||
|
||||
if (priv->ip6_internal_gw)
|
||||
nm_log_info (LOGD_VPN, " Internal Gateway: %s", ip6_address_to_string (priv->ip6_internal_gw));
|
||||
nm_log_info (LOGD_VPN, " Internal Address: %s", ip6_address_to_string (&address6->address));
|
||||
nm_log_info (LOGD_VPN, " Internal Gateway: %s", nm_utils_inet6_ntop (priv->ip6_internal_gw, NULL));
|
||||
nm_log_info (LOGD_VPN, " Internal Address: %s", nm_utils_inet6_ntop (&address6->address, NULL));
|
||||
nm_log_info (LOGD_VPN, " Internal Prefix: %d", address6->plen);
|
||||
nm_log_info (LOGD_VPN, " Internal Point-to-Point Address: %s", ip6_address_to_string (&address6->peer_address));
|
||||
nm_log_info (LOGD_VPN, " Internal Point-to-Point Address: %s", nm_utils_inet6_ntop (&address6->peer_address, NULL));
|
||||
nm_log_info (LOGD_VPN, " Maximum Segment Size (MSS): %d", nm_ip6_config_get_mss (priv->ip6_config));
|
||||
|
||||
num = nm_ip6_config_get_num_routes (priv->ip6_config);
|
||||
for (i = 0; i < num; i++) {
|
||||
const NMPlatformIP6Route *route = nm_ip6_config_get_route (priv->ip6_config, i);
|
||||
char *s = g_strdup (ip6_address_to_string (&route->gateway));
|
||||
|
||||
nm_log_info (LOGD_VPN, " Static Route: %s/%d Next Hop: %s",
|
||||
ip6_address_to_string (&route->network),
|
||||
nm_utils_inet6_ntop (&route->network, NULL),
|
||||
route->plen,
|
||||
s);
|
||||
g_free (s);
|
||||
nm_utils_inet6_ntop (&route->gateway, buf));
|
||||
}
|
||||
|
||||
nm_log_info (LOGD_VPN, " Forbid Default Route: %s",
|
||||
|
|
@ -630,7 +596,7 @@ print_vpn_config (NMVPNConnection *connection)
|
|||
num = nm_ip6_config_get_num_nameservers (priv->ip6_config);
|
||||
for (i = 0; i < num; i++) {
|
||||
nm_log_info (LOGD_VPN, " Internal DNS: %s",
|
||||
ip6_address_to_string (nm_ip6_config_get_nameserver (priv->ip6_config, i)));
|
||||
nm_utils_inet6_ntop (nm_ip6_config_get_nameserver (priv->ip6_config, i), NULL));
|
||||
}
|
||||
|
||||
if (nm_ip6_config_get_num_domains (priv->ip6_config) > 0)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue