dns: fix compiler warning by refactoring use of inet_ntop
Use nm_utils_inet4_ntop() and nm_utils_inet6_ntop() instead. And get rid of the unneeded error-checking. gcc warns: make[4]: Entering directory `/data/src/NetworkManager/src' CC nm-dns-manager.lo dns-manager/nm-dns-manager.c: In function 'merge_one_ip4_config': dns-manager/nm-dns-manager.c:137:37: warning: ordered comparison of pointer with integer zero [-Wextra] if (inet_ntop (AF_INET, &addr, buf, INET_ADDRSTRLEN) > 0) ^ dns-manager/nm-dns-manager.c:168:37: warning: ordered comparison of pointer with integer zero [-Wextra] if (inet_ntop (AF_INET, &addr, buf, INET_ADDRSTRLEN) > 0) ^ dns-manager/nm-dns-manager.c: In function 'merge_one_ip6_config': dns-manager/nm-dns-manager.c:197:64: warning: ordered comparison of pointer with integer zero [-Wextra] if (inet_ntop (AF_INET, &(addr->s6_addr32[3]), buf, INET_ADDRSTRLEN) > 0) ^ dns-manager/nm-dns-manager.c:200:38: warning: ordered comparison of pointer with integer zero [-Wextra] if (inet_ntop (AF_INET6, addr, buf, INET6_ADDRSTRLEN) > 0) { ^ Signed-off-by: Thomas Haller <thaller@redhat.com>
This commit is contained in:
@@ -35,6 +35,7 @@
|
|||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include <glib/gi18n.h>
|
#include <glib/gi18n.h>
|
||||||
|
|
||||||
|
#include "libnm-util/nm-utils.h"
|
||||||
#include "nm-dns-manager.h"
|
#include "nm-dns-manager.h"
|
||||||
#include "nm-ip4-config.h"
|
#include "nm-ip4-config.h"
|
||||||
#include "nm-ip6-config.h"
|
#include "nm-ip6-config.h"
|
||||||
@@ -130,12 +131,8 @@ merge_one_ip4_config (NMResolvConfData *rc, NMIP4Config *src)
|
|||||||
|
|
||||||
num = nm_ip4_config_get_num_nameservers (src);
|
num = nm_ip4_config_get_num_nameservers (src);
|
||||||
for (i = 0; i < num; i++) {
|
for (i = 0; i < num; i++) {
|
||||||
guint32 addr;
|
add_string_item (rc->nameservers,
|
||||||
char buf[INET_ADDRSTRLEN];
|
nm_utils_inet4_ntop (nm_ip4_config_get_nameserver (src, i), NULL));
|
||||||
|
|
||||||
addr = nm_ip4_config_get_nameserver (src, i);
|
|
||||||
if (inet_ntop (AF_INET, &addr, buf, INET_ADDRSTRLEN) > 0)
|
|
||||||
add_string_item (rc->nameservers, buf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
num = nm_ip4_config_get_num_domains (src);
|
num = nm_ip4_config_get_num_domains (src);
|
||||||
@@ -161,12 +158,8 @@ merge_one_ip4_config (NMResolvConfData *rc, NMIP4Config *src)
|
|||||||
/* NIS stuff */
|
/* NIS stuff */
|
||||||
num = nm_ip4_config_get_num_nis_servers (src);
|
num = nm_ip4_config_get_num_nis_servers (src);
|
||||||
for (i = 0; i < num; i++) {
|
for (i = 0; i < num; i++) {
|
||||||
guint32 addr;
|
add_string_item (rc->nis_servers,
|
||||||
char buf[INET_ADDRSTRLEN];
|
nm_utils_inet4_ntop (nm_ip4_config_get_nis_server (src, i), NULL));
|
||||||
|
|
||||||
addr = nm_ip4_config_get_nis_server (src, i);
|
|
||||||
if (inet_ntop (AF_INET, &addr, buf, INET_ADDRSTRLEN) > 0)
|
|
||||||
add_string_item (rc->nis_servers, buf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nm_ip4_config_get_nis_domain (src)) {
|
if (nm_ip4_config_get_nis_domain (src)) {
|
||||||
@@ -187,26 +180,22 @@ merge_one_ip6_config (NMResolvConfData *rc, NMIP6Config *src)
|
|||||||
num = nm_ip6_config_get_num_nameservers (src);
|
num = nm_ip6_config_get_num_nameservers (src);
|
||||||
for (i = 0; i < num; i++) {
|
for (i = 0; i < num; i++) {
|
||||||
const struct in6_addr *addr;
|
const struct in6_addr *addr;
|
||||||
char buf[INET6_ADDRSTRLEN];
|
char buf[NM_UTILS_INET_ADDRSTRLEN + 50];
|
||||||
char *tmp;
|
|
||||||
|
|
||||||
addr = nm_ip6_config_get_nameserver (src, i);
|
addr = nm_ip6_config_get_nameserver (src, i);
|
||||||
|
|
||||||
/* inet_ntop is probably supposed to do this for us, but it doesn't */
|
/* inet_ntop is probably supposed to do this for us, but it doesn't */
|
||||||
if (IN6_IS_ADDR_V4MAPPED (addr)) {
|
if (IN6_IS_ADDR_V4MAPPED (addr))
|
||||||
if (inet_ntop (AF_INET, &(addr->s6_addr32[3]), buf, INET_ADDRSTRLEN) > 0)
|
nm_utils_inet4_ntop (addr->s6_addr32[3], buf);
|
||||||
add_string_item (rc->nameservers, buf);
|
else {
|
||||||
} else {
|
nm_utils_inet6_ntop (addr, buf);
|
||||||
if (inet_ntop (AF_INET6, addr, buf, INET6_ADDRSTRLEN) > 0) {
|
|
||||||
if (iface && IN6_IS_ADDR_LINKLOCAL (addr)) {
|
if (iface && IN6_IS_ADDR_LINKLOCAL (addr)) {
|
||||||
tmp = g_strdup_printf ("%s%%%s", buf, iface);
|
g_strlcat (buf, "%", sizeof (buf));
|
||||||
add_string_item (rc->nameservers, tmp);
|
g_strlcat (buf, iface, sizeof (buf));
|
||||||
g_free (tmp);
|
}
|
||||||
} else
|
}
|
||||||
add_string_item (rc->nameservers, buf);
|
add_string_item (rc->nameservers, buf);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
num = nm_ip6_config_get_num_domains (src);
|
num = nm_ip6_config_get_num_domains (src);
|
||||||
for (i = 0; i < num; i++) {
|
for (i = 0; i < num; i++) {
|
||||||
|
Reference in New Issue
Block a user