NetworkManager r3777 - in trunk: . libnm-glib libnm-util src src/backends src/dhcp-manager src/named-manager src/vpn-manager system-settings/plugins/ifcfg-fedora system-settings/plugins/ifcfg-suse system-settings/plugins/keyfile test vpn-daemons/openvpn/src vpn-daemons/pptp/src vpn-daemons/vpnc/src



Author: dcbw
Date: Thu Jun 26 19:33:13 2008
New Revision: 3777
URL: http://svn.gnome.org/viewvc/NetworkManager?rev=3777&view=rev

Log:
2008-06-26  Dan Williams <dcbw redhat com>

	Patch from David Cantrell <dcantrell redhat com>
	
	* Use inet_ntop() and inet_pton() everwhere and check for errors



Modified:
   trunk/ChangeLog
   trunk/libnm-glib/libnm-glib-test.c
   trunk/libnm-util/nm-utils.c
   trunk/src/autoip.c
   trunk/src/backends/NetworkManagerSuSE.c
   trunk/src/dhcp-manager/nm-dhcp-manager.c
   trunk/src/named-manager/nm-named-manager.c
   trunk/src/vpn-manager/nm-vpn-connection.c
   trunk/system-settings/plugins/ifcfg-fedora/reader.c
   trunk/system-settings/plugins/ifcfg-suse/parser.c
   trunk/system-settings/plugins/keyfile/writer.c
   trunk/test/nm-dhcp-opt-test.c
   trunk/test/nm-tool.c
   trunk/vpn-daemons/openvpn/src/nm-openvpn-service-openvpn-helper.c
   trunk/vpn-daemons/openvpn/src/nm-openvpn-service.c
   trunk/vpn-daemons/pptp/src/nm-ppp-starter.c
   trunk/vpn-daemons/vpnc/src/nm-vpnc-service-vpnc-helper.c

Modified: trunk/libnm-glib/libnm-glib-test.c
==============================================================================
--- trunk/libnm-glib/libnm-glib-test.c	(original)
+++ trunk/libnm-glib/libnm-glib-test.c	Thu Jun 26 19:33:13 2008
@@ -1,5 +1,6 @@
 #include <stdlib.h>
 #include <signal.h>
+#include <string.h>
 
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -47,13 +48,19 @@
 static gchar *
 ip4_address_as_string (guint32 ip)
 {
+	char buf[INET_ADDRSTRLEN+1];
 	struct in_addr tmp_addr;
-	gchar *ip_string;
 
+	memset (&buf, '\0', sizeof (buf));
 	tmp_addr.s_addr = ip;
-	ip_string = inet_ntoa (tmp_addr);
 
-	return g_strdup (ip_string);
+	if (inet_ntop (AF_INET, &tmp_addr, buf, INET_ADDRSTRLEN)) {
+		return g_strdup (buf);
+	} else {
+		nm_warning ("%s: error converting IP4 address 0x%X",
+		            __func__, ntohl (tmp_addr.s_addr));
+		return NULL;
+	}
 }
 
 static void

Modified: trunk/libnm-util/nm-utils.c
==============================================================================
--- trunk/libnm-util/nm-utils.c	(original)
+++ trunk/libnm-util/nm-utils.c	Thu Jun 26 19:33:13 2008
@@ -490,7 +490,9 @@
 
 		memset (buf, 0, sizeof (buf));
 		addr.s_addr = g_array_index (array, guint32, i++);
-		inet_ntop (AF_INET, &addr, buf, INET_ADDRSTRLEN);
+		if (!inet_ntop (AF_INET, &addr, buf, INET_ADDRSTRLEN))
+			nm_warning ("%s: error converting IP4 address 0x%X",
+			            __func__, ntohl (addr.s_addr));
 		g_string_append_printf (printable, "%u (%s)", addr.s_addr, buf);
 	}
 	g_string_append_c (printable, ']');
@@ -528,13 +530,17 @@
 
 		memset (buf, 0, sizeof (buf));
 		addr.s_addr = g_array_index (array, guint32, 0);
-		inet_ntop (AF_INET, &addr, buf, INET_ADDRSTRLEN);
+		if (!inet_ntop (AF_INET, &addr, buf, INET_ADDRSTRLEN))
+			nm_warning ("%s: error converting IP4 address 0x%X",
+			            __func__, ntohl (addr.s_addr));
 		g_string_append_printf (printable, "ip = %s", buf);
 		g_string_append (printable, ", ");
 
 		memset (buf, 0, sizeof (buf));
 		addr.s_addr = g_array_index (array, guint32, 1);
