summaryrefslogtreecommitdiff
path: root/libnm-util
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2017-06-02 13:15:18 +0200
committerThomas Haller <thaller@redhat.com>2017-06-02 14:07:10 +0200
commitea6648cea13219fac81b01f1ea85292a08f671b3 (patch)
treef2adf1d146a808041ce694ce194e0eca68c90966 /libnm-util
parentc0419257e70cc64c889a9a906445a74efb92dc44 (diff)
downloadNetworkManager-ea6648cea13219fac81b01f1ea85292a08f671b3.tar.gz
all: replace uses of inet_aton() and friends
rpmdiff complains about uses of inet_aton, inet_makeaddr, inet_netof, inet_ntoa under the IPv6 section: usr/sbin/NetworkManager on aarch64 i686 x86_64 ppc ppc64 ppc64le s390 s390x uses function inet_aton, which may impact IPv6 support I think the warning is bogus, but refactor our code to avoid it. Note that systemd code still uses them, so it don't avoid the rpmdiff warning. But let's not diverge our systemd import from upstream for this. - for NMSettingBond:validate_ip() also avoid g_strsplit_set() which allocates a full strv. Instead, we can do with one g_strdup(). - for test-resolvconf-capture.c, replace the functions with macros. Macros should be avoided usually, but for test asserts they are more convenient as they preserved the __FILE__:__LINE__ of where the assertion fails.
Diffstat (limited to 'libnm-util')
-rw-r--r--libnm-util/nm-setting-bond.c29
1 files changed, 22 insertions, 7 deletions
diff --git a/libnm-util/nm-setting-bond.c b/libnm-util/nm-setting-bond.c
index 8a11bc23e9..f56cb428cf 100644
--- a/libnm-util/nm-setting-bond.c
+++ b/libnm-util/nm-setting-bond.c
@@ -258,19 +258,34 @@ validate_list (const char *name, const char *value, const BondDefault *def)
static gboolean
validate_ip (const char *name, const char *value)
{
- char **ips, **iter;
- gboolean success = TRUE;
+ gs_free char *value_clone = NULL;
struct in_addr addr;
if (!value || !value[0])
return FALSE;
- ips = g_strsplit_set (value, ",", 0);
- for (iter = ips; iter && *iter && success; iter++)
- success = !!inet_aton (*iter, &addr);
- g_strfreev (ips);
+ value_clone = g_strdup (value);
+ value = value_clone;
+ for (;;) {
+ char *eow;
- return success;
+ /* we do not skip over empty words. E.g
+ * "192.168.1.1," is an error.
+ *
+ * ... for no particular reason. */
+
+ eow = strchr (value, ',');
+ if (eow)
+ *eow = '\0';
+
+ if (inet_pton (AF_INET, value, &addr) != 1)
+ return FALSE;
+
+ if (!eow)
+ break;
+ value = eow + 1;
+ }
+ return TRUE;
}
static gboolean