libpurple/protocols/oscar/peer.c

changeset 33894
7e3ea8475aad
parent 33811
5ab172aeeff2
child 34331
c8486462bb63
child 34529
68cf25486001
--- a/libpurple/protocols/oscar/peer.c	Mon Apr 15 00:48:17 2013 +0200
+++ b/libpurple/protocols/oscar/peer.c	Wed Apr 17 18:56:03 2013 +0200
@@ -642,6 +642,40 @@
 }
 
 /**
+ * Converts a dot-decimal IP address to an array of unsigned
+ * chars.  For example, converts 192.168.0.1 to a 4 byte
+ * array containing 192, 168, 0 and 1.
+ *
+ * @param ip An IP address in dot-decimal notiation.
+ * @return An array of 4 bytes containing an IP addresses
+ *         equivalent to the given parameter, or NULL if
+ *         the given IP address is invalid.  This value
+ *         is statically allocated and should not be
+ *         freed.
+ */
+static const unsigned char *
+peer_ip_atoi(const char *ip)
+{
+	static unsigned char ret[4];
+	gchar *delimiter = ".";
+	gchar **split;
+	int i;
+
+	g_return_val_if_fail(ip != NULL, NULL);
+
+	split = g_strsplit(ip, delimiter, 4);
+	for (i = 0; split[i] != NULL; i++)
+		ret[i] = atoi(split[i]);
+	g_strfreev(split);
+
+	/* i should always be 4 */
+	if (i != 4)
+		return NULL;
+
+	return ret;
+}
+
+/**
  * We've just opened a listener socket, so we send the remote
  * user an ICBM and ask them to connect to us.
  */
@@ -692,13 +726,13 @@
 	else
 		listener_ip = purple_network_get_my_ip(bos_conn->fd);
 
-	ip_atoi = purple_network_ip_atoi(listener_ip);
+	ip_atoi = peer_ip_atoi(listener_ip);
 	if (ip_atoi == NULL) {
 		/* Could not convert IP to 4 byte array--weird, but this does
 		   happen for some users (#4829, Adium #15839).  Maybe they're
 		   connecting with IPv6...?  Maybe through a proxy? */
 		purple_debug_error("oscar", "Can't ask peer to connect to us "
-				"because purple_network_ip_atoi(%s) returned NULL. "
+				"because peer_ip_atoi(%s) returned NULL. "
 				"fd=%d. is_ssl=%d\n",
 				listener_ip ? listener_ip : "(null)",
 				bos_conn->gsc ? bos_conn->gsc->fd : bos_conn->fd,

mercurial