-		inet_ntop (AF_INET, &addr, buf, INET_ADDRSTRLEN);
+		if (!inet_ntop (AF_INET, &addr, buf, INET_ADDRSTRLEN))
+			nm_warning ("%s: error converting IP4 address 0x%X",
+			            __func__, ntohl (addr.s_addr));
 		g_string_append_printf (printable, "mask = %s", buf);
 
 		if (array->len > 2) {
@@ -542,7 +548,9 @@
 
 			memset (buf, 0, sizeof (buf));
 			addr.s_addr = g_array_index (array, guint32, 2);
-			inet_ntop (AF_INET, &addr, buf, INET_ADDRSTRLEN);
+			if (!inet_ntop (AF_INET, &addr, buf, INET_ADDRSTRLEN))
+				nm_warning ("%s: error converting IP4 address 0x%X",
+				            __func__, ntohl (addr.s_addr));
 			g_string_append_printf (printable, "gw = %s", buf);
 		}
 

Modified: trunk/src/autoip.c
==============================================================================
--- trunk/src/autoip.c	(original)
+++ trunk/src/autoip.c	Thu Jun 26 19:33:13 2008
@@ -214,6 +214,9 @@
 	int				nannounce = 0;
 	gboolean			success = FALSE;
 	const char *iface;
+	char buf[INET_ADDRSTRLEN+1];
+
+	memset(&buf, '\0', sizeof (buf));
 
 	g_return_val_if_fail (dev != NULL, FALSE);
 	g_return_val_if_fail (out_ip != NULL, FALSE);
