Mercurial > pidgin.yaz
comparison libpurple/protocols/jabber/si.c @ 29495:02f6f49da454
Add a function to enumerate all local IPs
Adapted the XMPP prpl to include all local IPs as local streamhosts.
I haven't had the chance to test if this actually works using a "non-default"
interface, such as a VPN connection...
Refs #10160
author | Marcus Lundblad <ml@update.uu.se> |
---|---|
date | Wed, 09 Sep 2009 19:01:03 +0000 |
parents | c585572e80dd |
children | f1aa01ff26dd |
comparison
equal
deleted
inserted
replaced
29494:d6dff41a6d4c | 29495:02f6f49da454 |
---|---|
851 xmlnode_set_attrib(query, "sid", jsx->stream_id); | 851 xmlnode_set_attrib(query, "sid", jsx->stream_id); |
852 | 852 |
853 /* If we successfully started listening locally */ | 853 /* If we successfully started listening locally */ |
854 if (sock >= 0) { | 854 if (sock >= 0) { |
855 gchar *jid; | 855 gchar *jid; |
856 const char *local_ip, *public_ip; | 856 GList *local_ips = |
857 | 857 purple_network_get_all_local_system_ips(jsx->js->fd); |
858 const char *public_ip; | |
859 gboolean has_public_ip = FALSE; | |
860 | |
858 jsx->local_streamhost_fd = sock; | 861 jsx->local_streamhost_fd = sock; |
859 | 862 |
860 jid = g_strdup_printf("%s@%s/%s", jsx->js->user->node, | 863 jid = g_strdup_printf("%s@%s/%s", jsx->js->user->node, |
861 jsx->js->user->domain, jsx->js->user->resource); | 864 jsx->js->user->domain, jsx->js->user->resource); |
862 xfer->local_port = purple_network_get_port_from_fd(sock); | 865 xfer->local_port = purple_network_get_port_from_fd(sock); |
863 g_snprintf(port, sizeof(port), "%hu", xfer->local_port); | 866 g_snprintf(port, sizeof(port), "%hu", xfer->local_port); |
864 | 867 |
865 /* Include the localhost's IP (for in-network transfers) */ | 868 public_ip = purple_network_get_my_ip(jsx->js->fd); |
866 local_ip = purple_network_get_local_system_ip(jsx->js->fd); | 869 |
867 if (strcmp(local_ip, "0.0.0.0") != 0) { | 870 /* Include the localhost's IPs (for in-network transfers) */ |
871 while (local_ips) { | |
872 gchar *local_ip = local_ips->data; | |
868 streamhost_count++; | 873 streamhost_count++; |
869 streamhost = xmlnode_new_child(query, "streamhost"); | 874 streamhost = xmlnode_new_child(query, "streamhost"); |
870 xmlnode_set_attrib(streamhost, "jid", jid); | 875 xmlnode_set_attrib(streamhost, "jid", jid); |
871 xmlnode_set_attrib(streamhost, "host", local_ip); | 876 xmlnode_set_attrib(streamhost, "host", local_ip); |
872 xmlnode_set_attrib(streamhost, "port", port); | 877 xmlnode_set_attrib(streamhost, "port", port); |
878 if (purple_strequal(local_ip, public_ip)) | |
879 has_public_ip = TRUE; | |
880 g_free(local_ip); | |
881 local_ips = g_list_delete_link(local_ips, local_ips); | |
873 } | 882 } |
874 | 883 |
875 /* Include the public IP (assuming that there is a port mapped somehow) */ | 884 /* Include the public IP (assuming that there is a port mapped somehow) */ |
876 public_ip = purple_network_get_my_ip(jsx->js->fd); | 885 if (!has_public_ip && strcmp(public_ip, "0.0.0.0") != 0) { |
877 if (strcmp(public_ip, local_ip) != 0 && strcmp(public_ip, "0.0.0.0") != 0) { | |
878 streamhost_count++; | 886 streamhost_count++; |
879 streamhost = xmlnode_new_child(query, "streamhost"); | 887 streamhost = xmlnode_new_child(query, "streamhost"); |
880 xmlnode_set_attrib(streamhost, "jid", jid); | 888 xmlnode_set_attrib(streamhost, "jid", jid); |
881 xmlnode_set_attrib(streamhost, "host", public_ip); | 889 xmlnode_set_attrib(streamhost, "host", public_ip); |
882 xmlnode_set_attrib(streamhost, "port", port); | 890 xmlnode_set_attrib(streamhost, "port", port); |