pidgin/pidgin

Parents 924a47d2652d
Children 35b14cab108f
Replace bonjour_xmpp_get_local_ips by purple_network_get_all_local_system_ips.

The only difference is that the former allows specifying an existing
socket to use for the SIOCGIFCONF ioctl.
--- a/libpurple/protocols/bonjour/bonjour_ft.c Mon May 11 02:40:30 2020 +0000
+++ b/libpurple/protocols/bonjour/bonjour_ft.c Tue May 12 04:06:23 2020 -0400
@@ -887,7 +887,7 @@
XepIq *iq;
PurpleXmlNode *query, *streamhost;
gchar *port;
- GSList *local_ips;
+ GList *local_ips;
BonjourData *bd;
purple_debug_info("bonjour", "Bonjour-bytestreams-listen. sock=%d.\n", sock);
@@ -912,7 +912,7 @@
purple_xfer_set_local_port(xfer, purple_network_get_port_from_fd(sock));
- local_ips = bonjour_xmpp_get_local_ips(sock);
+ local_ips = purple_network_get_all_local_system_ips();
port = g_strdup_printf("%hu", purple_xfer_get_local_port(xfer));
while(local_ips) {
@@ -921,7 +921,7 @@
purple_xmlnode_set_attrib(streamhost, "host", local_ips->data);
purple_xmlnode_set_attrib(streamhost, "port", port);
g_free(local_ips->data);
- local_ips = g_slist_delete_link(local_ips, local_ips);
+ local_ips = g_list_delete_link(local_ips, local_ips);
}
g_free(port);
--- a/libpurple/protocols/bonjour/xmpp.c Mon May 11 02:40:30 2020 +0000
+++ b/libpurple/protocols/bonjour/xmpp.c Tue May 12 04:06:23 2020 -0400
@@ -1368,98 +1368,6 @@
return (ret >= 0) ? 0 : -1;
}
-/* This returns a list containing all non-localhost IPs */
-GSList *
-bonjour_xmpp_get_local_ips(int fd)
-{
- GSList *ips = NULL;
- const char *address_text;
- int ret;
-
-#ifdef HAVE_GETIFADDRS /* This is required for IPv6 */
- struct ifaddrs *ifap, *ifa;
- common_sockaddr_t addr;
- char addrstr[INET6_ADDRSTRLEN];
-
- ret = getifaddrs(&ifap);
- if (ret != 0) {
- const char *error = g_strerror(errno);
- purple_debug_error("bonjour", "getifaddrs() error: %s\n", error ? error : "(null)");
- return NULL;
- }
-
- for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) {
- if (!(ifa->ifa_flags & IFF_RUNNING) || (ifa->ifa_flags & IFF_LOOPBACK) || ifa->ifa_addr == NULL)
- continue;
-
- memcpy(&addr, ifa->ifa_addr, sizeof(addr));
- address_text = NULL;
- switch (addr.sa.sa_family) {
- case AF_INET:
- address_text = inet_ntop(addr.sa.sa_family,
- &addr.in.sin_addr,
- addrstr, sizeof(addrstr));
- break;
-#ifdef PF_INET6
- case AF_INET6:
- address_text = inet_ntop(addr.sa.sa_family,
- &addr.in6.sin6_addr,
- addrstr, sizeof(addrstr));
- break;
-#endif
- }
-
- if (address_text != NULL) {
- if (addr.sa.sa_family == AF_INET)
- ips = g_slist_append(ips, g_strdup(address_text));
- else
- ips = g_slist_prepend(ips, g_strdup(address_text));
- }
- }
-
- freeifaddrs(ifap);
-#else
- char *tmp;
- struct ifconf ifc;
- struct ifreq *ifr;
- char buffer[1024];
- struct sockaddr_in *sinptr;
- int source = fd;
-
- if (fd < 0)
- source = socket(PF_INET, SOCK_STREAM, 0);
-
- ifc.ifc_len = sizeof(buffer);
- ifc.ifc_req = (struct ifreq *)buffer;
- ret = ioctl(source, SIOCGIFCONF, &ifc);
-
- if (fd < 0)
- close(source);
-
- if (ret < 0) {
- const char *error = g_strerror(errno);
- purple_debug_error("bonjour", "ioctl(SIOCGIFCONF) error: %s\n", error ? error : "(null)");
- return NULL;
- }
-
- tmp = buffer;
- while (tmp < buffer + ifc.ifc_len) {
- ifr = (struct ifreq *)tmp;
- tmp += HX_SIZE_OF_IFREQ(*ifr);
-
- if (ifr->ifr_addr.sa_family == AF_INET) {
- sinptr = (struct sockaddr_in *)&ifr->ifr_addr;
- if ((ntohl(sinptr->sin_addr.s_addr) >> 24) != 127) {
- address_text = inet_ntoa(sinptr->sin_addr);
- ips = g_slist_prepend(ips, g_strdup(address_text));
- }
- }
- }
-#endif
-
- return ips;
-}
-
void
append_iface_if_linklocal(char *ip, guint32 interface_param) {
struct in6_addr in6_addr;
--- a/libpurple/protocols/bonjour/xmpp.h Mon May 11 02:40:30 2020 +0000
+++ b/libpurple/protocols/bonjour/xmpp.h Tue May 12 04:06:23 2020 -0400
@@ -105,7 +105,6 @@
XepIq *xep_iq_new(void *data, XepIqType type, const char *to, const char *from, const char *id);
int xep_iq_send_and_free(XepIq *iq);
-GSList * bonjour_xmpp_get_local_ips(int fd);
void append_iface_if_linklocal(char *ip, guint32 interface_param);