pidgin: a821cc09: util: Make purple_fd_get_ip IPv6-aware
darkrain42 at pidgin.im
darkrain42 at pidgin.im
Sun Apr 18 17:50:13 EDT 2010
-----------------------------------------------------------------
Revision: a821cc098fc75ffd4bbb35f2403632fa7b29e214
Ancestor: 16e3534d66c6f48b22fda1a9decd929533d7b68e
Author: darkrain42 at pidgin.im
Date: 2010-04-16T03:29:10
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/a821cc098fc75ffd4bbb35f2403632fa7b29e214
Modified files:
libpurple/util.c
ChangeLog:
util: Make purple_fd_get_ip IPv6-aware
-------------- next part --------------
============================================================
--- libpurple/util.c 6b3c2336667fcf9469f246fd24c1b90afc589d2c
+++ libpurple/util.c 93bcbf36374b2a3cac2fe7e0d745939b8a7f2b89
@@ -2971,17 +2971,37 @@ purple_fd_get_ip(int fd)
char *
purple_fd_get_ip(int fd)
{
- struct sockaddr addr;
+ struct sockaddr_storage addr;
socklen_t namelen = sizeof(addr);
- struct in_addr in;
+ int family;
g_return_val_if_fail(fd != 0, NULL);
- if (getsockname(fd, &addr, &namelen))
+ if (getsockname(fd, (struct sockaddr *)&addr, &namelen))
return NULL;
- in = ((struct sockaddr_in *)&addr)->sin_addr;
- return g_strdup(inet_ntoa(in));
+ family = ((struct sockaddr *)&addr)->sa_family;
+
+ if (family == AF_INET) {
+ struct sockaddr_in *ipv4 = (struct sockaddr_in *)&addr;
+ struct in_addr addr = ipv4->sin_addr;
+ return g_strdup(inet_ntoa(addr));
+ } else if (family == AF_INET6) {
+#ifdef HAVE_INET_NTOP
+ struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)&addr;
+ struct in6_addr addr = ipv6->sin6_addr;
+ char host[INET6_ADDRSTRLEN];
+ const char *tmp;
+
+ tmp = inet_ntop(family, &addr, host, sizeof(host));
+ return g_strdup(tmp);
+#else /* HAVE_INET_NTOP */
+ /* TODO: Patches welcome...I guess? */
+ return NULL;
+#endif
+ }
+
+ return NULL;
}
More information about the Commits
mailing list