@@ -262,7 +265,12 @@
 
 		if (nprobes < PROBE_NUM)
 		{
-			nm_info ("autoip: Sending probe #%d for IP address %s.", nprobes, inet_ntoa (ip));
+			if (!inet_ntop (AF_INET, &ip, buf, INET_ADDRSTRLEN)) {
+				nm_warning ("%s: error converting IP4 address 0x%X",
+				            __func__, ntohl (ip.s_addr));
+				continue;
+			}
+			nm_info ("autoip: Sending probe #%d for IP address %s.", nprobes, buf);
 			arp (fd, &saddr, ARPOP_REQUEST, &addr, null_ip, &null_addr, ip);
 			nprobes++;
 			gettimeofday (&timeout, NULL);
@@ -284,7 +292,12 @@
 		}
 		else if (nannounce < ANNOUNCE_NUM)
 		{
-			nm_info ("autoip: Sending announce #%d for IP address %s.", nannounce, inet_ntoa (ip));
+			if (!inet_ntop (AF_INET, &ip, buf, INET_ADDRSTRLEN)) {
+				nm_warning ("%s: error converting IP4 address 0x%X",
+				            __func__, ntohl (ip.s_addr));
+				continue;
+			}
+			nm_info ("autoip: Sending announce #%d for IP address %s.", nannounce, buf);
 			arp (fd, &saddr, ARPOP_REQUEST, &addr, ip, &addr, ip);
 			nannounce++;
 			gettimeofday (&timeout, NULL);
@@ -319,10 +332,20 @@
 			{
 				struct in_addr a;
 				memcpy (&(a.s_addr), &(p.sInaddr), sizeof (a.s_addr));
-				nm_warning (" source = %s %02X:%02X:%02X:%02X:%02X:%02X, ", inet_ntoa (a),
+				if (!inet_ntop (AF_INET, &a, buf, INET_ADDRSTRLEN)) {
+					nm_warning ("%s: error converting IP4 address 0x%X",
+					            __func__, ntohl (a.s_addr));
+					continue;
+				}
+				nm_warning (" source = %s %02X:%02X:%02X:%02X:%02X:%02X, ", buf,
 					p.sHaddr[0], p.sHaddr[1], p.sHaddr[2], p.sHaddr[3], p.sHaddr[4], p.sHaddr[5]);
 				memcpy (&(a.s_addr), &(p.tInaddr), sizeof (a.s_addr));
-				nm_warning (" target = %s %02X:%02X:%02X:%02X:%02X:%02X\n", inet_ntoa (a),
+				if (!inet_ntop (AF_INET, &a, buf, INET_ADDRSTRLEN)) {
+					nm_warning ("%s: error converting IP4 address 0x%X",
+					            __func__, ntohl (a.s_addr));
+					continue;
+				}
+				nm_warning (" target = %s %02X:%02X:%02X:%02X:%02X:%02X\n", buf,
 					p.tHaddr[0], p.tHaddr[1], p.tHaddr[2], p.tHaddr[3], p.tHaddr[4], p.tHaddr[5]);
 			}
 		#endif
@@ -333,7 +356,12 @@
 				&& (memcmp (&addr, &p.tHaddr, ETH_ALEN) != 0))
 			{
 			#ifdef ARP_DEBUG
-				nm_warning ("autoip: (%s) ARP conflict for IP address %s.\n", iface, inet_ntoa(ip));
+				if (!inet_ntop (AF_INET, &ip, buf, INET_ADDRSTRLEN)) {
+					nm_warning ("%s: error converting IP4 address 0x%X",
+					            __func__, ntohl (ip.s_addr));
+					continue;
+				}
+				nm_warning ("autoip: (%s) ARP conflict for IP address %s.\n", iface, buf);
 			#endif
 
 				/* Ok, start all over again */

Modified: trunk/src/backends/NetworkManagerSuSE.c
==============================================================================
--- trunk/src/backends/NetworkManagerSuSE.c	(original)
+++ trunk/src/backends/NetworkManagerSuSE.c	Thu Jun 26 19:33:13 2008
@@ -106,6 +106,9 @@
 	struct in_addr	temp_addr;
 	int i;
 	FILE *ypconf = NULL;
+	char buf[INET_ADDRSTRLEN+1];
+
+	memset (&buf, '\0', sizeof (buf));
 
 	g_return_if_fail (config != NULL);
 
@@ -145,7 +148,12 @@
 				fprintf (ypconf, "# generated by NetworkManager, do not edit!\n\n");
 				for (i = 0; i < num_nis_servers; i++) {
 					temp_addr.s_addr = nm_ip4_config_get_nis_server (config, i);
-					fprintf (ypconf, "domain %s server %s\n", nis_domain, inet_ntoa (temp_addr));
+
+					if (!inet_ntop (AF_INET, &temp_addr, buf, INET_ADDRSTRLEN))
+						nm_warning ("%s: error converting IP4 address 0x%X",
+						            __func__, ntohl (tempaddr.s_addr));
+					else
+						fprintf (ypconf, "domain %s server %s\n", nis_domain, buf);
 				}
 				fprintf (ypconf, "\n");
 				fclose (ypconf);

Modified: trunk/src/dhcp-manager/nm-dhcp-manager.c
==============================================================================
--- trunk/src/dhcp-manager/nm-dhcp-manager.c	(original)
+++ trunk/src/dhcp-manager/nm-dhcp-manager.c	Thu Jun 26 19:33:13 2008
@@ -889,20 +889,20 @@
 	}
 
 	str = g_hash_table_lookup (device->options, "new_ip_address");
-	if (str && inet_aton (str, &tmp_addr)) {
+	if (str && (inet_pton (AF_INET, str, &tmp_addr) > 0)) {
 		addr->address = tmp_addr.s_addr;
 		nm_info ("  address %s", str);
 	} else
 		goto error;
 
 	str = g_hash_table_lookup (device->options, "new_subnet_mask");
-	if (str && inet_aton (str, &tmp_addr)) {
+	if (str && (inet_pton (AF_INET, str, &tmp_addr) > 0)) {
 		addr->netmask = tmp_addr.s_addr;
 		nm_info ("  netmask %s", str);
 	}
 
 	str = g_hash_table_lookup (device->options, "new_routers");
-	if (str && inet_aton (str, &tmp_addr)) {
+	if (str && (inet_pton (AF_INET, str, &tmp_addr) > 0)) {
 		addr->gateway = tmp_addr.s_addr;
 		nm_info("  gateway %s", str);
 	}
@@ -922,7 +922,7 @@
 		char **s;
 
 		for (s = searches; *s; s++) {
-			if (inet_aton (*s, &tmp_addr)) {
+			if (inet_pton (AF_INET, *s, &tmp_addr) > 0) {
 				nm_ip4_config_add_nameserver (ip4_config, tmp_addr.s_addr);
 				nm_info ("  nameserver '%s'", *s);
 			} else
@@ -967,7 +967,7 @@
 		char **s;
 
 		for (s = searches; *s; s++) {
-			if (inet_aton (*s, &tmp_addr)) {
+			if (inet_pton (AF_INET, *s, &tmp_addr) > 0) {
 				nm_ip4_config_add_nis_server (ip4_config, tmp_addr.s_addr);
 				nm_info ("  nis server '%s'", *s);
 			} else
@@ -987,11 +987,11 @@
 				struct in_addr rt_addr;
 				struct in_addr rt_route;
 
-				if (inet_aton (*s, &rt_addr) == 0) {
+				if (inet_pton (AF_INET, *s, &rt_addr) <= 0) {
 					nm_warning ("DHCP provided invalid static route address: '%s'", *s);
 					continue;
 				}
-				if (inet_aton (*(s + 1), &rt_route) == 0) {
+				if (inet_pton (AF_INET, *(s + 1), &rt_route) <= 0) {
 					nm_warning ("DHCP provided invalid static route gateway: '%s'", *(s + 1));
 					continue;
 				}

Modified: trunk/src/named-manager/nm-named-manager.c
==============================================================================
--- trunk/src/named-manager/nm-named-manager.c	(original)
+++ trunk/src/named-manager/nm-named-manager.c	Thu Jun 26 19:33:13 2008
@@ -108,7 +108,9 @@
 		if (!buf)
 			continue;
 
-		inet_ntop (AF_INET, &addr, buf, ADDR_BUF_LEN);
+		if (!inet_ntop (AF_INET, &addr, buf, ADDR_BUF_LEN))
+			nm_warning ("%s: error converting IP4 address 0x%X",
+			            __func__, ntohl (addr.s_addr));
 
 		if (i == 3) {
 			g_string_append (str, "\n# ");

Modified: trunk/src/vpn-manager/nm-vpn-connection.c
==============================================================================
--- trunk/src/vpn-manager/nm-vpn-connection.c	(original)
+++ trunk/src/vpn-manager/nm-vpn-connection.c	Thu Jun 26 19:33:13 2008
@@ -261,9 +261,18 @@
 ip_address_to_string (guint32 numeric)
 {
 	struct in_addr temp_addr;
+	char buf[INET_ADDRSTRLEN+1];
 
+	memset (&buf, '\0', sizeof (buf));
 	temp_addr.s_addr = numeric;
-	return inet_ntoa (temp_addr);
+
+	if (inet_ntop (AF_INET, &temp_addr, buf, INET_ADDRSTRLEN)) {
+		return g_strdup (buf);
+	} else {
+		nm_warning ("%s: error converting IP4 address 0x%X",
+		            __func__, ntohl (temp_addr.s_addr));
+		return NULL;
+	}
 }
 
 static void

Modified: trunk/system-settings/plugins/ifcfg-fedora/reader.c
==============================================================================
--- trunk/system-settings/plugins/ifcfg-fedora/reader.c	(original)
+++ trunk/system-settings/plugins/ifcfg-fedora/reader.c	Thu Jun 26 19:33:13 2008
@@ -137,7 +137,7 @@
 	if (!value)
 		return;
 
-	if (inet_pton (AF_INET, value, &ip4_addr))
+	if (inet_pton (AF_INET, value, &ip4_addr) > 0)
 		*out_addr = ip4_addr.s_addr;
 	else {
 		g_set_error (error, ifcfg_plugin_error_quark (), 0,

Modified: trunk/system-settings/plugins/ifcfg-suse/parser.c
==============================================================================
--- trunk/system-settings/plugins/ifcfg-suse/parser.c	(original)
+++ trunk/system-settings/plugins/ifcfg-suse/parser.c	Thu Jun 26 19:33:13 2008
@@ -141,7 +141,7 @@
 
 		pieces = g_strsplit (str, "/", 2);
 
-		if (inet_pton (AF_INET, pieces[0], &ip4_addr)) {
+		if (inet_pton (AF_INET, pieces[0], &ip4_addr) > 0) {
 			tmp.address = ip4_addr.s_addr;
 
 			if (g_strv_length (pieces) == 2)
@@ -166,7 +166,7 @@
 		if (str) {
 			struct in_addr mask_addr;
 
-			if (inet_pton (AF_INET, str, &mask_addr))
+			if (inet_pton (AF_INET, str, &mask_addr) > 0)
 				tmp.netmask = mask_addr.s_addr;
 			else {
 				g_warning ("Ignoring invalid IP4 addres: invalid netmask: '%s'", str);

Modified: trunk/system-settings/plugins/keyfile/writer.c
==============================================================================
--- trunk/system-settings/plugins/keyfile/writer.c	(original)
+++ trunk/system-settings/plugins/keyfile/writer.c	Thu Jun 26 19:33:13 2008
@@ -7,6 +7,7 @@
 #include <nm-setting.h>
 #include <nm-setting-connection.h>
 #include <nm-setting-ip4-config.h>
+#include <nm-utils.h>
 #include <string.h>
 #include <arpa/inet.h>
 
@@ -36,7 +37,13 @@
 			struct in_addr addr;
 
 			addr.s_addr = g_array_index (array, guint32, i);
-			list[i] = g_strdup (inet_ntop (AF_INET, &addr, buf, sizeof (buf)));
+			if (!inet_ntop (AF_INET, &addr, buf, sizeof (buf))) {
+				nm_warning ("%s: error converting IP4 address 0x%X",
+				            __func__, ntohl (addr.s_addr));
+				list[i] = NULL;
+			} else {
+				list[i] = g_strdup (buf);
+			}
 		}
 
 		g_key_file_set_string_list (file, setting->name, key, (const char **) list, array->len);
@@ -81,14 +88,33 @@
 		char *key_name;
 
 		addr.s_addr = g_array_index (tuple, guint32, 0);
-		list[0] = g_strdup (inet_ntop (AF_INET, &addr, buf, sizeof (buf)));
+		if (!inet_ntop (AF_INET, &addr, buf, sizeof (buf))) {
+			nm_warning ("%s: error converting IP4 address 0x%X",
+			            __func__, ntohl (addr.s_addr));
+			list[0] = NULL;
+		} else {
+			list[0] = g_strdup (buf);
+		}
 
 		addr.s_addr = g_array_index (tuple, guint32, 1);
-		list[1] = g_strdup (inet_ntop (AF_INET, &addr, buf, sizeof (buf)));
+		if (!inet_ntop (AF_INET, &addr, buf, sizeof (buf))) {
+			nm_warning ("%s: error converting IP4 address 0x%X",
+			            __func__, ntohl (addr.s_addr));
+			list[1] = NULL;
+		} else {
+			list[1] = g_strdup (buf);
+		}
 
 		addr.s_addr = g_array_index (tuple, guint32, 2);
-		if (addr.s_addr)
-			list[2] = g_strdup (inet_ntop (AF_INET, &addr, buf, sizeof (buf)));
+		if (addr.s_addr) {
+			if (!inet_ntop (AF_INET, &addr, buf, sizeof (buf))) {
+				nm_warning ("%s: error converting IP4 address 0x%X",
+					        __func__, ntohl (addr.s_addr));
+				list[2] = NULL;
+			} else {
+				list[2] = g_strdup (buf);
+			}
+		}
 
 		key_name = g_strdup_printf ("address%d", j + 1);
 		g_key_file_set_string_list (file, setting->name, key_name, (const char **) list, list[2] ? 3 : 2);

Modified: trunk/test/nm-dhcp-opt-test.c
==============================================================================
--- trunk/test/nm-dhcp-opt-test.c	(original)
+++ trunk/test/nm-dhcp-opt-test.c	Thu Jun 26 19:33:13 2008
@@ -155,6 +155,9 @@
 	const char	*name = NULL;
 	int			 opt_type = -1;
 	unsigned int foo;
+	char buf[INET_ADDRSTRLEN+1];
+
+	memset (&buf, '\0', sizeof (buf));
 
 	ret = call_nm_method (connection, "getName", opt, FALSE, DBUS_TYPE_STRING, (void *)(&name), NULL);
 	if (ret != RETURN_SUCCESS)
@@ -212,7 +215,11 @@
 					break;
 				case DBUS_TYPE_UINT32:
 					in.s_addr = uint32[i];
-					fprintf (stderr, "%u (%s)%s", uint32[i], inet_ntoa(in), last ? "" : ", ");
+					if (!inet_ntop (AF_INET, &in, buf, INET_ADDRSTRLEN))
+						nm_warning ("%s: error converting IP4 address 0x%X",
+						            __func__, ntohl (in.s_addr));
+					else
+						fprintf (stderr, "%u (%s)%s", uint32[i], buf, last ? "" : ", ");
 					break;
 				case DBUS_TYPE_STRING:
 					fprintf (stderr, "'%s'%s", string[i], last ? "" : ", ");

Modified: trunk/test/nm-tool.c
==============================================================================
--- trunk/test/nm-tool.c	(original)
+++ trunk/test/nm-tool.c	Thu Jun 26 19:33:13 2008
@@ -162,12 +162,18 @@
 ip4_address_as_string (guint32 ip)
 {
 	struct in_addr tmp_addr;
-	gchar *ip_string;
+	char buf[INET_ADDRSTRLEN+1];
 
+	memset (&buf, '\0', sizeof (buf));
 	tmp_addr.s_addr = ip;
-	ip_string = inet_ntoa (tmp_addr);
 
-	return g_strdup (ip_string);
+	if (inet_ntop (AF_INET, &tmp_addr, buf, INET_ADDRSTRLEN)) {
+		return g_strdup (buf);
+	} else {
+		nm_warning ("%s: error converting IP4 address 0x%X",
+		            __func__, ntohl (tmp_addr.s_addr));
+		return NULL;
+	}
 }
 
 static const char *

Modified: trunk/vpn-daemons/openvpn/src/nm-openvpn-service-openvpn-helper.c
==============================================================================
--- trunk/vpn-daemons/openvpn/src/nm-openvpn-service-openvpn-helper.c	(original)
+++ trunk/vpn-daemons/openvpn/src/nm-openvpn-service-openvpn-helper.c	Thu Jun 26 19:33:13 2008
@@ -135,7 +135,7 @@
 	if (!str || strlen (str) < 1)
 		return NULL;
 
-	if (!inet_aton (str, &temp_addr))
+	if (inet_pton (AF_INET, str, &temp_addr) <= 0)
 		return NULL;
 
 	val = g_slice_new0 (GValue);
@@ -164,7 +164,7 @@
 
 	split = g_strsplit (str, " ", -1);
 	for (i = 0; split[i]; i++) {
-		if (inet_aton (split[i], &temp_addr))
+		if (inet_pton (AF_INET, split[i], &temp_addr) > 0)
 			g_array_append_val (array, temp_addr.s_addr);
 	}
 
@@ -203,21 +203,21 @@
 		if (!tmp || strlen (tmp) < 1)
 			break;
 
-		if (inet_aton (tmp, &network) != 0) {
+		if (inet_pton (AF_INET, tmp, &network) <= 0) {
 			nm_warning ("Ignoring invalid static route address '%s'", tmp ? tmp : "NULL");
 			continue;
 		}
 
 		snprintf (buf, BUFLEN, "route_netmask_%d", i);
 		tmp = getenv (buf);
-		if (!tmp || inet_aton (tmp, &netmask) != 0) {
+		if (!tmp || inet_pton (AF_INET, tmp, &netmask) <= 0) {
 			nm_warning ("Ignoring invalid static route netmask '%s'", tmp ? tmp : "NULL");
 			continue;
 		}
 
 		snprintf (buf, BUFLEN, "route_gateway_%d", i);
 		tmp = getenv (buf);
-		if (!tmp || inet_aton (tmp, &gateway) != 0) {
+		if (!tmp || inet_pton (AF_INET, tmp, &gateway) <= 0) {
 			nm_warning ("Ignoring invalid static route gateway '%s'", tmp ? tmp : "NULL");
 			continue;
 		}

Modified: trunk/vpn-daemons/openvpn/src/nm-openvpn-service.c
==============================================================================
--- trunk/vpn-daemons/openvpn/src/nm-openvpn-service.c	(original)
+++ trunk/vpn-daemons/openvpn/src/nm-openvpn-service.c	Thu Jun 26 19:33:13 2008
@@ -244,7 +244,8 @@
 		return FALSE;
 
 	serv_addr.sin_family = AF_INET;
-	inet_aton ("127.0.0.1", &(serv_addr.sin_addr));
+	if (inet_pton (AF_INET, "127.0.0.1", &(serv_addr.sin_addr)) <= 0)
+		nm_warning ("%s: could not convert 127.0.0.1", __func__);
 	serv_addr.sin_port = htons (1194);
  
 	connected = (connect (socket_fd, (struct sockaddr *) &serv_addr, sizeof (serv_addr)) == 0);

Modified: trunk/vpn-daemons/pptp/src/nm-ppp-starter.c
==============================================================================
--- trunk/vpn-daemons/pptp/src/nm-ppp-starter.c	(original)
+++ trunk/vpn-daemons/pptp/src/nm-ppp-starter.c	Thu Jun 26 19:33:13 2008
@@ -442,7 +442,9 @@
   int                   i = 0;
   struct hostent    *hostinfo = NULL;
   char *        pppd_pty = NULL;
+  char buf[INET_ADDRSTRLEN+1];
   
+  memset (&buf, '\0', sizeof (buf));
 
   /* Find pptp */
   pptp_binary = pptp_binary_paths;
@@ -466,7 +468,10 @@
         return -1;
       }
       data -> ip4_vpn_gateway = *(struct in_addr*)(hostinfo->h_addr_list[0]);
-      data -> str_ip4_vpn_gateway = g_strdup( inet_ntoa( data -> ip4_vpn_gateway ) );
+
+      if ( !inet_ntop (AF_INET, &data -> ip4_vpn_gateway, buf, INET_ADDRSTRLEN))
+        data -> str_ip4_vpn_gateway = NULL;
+      data -> str_ip4_vpn_gateway = g_strdup( buf );
 
       pppd_pty = g_strdup_printf ("%s %s --nolaunchpppd", (*pptp_binary), data->str_ip4_vpn_gateway);
 
@@ -510,7 +515,10 @@
 //        return -1;
 //      }
 //      data -> ip4_vpn_gateway = *(struct in_addr*)(hostinfo->h_addr_list[0]);
-//      data -> str_ip4_vpn_gateway = g_strdup( inet_ntoa( data -> ip4_vpn_gateway ) );
+//
+//      if ( !inet_ntop (AF_INET, &data -> ip4_vpn_gateway, buf, INET_ADDRSTRLEN))
+//        data -> str_ip4_gateway = NULL;
+//      data -> str_ip4_vpn_gateway = g_strdup( buf );
 //
 //      pppd_pty = g_strdup_printf ("%s %s --nolaunchpppd", (*pptp_binary), data->str_ip4_vpn_gateway);
 //

Modified: trunk/vpn-daemons/vpnc/src/nm-vpnc-service-vpnc-helper.c
==============================================================================
--- trunk/vpn-daemons/vpnc/src/nm-vpnc-service-vpnc-helper.c	(original)
+++ trunk/vpn-daemons/vpnc/src/nm-vpnc-service-vpnc-helper.c	Thu Jun 26 19:33:13 2008
@@ -141,7 +141,7 @@
 	if (!str || strlen (str) < 1)
 		return NULL;
 
-	if (!inet_aton (str, &temp_addr))
+	if (inet_pton (AF_INET, str, &temp_addr) <= 0)
 		return NULL;
 
 	return uint_to_gvalue (temp_addr.s_addr);
@@ -167,7 +167,7 @@
 	for (i = 0; split[i]; i++) {
 		struct in_addr addr;
 
-		if (inet_aton (split[i], &addr)) {
+		if (inet_pton (AF_INET, split[i], &addr) > 0) {
 			g_array_append_val (array, addr.s_addr);
 		} else {
 			g_strfreev (split);
@@ -215,14 +215,14 @@
 
 		snprintf (buf, BUFLEN, "CISCO_SPLIT_INC_%d_ADDR", i);
 		tmp = getenv (buf);
-		if (!tmp || inet_aton (tmp, &network) != 0) {
+		if (!tmp || inet_pton (AF_INET, tmp, &network) <= 0) {
 			nm_warning ("Ignoring invalid static route address '%s'", tmp ? tmp : "NULL");
 			continue;
 		}
 
 		snprintf (buf, BUFLEN, "CISCO_SPLIT_INC_%d_MASK", i);
 		tmp = getenv (buf);
-		if (!tmp || inet_aton (tmp, &netmask) != 0) {
+		if (!tmp || inet_pton (AF_INET, tmp, &netmask) <= 0) {
 			nm_warning ("Ignoring invalid static route netmask '%s'", tmp ? tmp : "NULL");
 			continue;
 		}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]