Mercurial > pidgin.yaz
diff libpurple/network.c @ 29502:0aac63e8489f
propagate from branch 'im.pidgin.pidgin' (head 84b4f3d9c0a8e1306eb70e9db0003177e2782269)
to branch 'im.pidgin.pidgin.next.minor' (head ff2751f3bf0343a572e3ab437dd01ff6efbaf336)
author | John Bailey <rekkanoryo@rekkanoryo.org> |
---|---|
date | Wed, 16 Sep 2009 16:25:59 +0000 |
parents | df24cbb0d6e2 |
children | ecd1aa92fd57 |
line wrap: on
line diff
--- a/libpurple/network.c Wed Sep 16 16:11:01 2009 +0000 +++ b/libpurple/network.c Wed Sep 16 16:25:59 2009 +0000 @@ -200,6 +200,45 @@ return "0.0.0.0"; } +GList * +purple_network_get_all_local_system_ips(void) +{ + GList *result = NULL; + int source = source = socket(PF_INET,SOCK_STREAM, 0); + char buffer[1024]; + char *tmp; + struct ifconf ifc; + struct ifreq *ifr; + + ifc.ifc_len = sizeof(buffer); + ifc.ifc_req = (struct ifreq *)buffer; + ioctl(source, SIOCGIFCONF, &ifc); + close(source); + + tmp = buffer; + while (tmp < buffer + ifc.ifc_len) { + char dst[INET_ADDRSTRLEN]; + + ifr = (struct ifreq *)tmp; + tmp += HX_SIZE_OF_IFREQ(*ifr); + + /* TODO: handle IPv6 */ + if (ifr->ifr_addr.sa_family == AF_INET) { + struct sockaddr_in *sinptr = (struct sockaddr_in *)&ifr->ifr_addr; + + inet_ntop(AF_INET, &sinptr->sin_addr, dst, + sizeof(dst)); + purple_debug_info("network", + "found local i/f with address %s on IPv4\n", dst); + if (!purple_strequal(dst, "127.0.0.1")) { + result = g_list_append(result, g_strdup(dst)); + } + } + } + + return result; +} + const char * purple_network_get_my_ip(int fd) {