Sat, 22 Mar 2008 09:40:38 +0000
Add log-handlers for farsight foo.
| 8231 | 1 | /** |
| 2 | * @file network.c Network Implementation | |
| 3 | * @ingroup core | |
|
20147
66f05a854eee
applied changes from 8a731bbd0197fbcc91a705c2d8f528154216defa
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
4 | */ |
|
66f05a854eee
applied changes from 8a731bbd0197fbcc91a705c2d8f528154216defa
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
5 | |
|
66f05a854eee
applied changes from 8a731bbd0197fbcc91a705c2d8f528154216defa
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
6 | /* purple |
| 8231 | 7 | * |
| 15884 | 8 | * Purple is the legal property of its developers, whose names are too numerous |
| 8231 | 9 | * to list here. Please refer to the COPYRIGHT file distributed with this |
| 10 | * source distribution. | |
| 11 | * | |
| 12 | * This program is free software; you can redistribute it and/or modify | |
| 13 | * it under the terms of the GNU General Public License as published by | |
| 14 | * the Free Software Foundation; either version 2 of the License, or | |
| 15 | * (at your option) any later version. | |
| 16 | * | |
| 17 | * This program is distributed in the hope that it will be useful, | |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 20 | * GNU General Public License for more details. | |
| 21 | * | |
| 22 | * You should have received a copy of the GNU General Public License | |
| 23 | * along with this program; if not, write to the Free Software | |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19832
diff
changeset
|
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 8231 | 25 | */ |
| 26 | ||
|
8245
c1397ca0a619
[gaim-migrate @ 8968]
Herman Bloggs <herman@bluedigits.com>
parents:
8240
diff
changeset
|
27 | #include "internal.h" |
| 8231 | 28 | |
|
13156
539a637c61dc
[gaim-migrate @ 15518]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
13131
diff
changeset
|
29 | #ifndef _WIN32 |
| 14864 | 30 | #include <resolv.h> |
| 31 | #include <netinet/in.h> | |
| 32 | #include <arpa/nameser.h> | |
|
13156
539a637c61dc
[gaim-migrate @ 15518]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
13131
diff
changeset
|
33 | #include <net/if.h> |
|
539a637c61dc
[gaim-migrate @ 15518]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
13131
diff
changeset
|
34 | #include <sys/ioctl.h> |
|
14784
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
35 | #else |
|
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
36 | #include <nspapi.h> |
|
13156
539a637c61dc
[gaim-migrate @ 15518]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
13131
diff
changeset
|
37 | #endif |
|
539a637c61dc
[gaim-migrate @ 15518]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
13131
diff
changeset
|
38 | |
|
539a637c61dc
[gaim-migrate @ 15518]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
13131
diff
changeset
|
39 | /* Solaris */ |
|
539a637c61dc
[gaim-migrate @ 15518]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
13131
diff
changeset
|
40 | #if defined (__SVR4) && defined (__sun) |
|
539a637c61dc
[gaim-migrate @ 15518]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
13131
diff
changeset
|
41 | #include <sys/sockio.h> |
|
539a637c61dc
[gaim-migrate @ 15518]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
13131
diff
changeset
|
42 | #endif |
|
539a637c61dc
[gaim-migrate @ 15518]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
13131
diff
changeset
|
43 | |
| 8231 | 44 | #include "debug.h" |
| 45 | #include "account.h" | |
|
16035
eb4eda79a147
The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents:
16012
diff
changeset
|
46 | #include "nat-pmp.h" |
| 8231 | 47 | #include "network.h" |
| 48 | #include "prefs.h" | |
|
11411
b74834586187
[gaim-migrate @ 13648]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11391
diff
changeset
|
49 | #include "stun.h" |
|
11195
d84d542a04ac
[gaim-migrate @ 13319]
Adam Warrington <awarring@users.sourceforge.net>
parents:
11033
diff
changeset
|
50 | #include "upnp.h" |
| 8231 | 51 | |
|
15278
7f469b5c8d7a
[gaim-migrate @ 18006]
Mark Doliner <markdoliner@pidgin.im>
parents:
15116
diff
changeset
|
52 | /* |
|
7f469b5c8d7a
[gaim-migrate @ 18006]
Mark Doliner <markdoliner@pidgin.im>
parents:
15116
diff
changeset
|
53 | * Calling sizeof(struct ifreq) isn't always correct on |
|
7f469b5c8d7a
[gaim-migrate @ 18006]
Mark Doliner <markdoliner@pidgin.im>
parents:
15116
diff
changeset
|
54 | * Mac OS X (and maybe others). |
|
7f469b5c8d7a
[gaim-migrate @ 18006]
Mark Doliner <markdoliner@pidgin.im>
parents:
15116
diff
changeset
|
55 | */ |
|
7f469b5c8d7a
[gaim-migrate @ 18006]
Mark Doliner <markdoliner@pidgin.im>
parents:
15116
diff
changeset
|
56 | #ifdef _SIZEOF_ADDR_IFREQ |
|
7f469b5c8d7a
[gaim-migrate @ 18006]
Mark Doliner <markdoliner@pidgin.im>
parents:
15116
diff
changeset
|
57 | # define HX_SIZE_OF_IFREQ(a) _SIZEOF_ADDR_IFREQ(a) |
|
7f469b5c8d7a
[gaim-migrate @ 18006]
Mark Doliner <markdoliner@pidgin.im>
parents:
15116
diff
changeset
|
58 | #else |
|
7f469b5c8d7a
[gaim-migrate @ 18006]
Mark Doliner <markdoliner@pidgin.im>
parents:
15116
diff
changeset
|
59 | # define HX_SIZE_OF_IFREQ(a) sizeof(a) |
|
7f469b5c8d7a
[gaim-migrate @ 18006]
Mark Doliner <markdoliner@pidgin.im>
parents:
15116
diff
changeset
|
60 | #endif |
|
7f469b5c8d7a
[gaim-migrate @ 18006]
Mark Doliner <markdoliner@pidgin.im>
parents:
15116
diff
changeset
|
61 | |
| 14758 | 62 | #ifdef HAVE_LIBNM |
| 63 | #include <libnm_glib.h> | |
| 64 | ||
| 65 | libnm_glib_ctx *nm_context = NULL; | |
| 66 | guint nm_callback_idx = 0; | |
| 67 | ||
|
14784
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
68 | #elif defined _WIN32 |
|
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
69 | static int current_network_count; |
| 14758 | 70 | #endif |
| 71 | ||
| 15884 | 72 | struct _PurpleNetworkListenData { |
|
12909
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
73 | int listenfd; |
|
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
74 | int socket_type; |
|
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
75 | gboolean retry; |
|
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
76 | gboolean adding; |
| 15884 | 77 | PurpleNetworkListenCallback cb; |
|
12909
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
78 | gpointer cb_data; |
|
15502
250802f80d94
Fix a crash when a network_listen_range process is canceled before its UPnP port mapping completes, which occurs regularly on certain routers when file transfers are initiated and then quickly finished. Much thanks to Elliott Harris and Eric Richie for their hard work with me hunting this down and fixing it.
Evan Schoenberg <evands@pidgin.im>
parents:
15435
diff
changeset
|
79 | UPnPMappingAddRemove *mapping_data; |
|
14329
05c3cc0c1f79
[gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
80 | }; |
|
11391
d172e72988cc
[gaim-migrate @ 13620]
Adam Warrington <awarring@users.sourceforge.net>
parents:
11336
diff
changeset
|
81 | |
| 14758 | 82 | #ifdef HAVE_LIBNM |
| 83 | void nm_callback_func(libnm_glib_ctx* ctx, gpointer user_data); | |
| 84 | #endif | |
| 85 | ||
|
8838
c23227da7b4a
[gaim-migrate @ 9604]
Mark Doliner <markdoliner@pidgin.im>
parents:
8834
diff
changeset
|
86 | const unsigned char * |
| 15884 | 87 | purple_network_ip_atoi(const char *ip) |
|
8838
c23227da7b4a
[gaim-migrate @ 9604]
Mark Doliner <markdoliner@pidgin.im>
parents:
8834
diff
changeset
|
88 | { |
|
c23227da7b4a
[gaim-migrate @ 9604]
Mark Doliner <markdoliner@pidgin.im>
parents:
8834
diff
changeset
|
89 | static unsigned char ret[4]; |
| 8981 | 90 | gchar *delimiter = "."; |
|
8838
c23227da7b4a
[gaim-migrate @ 9604]
Mark Doliner <markdoliner@pidgin.im>
parents:
8834
diff
changeset
|
91 | gchar **split; |
|
c23227da7b4a
[gaim-migrate @ 9604]
Mark Doliner <markdoliner@pidgin.im>
parents:
8834
diff
changeset
|
92 | int i; |
|
c23227da7b4a
[gaim-migrate @ 9604]
Mark Doliner <markdoliner@pidgin.im>
parents:
8834
diff
changeset
|
93 | |
|
c23227da7b4a
[gaim-migrate @ 9604]
Mark Doliner <markdoliner@pidgin.im>
parents:
8834
diff
changeset
|
94 | g_return_val_if_fail(ip != NULL, NULL); |
|
c23227da7b4a
[gaim-migrate @ 9604]
Mark Doliner <markdoliner@pidgin.im>
parents:
8834
diff
changeset
|
95 | |
| 8981 | 96 | split = g_strsplit(ip, delimiter, 4); |
|
8838
c23227da7b4a
[gaim-migrate @ 9604]
Mark Doliner <markdoliner@pidgin.im>
parents:
8834
diff
changeset
|
97 | for (i = 0; split[i] != NULL; i++) |
|
c23227da7b4a
[gaim-migrate @ 9604]
Mark Doliner <markdoliner@pidgin.im>
parents:
8834
diff
changeset
|
98 | ret[i] = atoi(split[i]); |
|
c23227da7b4a
[gaim-migrate @ 9604]
Mark Doliner <markdoliner@pidgin.im>
parents:
8834
diff
changeset
|
99 | g_strfreev(split); |
|
c23227da7b4a
[gaim-migrate @ 9604]
Mark Doliner <markdoliner@pidgin.im>
parents:
8834
diff
changeset
|
100 | |
|
c23227da7b4a
[gaim-migrate @ 9604]
Mark Doliner <markdoliner@pidgin.im>
parents:
8834
diff
changeset
|
101 | /* i should always be 4 */ |
|
c23227da7b4a
[gaim-migrate @ 9604]
Mark Doliner <markdoliner@pidgin.im>
parents:
8834
diff
changeset
|
102 | if (i != 4) |
|
c23227da7b4a
[gaim-migrate @ 9604]
Mark Doliner <markdoliner@pidgin.im>
parents:
8834
diff
changeset
|
103 | return NULL; |
|
c23227da7b4a
[gaim-migrate @ 9604]
Mark Doliner <markdoliner@pidgin.im>
parents:
8834
diff
changeset
|
104 | |
|
c23227da7b4a
[gaim-migrate @ 9604]
Mark Doliner <markdoliner@pidgin.im>
parents:
8834
diff
changeset
|
105 | return ret; |
|
c23227da7b4a
[gaim-migrate @ 9604]
Mark Doliner <markdoliner@pidgin.im>
parents:
8834
diff
changeset
|
106 | } |
|
c23227da7b4a
[gaim-migrate @ 9604]
Mark Doliner <markdoliner@pidgin.im>
parents:
8834
diff
changeset
|
107 | |
| 8231 | 108 | void |
| 15884 | 109 | purple_network_set_public_ip(const char *ip) |
| 8231 | 110 | { |
| 111 | g_return_if_fail(ip != NULL); | |
| 112 | ||
|
8838
c23227da7b4a
[gaim-migrate @ 9604]
Mark Doliner <markdoliner@pidgin.im>
parents:
8834
diff
changeset
|
113 | /* XXX - Ensure the IP address is valid */ |
|
c23227da7b4a
[gaim-migrate @ 9604]
Mark Doliner <markdoliner@pidgin.im>
parents:
8834
diff
changeset
|
114 | |
|
16478
19107605c565
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@pidgin.im>
parents:
16035
diff
changeset
|
115 | purple_prefs_set_string("/purple/network/public_ip", ip); |
| 8231 | 116 | } |
| 117 | ||
| 118 | const char * | |
| 15884 | 119 | purple_network_get_public_ip(void) |
| 8231 | 120 | { |
|
16478
19107605c565
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@pidgin.im>
parents:
16035
diff
changeset
|
121 | return purple_prefs_get_string("/purple/network/public_ip"); |
| 8231 | 122 | } |
| 123 | ||
| 124 | const char * | |
| 15884 | 125 | purple_network_get_local_system_ip(int fd) |
| 8231 | 126 | { |
|
13346
a024b2b0a160
[gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents:
13168
diff
changeset
|
127 | char buffer[1024]; |
|
a024b2b0a160
[gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents:
13168
diff
changeset
|
128 | static char ip[16]; |
|
a024b2b0a160
[gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents:
13168
diff
changeset
|
129 | char *tmp; |
|
a024b2b0a160
[gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents:
13168
diff
changeset
|
130 | struct ifconf ifc; |
|
a024b2b0a160
[gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents:
13168
diff
changeset
|
131 | struct ifreq *ifr; |
|
a024b2b0a160
[gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents:
13168
diff
changeset
|
132 | struct sockaddr_in *sinptr; |
|
a024b2b0a160
[gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents:
13168
diff
changeset
|
133 | guint32 lhost = htonl(127 * 256 * 256 * 256 + 1); |
|
a024b2b0a160
[gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents:
13168
diff
changeset
|
134 | long unsigned int add; |
|
a024b2b0a160
[gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents:
13168
diff
changeset
|
135 | int source = fd; |
| 8231 | 136 | |
|
13346
a024b2b0a160
[gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents:
13168
diff
changeset
|
137 | if (fd < 0) |
|
a024b2b0a160
[gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents:
13168
diff
changeset
|
138 | source = socket(PF_INET,SOCK_STREAM, 0); |
| 8231 | 139 | |
|
13346
a024b2b0a160
[gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents:
13168
diff
changeset
|
140 | ifc.ifc_len = sizeof(buffer); |
|
a024b2b0a160
[gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents:
13168
diff
changeset
|
141 | ifc.ifc_req = (struct ifreq *)buffer; |
|
a024b2b0a160
[gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents:
13168
diff
changeset
|
142 | ioctl(source, SIOCGIFCONF, &ifc); |
| 8231 | 143 | |
|
13346
a024b2b0a160
[gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents:
13168
diff
changeset
|
144 | if (fd < 0) |
|
a024b2b0a160
[gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents:
13168
diff
changeset
|
145 | close(source); |
| 8231 | 146 | |
|
13346
a024b2b0a160
[gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents:
13168
diff
changeset
|
147 | tmp = buffer; |
|
a024b2b0a160
[gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents:
13168
diff
changeset
|
148 | while (tmp < buffer + ifc.ifc_len) |
|
a024b2b0a160
[gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents:
13168
diff
changeset
|
149 | { |
|
a024b2b0a160
[gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents:
13168
diff
changeset
|
150 | ifr = (struct ifreq *)tmp; |
|
15278
7f469b5c8d7a
[gaim-migrate @ 18006]
Mark Doliner <markdoliner@pidgin.im>
parents:
15116
diff
changeset
|
151 | tmp += HX_SIZE_OF_IFREQ(*ifr); |
| 8231 | 152 | |
|
13346
a024b2b0a160
[gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents:
13168
diff
changeset
|
153 | if (ifr->ifr_addr.sa_family == AF_INET) |
|
a024b2b0a160
[gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents:
13168
diff
changeset
|
154 | { |
|
a024b2b0a160
[gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents:
13168
diff
changeset
|
155 | sinptr = (struct sockaddr_in *)&ifr->ifr_addr; |
|
a024b2b0a160
[gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents:
13168
diff
changeset
|
156 | if (sinptr->sin_addr.s_addr != lhost) |
|
a024b2b0a160
[gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents:
13168
diff
changeset
|
157 | { |
|
a024b2b0a160
[gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents:
13168
diff
changeset
|
158 | add = ntohl(sinptr->sin_addr.s_addr); |
|
a024b2b0a160
[gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents:
13168
diff
changeset
|
159 | g_snprintf(ip, 16, "%lu.%lu.%lu.%lu", |
|
a024b2b0a160
[gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents:
13168
diff
changeset
|
160 | ((add >> 24) & 255), |
|
a024b2b0a160
[gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents:
13168
diff
changeset
|
161 | ((add >> 16) & 255), |
|
a024b2b0a160
[gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents:
13168
diff
changeset
|
162 | ((add >> 8) & 255), |
|
a024b2b0a160
[gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents:
13168
diff
changeset
|
163 | add & 255); |
| 8231 | 164 | |
|
13346
a024b2b0a160
[gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents:
13168
diff
changeset
|
165 | return ip; |
|
a024b2b0a160
[gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents:
13168
diff
changeset
|
166 | } |
|
a024b2b0a160
[gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents:
13168
diff
changeset
|
167 | } |
|
a024b2b0a160
[gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents:
13168
diff
changeset
|
168 | } |
|
a024b2b0a160
[gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents:
13168
diff
changeset
|
169 | |
|
a024b2b0a160
[gaim-migrate @ 15715]
Mark Doliner <markdoliner@pidgin.im>
parents:
13168
diff
changeset
|
170 | return "0.0.0.0"; |
| 8231 | 171 | } |
| 172 | ||
| 173 | const char * | |
| 15884 | 174 | purple_network_get_my_ip(int fd) |
| 8231 | 175 | { |
|
12686
ec3e7c4ff045
[gaim-migrate @ 15029]
Richard Laager <rlaager@pidgin.im>
parents:
11424
diff
changeset
|
176 | const char *ip = NULL; |
| 15884 | 177 | PurpleStunNatDiscovery *stun; |
|
8834
0a798e3d2b84
[gaim-migrate @ 9598]
Mark Doliner <markdoliner@pidgin.im>
parents:
8251
diff
changeset
|
178 | |
|
0a798e3d2b84
[gaim-migrate @ 9598]
Mark Doliner <markdoliner@pidgin.im>
parents:
8251
diff
changeset
|
179 | /* Check if the user specified an IP manually */ |
|
16478
19107605c565
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@pidgin.im>
parents:
16035
diff
changeset
|
180 | if (!purple_prefs_get_bool("/purple/network/auto_ip")) { |
| 15884 | 181 | ip = purple_network_get_public_ip(); |
|
15116
037b787407ba
[gaim-migrate @ 17838]
Mark Doliner <markdoliner@pidgin.im>
parents:
14959
diff
changeset
|
182 | /* Make sure the IP address entered by the user is valid */ |
| 15884 | 183 | if ((ip != NULL) && (purple_network_ip_atoi(ip) != NULL)) |
|
8834
0a798e3d2b84
[gaim-migrate @ 9598]
Mark Doliner <markdoliner@pidgin.im>
parents:
8251
diff
changeset
|
184 | return ip; |
|
21810
0b5181178201
Allow UPnP and NAT-PMP port mapping to be disabled via a pref. This means that UPnP discovery will not occur if this new pref and the "Autodetect IP Address" pref are both unchecked. Fixes #4157.
Daniel Atallah <datallah@pidgin.im>
parents:
21549
diff
changeset
|
185 | } else { |
|
0b5181178201
Allow UPnP and NAT-PMP port mapping to be disabled via a pref. This means that UPnP discovery will not occur if this new pref and the "Autodetect IP Address" pref are both unchecked. Fixes #4157.
Daniel Atallah <datallah@pidgin.im>
parents:
21549
diff
changeset
|
186 | /* Check if STUN discovery was already done */ |
|
0b5181178201
Allow UPnP and NAT-PMP port mapping to be disabled via a pref. This means that UPnP discovery will not occur if this new pref and the "Autodetect IP Address" pref are both unchecked. Fixes #4157.
Daniel Atallah <datallah@pidgin.im>
parents:
21549
diff
changeset
|
187 | stun = purple_stun_discover(NULL); |
|
0b5181178201
Allow UPnP and NAT-PMP port mapping to be disabled via a pref. This means that UPnP discovery will not occur if this new pref and the "Autodetect IP Address" pref are both unchecked. Fixes #4157.
Daniel Atallah <datallah@pidgin.im>
parents:
21549
diff
changeset
|
188 | if ((stun != NULL) && (stun->status == PURPLE_STUN_STATUS_DISCOVERED)) |
|
0b5181178201
Allow UPnP and NAT-PMP port mapping to be disabled via a pref. This means that UPnP discovery will not occur if this new pref and the "Autodetect IP Address" pref are both unchecked. Fixes #4157.
Daniel Atallah <datallah@pidgin.im>
parents:
21549
diff
changeset
|
189 | return stun->publicip; |
|
11424
b0f8535daa74
[gaim-migrate @ 13661]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11411
diff
changeset
|
190 | |
|
21810
0b5181178201
Allow UPnP and NAT-PMP port mapping to be disabled via a pref. This means that UPnP discovery will not occur if this new pref and the "Autodetect IP Address" pref are both unchecked. Fixes #4157.
Daniel Atallah <datallah@pidgin.im>
parents:
21549
diff
changeset
|
191 | /* Attempt to get the IP from a NAT device using UPnP */ |
|
0b5181178201
Allow UPnP and NAT-PMP port mapping to be disabled via a pref. This means that UPnP discovery will not occur if this new pref and the "Autodetect IP Address" pref are both unchecked. Fixes #4157.
Daniel Atallah <datallah@pidgin.im>
parents:
21549
diff
changeset
|
192 | ip = purple_upnp_get_public_ip(); |
|
0b5181178201
Allow UPnP and NAT-PMP port mapping to be disabled via a pref. This means that UPnP discovery will not occur if this new pref and the "Autodetect IP Address" pref are both unchecked. Fixes #4157.
Daniel Atallah <datallah@pidgin.im>
parents:
21549
diff
changeset
|
193 | if (ip != NULL) |
|
0b5181178201
Allow UPnP and NAT-PMP port mapping to be disabled via a pref. This means that UPnP discovery will not occur if this new pref and the "Autodetect IP Address" pref are both unchecked. Fixes #4157.
Daniel Atallah <datallah@pidgin.im>
parents:
21549
diff
changeset
|
194 | return ip; |
|
11195
d84d542a04ac
[gaim-migrate @ 13319]
Adam Warrington <awarring@users.sourceforge.net>
parents:
11033
diff
changeset
|
195 | |
|
21810
0b5181178201
Allow UPnP and NAT-PMP port mapping to be disabled via a pref. This means that UPnP discovery will not occur if this new pref and the "Autodetect IP Address" pref are both unchecked. Fixes #4157.
Daniel Atallah <datallah@pidgin.im>
parents:
21549
diff
changeset
|
196 | /* Attempt to get the IP from a NAT device using NAT-PMP */ |
|
0b5181178201
Allow UPnP and NAT-PMP port mapping to be disabled via a pref. This means that UPnP discovery will not occur if this new pref and the "Autodetect IP Address" pref are both unchecked. Fixes #4157.
Daniel Atallah <datallah@pidgin.im>
parents:
21549
diff
changeset
|
197 | ip = purple_pmp_get_public_ip(); |
|
0b5181178201
Allow UPnP and NAT-PMP port mapping to be disabled via a pref. This means that UPnP discovery will not occur if this new pref and the "Autodetect IP Address" pref are both unchecked. Fixes #4157.
Daniel Atallah <datallah@pidgin.im>
parents:
21549
diff
changeset
|
198 | if (ip != NULL) |
|
0b5181178201
Allow UPnP and NAT-PMP port mapping to be disabled via a pref. This means that UPnP discovery will not occur if this new pref and the "Autodetect IP Address" pref are both unchecked. Fixes #4157.
Daniel Atallah <datallah@pidgin.im>
parents:
21549
diff
changeset
|
199 | return ip; |
|
0b5181178201
Allow UPnP and NAT-PMP port mapping to be disabled via a pref. This means that UPnP discovery will not occur if this new pref and the "Autodetect IP Address" pref are both unchecked. Fixes #4157.
Daniel Atallah <datallah@pidgin.im>
parents:
21549
diff
changeset
|
200 | } |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
15502
diff
changeset
|
201 | |
|
8834
0a798e3d2b84
[gaim-migrate @ 9598]
Mark Doliner <markdoliner@pidgin.im>
parents:
8251
diff
changeset
|
202 | /* Just fetch the IP of the local system */ |
| 15884 | 203 | return purple_network_get_local_system_ip(fd); |
| 8231 | 204 | } |
| 205 | ||
|
11391
d172e72988cc
[gaim-migrate @ 13620]
Adam Warrington <awarring@users.sourceforge.net>
parents:
11336
diff
changeset
|
206 | |
|
12909
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
207 | static void |
| 15884 | 208 | purple_network_set_upnp_port_mapping_cb(gboolean success, gpointer data) |
|
12909
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
209 | { |
| 15884 | 210 | PurpleNetworkListenData *listen_data; |
|
14329
05c3cc0c1f79
[gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
211 | |
|
05c3cc0c1f79
[gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
212 | listen_data = data; |
|
05c3cc0c1f79
[gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
213 | /* TODO: Once we're keeping track of upnp requests... */ |
|
05c3cc0c1f79
[gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
214 | /* listen_data->pnp_data = NULL; */ |
|
12909
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
215 | |
|
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
216 | if (!success) { |
| 15884 | 217 | purple_debug_info("network", "Couldn't create UPnP mapping\n"); |
|
14329
05c3cc0c1f79
[gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
218 | if (listen_data->retry) { |
|
05c3cc0c1f79
[gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
219 | listen_data->retry = FALSE; |
|
05c3cc0c1f79
[gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
220 | listen_data->adding = FALSE; |
| 15884 | 221 | listen_data->mapping_data = purple_upnp_remove_port_mapping( |
| 222 | purple_network_get_port_from_fd(listen_data->listenfd), | |
|
15502
250802f80d94
Fix a crash when a network_listen_range process is canceled before its UPnP port mapping completes, which occurs regularly on certain routers when file transfers are initiated and then quickly finished. Much thanks to Elliott Harris and Eric Richie for their hard work with me hunting this down and fixing it.
Evan Schoenberg <evands@pidgin.im>
parents:
15435
diff
changeset
|
223 | (listen_data->socket_type == SOCK_STREAM) ? "TCP" : "UDP", |
| 15884 | 224 | purple_network_set_upnp_port_mapping_cb, listen_data); |
|
12909
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
225 | return; |
|
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
226 | } |
|
14329
05c3cc0c1f79
[gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
227 | } else if (!listen_data->adding) { |
|
12909
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
228 | /* We've tried successfully to remove the port mapping. |
|
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
229 | * Try to add it again */ |
|
14329
05c3cc0c1f79
[gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
230 | listen_data->adding = TRUE; |
| 15884 | 231 | listen_data->mapping_data = purple_upnp_set_port_mapping( |
| 232 | purple_network_get_port_from_fd(listen_data->listenfd), | |
|
15502
250802f80d94
Fix a crash when a network_listen_range process is canceled before its UPnP port mapping completes, which occurs regularly on certain routers when file transfers are initiated and then quickly finished. Much thanks to Elliott Harris and Eric Richie for their hard work with me hunting this down and fixing it.
Evan Schoenberg <evands@pidgin.im>
parents:
15435
diff
changeset
|
233 | (listen_data->socket_type == SOCK_STREAM) ? "TCP" : "UDP", |
| 15884 | 234 | purple_network_set_upnp_port_mapping_cb, listen_data); |
|
12909
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
235 | return; |
|
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
236 | } |
|
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
237 | |
|
14329
05c3cc0c1f79
[gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
238 | if (listen_data->cb) |
|
05c3cc0c1f79
[gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
239 | listen_data->cb(listen_data->listenfd, listen_data->cb_data); |
|
12909
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
240 | |
| 15884 | 241 | /* Clear the UPnP mapping data, since it's complete and purple_netweork_listen_cancel() will try to cancel |
|
15502
250802f80d94
Fix a crash when a network_listen_range process is canceled before its UPnP port mapping completes, which occurs regularly on certain routers when file transfers are initiated and then quickly finished. Much thanks to Elliott Harris and Eric Richie for their hard work with me hunting this down and fixing it.
Evan Schoenberg <evands@pidgin.im>
parents:
15435
diff
changeset
|
242 | * it otherwise. */ |
|
250802f80d94
Fix a crash when a network_listen_range process is canceled before its UPnP port mapping completes, which occurs regularly on certain routers when file transfers are initiated and then quickly finished. Much thanks to Elliott Harris and Eric Richie for their hard work with me hunting this down and fixing it.
Evan Schoenberg <evands@pidgin.im>
parents:
15435
diff
changeset
|
243 | listen_data->mapping_data = NULL; |
| 15884 | 244 | purple_network_listen_cancel(listen_data); |
|
12909
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
245 | } |
|
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
246 | |
|
15933
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
247 | static gboolean |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
248 | purple_network_finish_pmp_map_cb(gpointer data) |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
249 | { |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
250 | PurpleNetworkListenData *listen_data; |
|
15963
effb28723fee
Whitespace and make sure stuff is #defined to an actual value.
Mark Doliner <markdoliner@pidgin.im>
parents:
15956
diff
changeset
|
251 | |
|
15933
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
252 | listen_data = data; |
|
15963
effb28723fee
Whitespace and make sure stuff is #defined to an actual value.
Mark Doliner <markdoliner@pidgin.im>
parents:
15956
diff
changeset
|
253 | |
|
15933
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
254 | if (listen_data->cb) |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
255 | listen_data->cb(listen_data->listenfd, listen_data->cb_data); |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
256 | |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
257 | purple_network_listen_cancel(listen_data); |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
258 | |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
259 | return FALSE; |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
260 | } |
|
12909
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
261 | |
|
21549
7436059db33b
Don't map the port used for bonjour file transfers externally. This adds a new function that will go away in 3.0.0 when we can modify purple_network_do_listen to take an additional parameter.
Daniel Atallah <datallah@pidgin.im>
parents:
21389
diff
changeset
|
262 | static gboolean listen_map_external = TRUE; |
|
7436059db33b
Don't map the port used for bonjour file transfers externally. This adds a new function that will go away in 3.0.0 when we can modify purple_network_do_listen to take an additional parameter.
Daniel Atallah <datallah@pidgin.im>
parents:
21389
diff
changeset
|
263 | void purple_network_listen_map_external(gboolean map_external) |
|
7436059db33b
Don't map the port used for bonjour file transfers externally. This adds a new function that will go away in 3.0.0 when we can modify purple_network_do_listen to take an additional parameter.
Daniel Atallah <datallah@pidgin.im>
parents:
21389
diff
changeset
|
264 | { |
|
7436059db33b
Don't map the port used for bonjour file transfers externally. This adds a new function that will go away in 3.0.0 when we can modify purple_network_do_listen to take an additional parameter.
Daniel Atallah <datallah@pidgin.im>
parents:
21389
diff
changeset
|
265 | listen_map_external = map_external; |
|
7436059db33b
Don't map the port used for bonjour file transfers externally. This adds a new function that will go away in 3.0.0 when we can modify purple_network_do_listen to take an additional parameter.
Daniel Atallah <datallah@pidgin.im>
parents:
21389
diff
changeset
|
266 | } |
|
7436059db33b
Don't map the port used for bonjour file transfers externally. This adds a new function that will go away in 3.0.0 when we can modify purple_network_do_listen to take an additional parameter.
Daniel Atallah <datallah@pidgin.im>
parents:
21389
diff
changeset
|
267 | |
| 15884 | 268 | static PurpleNetworkListenData * |
| 269 | purple_network_do_listen(unsigned short port, int socket_type, PurpleNetworkListenCallback cb, gpointer cb_data) | |
| 8231 | 270 | { |
|
9452
0e3cdb898d3e
[gaim-migrate @ 10276]
Mark Doliner <markdoliner@pidgin.im>
parents:
9449
diff
changeset
|
271 | int listenfd = -1; |
|
20239
ae122f419324
applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents:
20147
diff
changeset
|
272 | int flags; |
| 8231 | 273 | const int on = 1; |
| 15884 | 274 | PurpleNetworkListenData *listen_data; |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
15502
diff
changeset
|
275 | unsigned short actual_port; |
|
13426
032ea2c9ce2d
[gaim-migrate @ 15800]
Daniel Atallah <datallah@pidgin.im>
parents:
13346
diff
changeset
|
276 | #ifdef HAVE_GETADDRINFO |
|
9449
8c5a1697bca6
[gaim-migrate @ 10273]
Mark Doliner <markdoliner@pidgin.im>
parents:
8981
diff
changeset
|
277 | int errnum; |
|
8c5a1697bca6
[gaim-migrate @ 10273]
Mark Doliner <markdoliner@pidgin.im>
parents:
8981
diff
changeset
|
278 | struct addrinfo hints, *res, *next; |
| 9456 | 279 | char serv[6]; |
| 8231 | 280 | |
|
9449
8c5a1697bca6
[gaim-migrate @ 10273]
Mark Doliner <markdoliner@pidgin.im>
parents:
8981
diff
changeset
|
281 | /* |
|
8c5a1697bca6
[gaim-migrate @ 10273]
Mark Doliner <markdoliner@pidgin.im>
parents:
8981
diff
changeset
|
282 | * Get a list of addresses on this machine. |
|
8c5a1697bca6
[gaim-migrate @ 10273]
Mark Doliner <markdoliner@pidgin.im>
parents:
8981
diff
changeset
|
283 | */ |
|
8c5a1697bca6
[gaim-migrate @ 10273]
Mark Doliner <markdoliner@pidgin.im>
parents:
8981
diff
changeset
|
284 | snprintf(serv, sizeof(serv), "%hu", port); |
| 8231 | 285 | memset(&hints, 0, sizeof(struct addrinfo)); |
| 286 | hints.ai_flags = AI_PASSIVE; | |
| 287 | hints.ai_family = AF_UNSPEC; | |
|
12730
f64fdbc34677
[gaim-migrate @ 15074]
Daniel Atallah <datallah@pidgin.im>
parents:
12728
diff
changeset
|
288 | hints.ai_socktype = socket_type; |
|
9449
8c5a1697bca6
[gaim-migrate @ 10273]
Mark Doliner <markdoliner@pidgin.im>
parents:
8981
diff
changeset
|
289 | errnum = getaddrinfo(NULL /* any IP */, serv, &hints, &res); |
|
8c5a1697bca6
[gaim-migrate @ 10273]
Mark Doliner <markdoliner@pidgin.im>
parents:
8981
diff
changeset
|
290 | if (errnum != 0) { |
|
11221
be3982550ac0
[gaim-migrate @ 13353]
Daniel Atallah <datallah@pidgin.im>
parents:
11215
diff
changeset
|
291 | #ifndef _WIN32 |
|
21977
c87889698afb
Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <markdoliner@pidgin.im>
parents:
21817
diff
changeset
|
292 | purple_debug_warning("network", "getaddrinfo: %s\n", purple_gai_strerror(errnum)); |
|
9449
8c5a1697bca6
[gaim-migrate @ 10273]
Mark Doliner <markdoliner@pidgin.im>
parents:
8981
diff
changeset
|
293 | if (errnum == EAI_SYSTEM) |
|
21389
e1dd8142bb87
replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents:
20239
diff
changeset
|
294 | purple_debug_warning("network", "getaddrinfo: system error: %s\n", g_strerror(errno)); |
|
11221
be3982550ac0
[gaim-migrate @ 13353]
Daniel Atallah <datallah@pidgin.im>
parents:
11215
diff
changeset
|
295 | #else |
| 15884 | 296 | purple_debug_warning("network", "getaddrinfo: Error Code = %d\n", errnum); |
|
11221
be3982550ac0
[gaim-migrate @ 13353]
Daniel Atallah <datallah@pidgin.im>
parents:
11215
diff
changeset
|
297 | #endif |
|
14329
05c3cc0c1f79
[gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
298 | return NULL; |
| 8231 | 299 | } |
|
9449
8c5a1697bca6
[gaim-migrate @ 10273]
Mark Doliner <markdoliner@pidgin.im>
parents:
8981
diff
changeset
|
300 | |
|
8c5a1697bca6
[gaim-migrate @ 10273]
Mark Doliner <markdoliner@pidgin.im>
parents:
8981
diff
changeset
|
301 | /* |
|
8c5a1697bca6
[gaim-migrate @ 10273]
Mark Doliner <markdoliner@pidgin.im>
parents:
8981
diff
changeset
|
302 | * Go through the list of addresses and attempt to listen on |
|
8c5a1697bca6
[gaim-migrate @ 10273]
Mark Doliner <markdoliner@pidgin.im>
parents:
8981
diff
changeset
|
303 | * one of them. |
|
8c5a1697bca6
[gaim-migrate @ 10273]
Mark Doliner <markdoliner@pidgin.im>
parents:
8981
diff
changeset
|
304 | * XXX - Try IPv6 addresses first? |
|
8c5a1697bca6
[gaim-migrate @ 10273]
Mark Doliner <markdoliner@pidgin.im>
parents:
8981
diff
changeset
|
305 | */ |
|
8c5a1697bca6
[gaim-migrate @ 10273]
Mark Doliner <markdoliner@pidgin.im>
parents:
8981
diff
changeset
|
306 | for (next = res; next != NULL; next = next->ai_next) { |
| 9455 | 307 | listenfd = socket(next->ai_family, next->ai_socktype, next->ai_protocol); |
| 8231 | 308 | if (listenfd < 0) |
| 309 | continue; | |
|
9449
8c5a1697bca6
[gaim-migrate @ 10273]
Mark Doliner <markdoliner@pidgin.im>
parents:
8981
diff
changeset
|
310 | if (setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) != 0) |
|
21389
e1dd8142bb87
replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents:
20239
diff
changeset
|
311 | purple_debug_warning("network", "setsockopt: %s\n", g_strerror(errno)); |
| 9455 | 312 | if (bind(listenfd, next->ai_addr, next->ai_addrlen) == 0) |
| 8231 | 313 | break; /* success */ |
|
12730
f64fdbc34677
[gaim-migrate @ 15074]
Daniel Atallah <datallah@pidgin.im>
parents:
12728
diff
changeset
|
314 | /* XXX - It is unclear to me (datallah) whether we need to be |
|
f64fdbc34677
[gaim-migrate @ 15074]
Daniel Atallah <datallah@pidgin.im>
parents:
12728
diff
changeset
|
315 | using a new socket each time */ |
| 8231 | 316 | close(listenfd); |
|
9449
8c5a1697bca6
[gaim-migrate @ 10273]
Mark Doliner <markdoliner@pidgin.im>
parents:
8981
diff
changeset
|
317 | } |
| 8231 | 318 | |
|
9449
8c5a1697bca6
[gaim-migrate @ 10273]
Mark Doliner <markdoliner@pidgin.im>
parents:
8981
diff
changeset
|
319 | freeaddrinfo(res); |
| 8231 | 320 | |
|
9449
8c5a1697bca6
[gaim-migrate @ 10273]
Mark Doliner <markdoliner@pidgin.im>
parents:
8981
diff
changeset
|
321 | if (next == NULL) |
|
14329
05c3cc0c1f79
[gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
322 | return NULL; |
| 8231 | 323 | #else |
| 324 | struct sockaddr_in sockin; | |
| 325 | ||
|
12730
f64fdbc34677
[gaim-migrate @ 15074]
Daniel Atallah <datallah@pidgin.im>
parents:
12728
diff
changeset
|
326 | if ((listenfd = socket(AF_INET, socket_type, 0)) < 0) { |
|
21389
e1dd8142bb87
replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents:
20239
diff
changeset
|
327 | purple_debug_warning("network", "socket: %s\n", g_strerror(errno)); |
|
14329
05c3cc0c1f79
[gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
328 | return NULL; |
| 8231 | 329 | } |
| 330 | ||
|
9449
8c5a1697bca6
[gaim-migrate @ 10273]
Mark Doliner <markdoliner@pidgin.im>
parents:
8981
diff
changeset
|
331 | if (setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) != 0) |
|
21389
e1dd8142bb87
replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents:
20239
diff
changeset
|
332 | purple_debug_warning("network", "setsockopt: %s\n", g_strerror(errno)); |
| 8231 | 333 | |
| 334 | memset(&sockin, 0, sizeof(struct sockaddr_in)); | |
|
9449
8c5a1697bca6
[gaim-migrate @ 10273]
Mark Doliner <markdoliner@pidgin.im>
parents:
8981
diff
changeset
|
335 | sockin.sin_family = PF_INET; |
|
8251
091ca9b900c1
[gaim-migrate @ 8974]
Mark Doliner <markdoliner@pidgin.im>
parents:
8250
diff
changeset
|
336 | sockin.sin_port = htons(port); |
| 8231 | 337 | |
| 338 | if (bind(listenfd, (struct sockaddr *)&sockin, sizeof(struct sockaddr_in)) != 0) { | |
|
21389
e1dd8142bb87
replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents:
20239
diff
changeset
|
339 | purple_debug_warning("network", "bind: %s\n", g_strerror(errno)); |
| 8231 | 340 | close(listenfd); |
|
14329
05c3cc0c1f79
[gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
341 | return NULL; |
| 8231 | 342 | } |
| 343 | #endif | |
| 344 | ||
|
12730
f64fdbc34677
[gaim-migrate @ 15074]
Daniel Atallah <datallah@pidgin.im>
parents:
12728
diff
changeset
|
345 | if (socket_type == SOCK_STREAM && listen(listenfd, 4) != 0) { |
|
21389
e1dd8142bb87
replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents:
20239
diff
changeset
|
346 | purple_debug_warning("network", "listen: %s\n", g_strerror(errno)); |
| 8231 | 347 | close(listenfd); |
|
14329
05c3cc0c1f79
[gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
348 | return NULL; |
| 8231 | 349 | } |
|
20239
ae122f419324
applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents:
20147
diff
changeset
|
350 | flags = fcntl(listenfd, F_GETFL); |
|
ae122f419324
applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents:
20147
diff
changeset
|
351 | fcntl(listenfd, F_SETFL, flags | O_NONBLOCK); |
| 8231 | 352 | |
| 15884 | 353 | actual_port = purple_network_get_port_from_fd(listenfd); |
|
11391
d172e72988cc
[gaim-migrate @ 13620]
Adam Warrington <awarring@users.sourceforge.net>
parents:
11336
diff
changeset
|
354 | |
| 15884 | 355 | purple_debug_info("network", "Listening on port: %hu\n", actual_port); |
|
15963
effb28723fee
Whitespace and make sure stuff is #defined to an actual value.
Mark Doliner <markdoliner@pidgin.im>
parents:
15956
diff
changeset
|
356 | |
| 15884 | 357 | listen_data = g_new0(PurpleNetworkListenData, 1); |
|
14329
05c3cc0c1f79
[gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
358 | listen_data->listenfd = listenfd; |
|
05c3cc0c1f79
[gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
359 | listen_data->adding = TRUE; |
|
05c3cc0c1f79
[gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
360 | listen_data->retry = TRUE; |
|
05c3cc0c1f79
[gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
361 | listen_data->cb = cb; |
|
05c3cc0c1f79
[gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
362 | listen_data->cb_data = cb_data; |
|
19822
a533aa745702
Store the socket_type in the PurpleNetworkListenData correctly so that callback functions can use it correctly. Fixes #2933.
Daniel Atallah <datallah@pidgin.im>
parents:
19585
diff
changeset
|
363 | listen_data->socket_type = socket_type; |
|
11195
d84d542a04ac
[gaim-migrate @ 13319]
Adam Warrington <awarring@users.sourceforge.net>
parents:
11033
diff
changeset
|
364 | |
|
21810
0b5181178201
Allow UPnP and NAT-PMP port mapping to be disabled via a pref. This means that UPnP discovery will not occur if this new pref and the "Autodetect IP Address" pref are both unchecked. Fixes #4157.
Daniel Atallah <datallah@pidgin.im>
parents:
21549
diff
changeset
|
365 | if (!listen_map_external || !purple_prefs_get_bool("/purple/network/map_ports")) |
|
21549
7436059db33b
Don't map the port used for bonjour file transfers externally. This adds a new function that will go away in 3.0.0 when we can modify purple_network_do_listen to take an additional parameter.
Daniel Atallah <datallah@pidgin.im>
parents:
21389
diff
changeset
|
366 | { |
|
7436059db33b
Don't map the port used for bonjour file transfers externally. This adds a new function that will go away in 3.0.0 when we can modify purple_network_do_listen to take an additional parameter.
Daniel Atallah <datallah@pidgin.im>
parents:
21389
diff
changeset
|
367 | purple_debug_info("network", "Skipping external port mapping.\n"); |
|
7436059db33b
Don't map the port used for bonjour file transfers externally. This adds a new function that will go away in 3.0.0 when we can modify purple_network_do_listen to take an additional parameter.
Daniel Atallah <datallah@pidgin.im>
parents:
21389
diff
changeset
|
368 | /* The pmp_map_cb does what we want to do */ |
|
7436059db33b
Don't map the port used for bonjour file transfers externally. This adds a new function that will go away in 3.0.0 when we can modify purple_network_do_listen to take an additional parameter.
Daniel Atallah <datallah@pidgin.im>
parents:
21389
diff
changeset
|
369 | purple_timeout_add(0, purple_network_finish_pmp_map_cb, listen_data); |
|
7436059db33b
Don't map the port used for bonjour file transfers externally. This adds a new function that will go away in 3.0.0 when we can modify purple_network_do_listen to take an additional parameter.
Daniel Atallah <datallah@pidgin.im>
parents:
21389
diff
changeset
|
370 | } |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
15502
diff
changeset
|
371 | /* Attempt a NAT-PMP Mapping, which will return immediately */ |
|
21549
7436059db33b
Don't map the port used for bonjour file transfers externally. This adds a new function that will go away in 3.0.0 when we can modify purple_network_do_listen to take an additional parameter.
Daniel Atallah <datallah@pidgin.im>
parents:
21389
diff
changeset
|
372 | else if (purple_pmp_create_map(((socket_type == SOCK_STREAM) ? PURPLE_PMP_TYPE_TCP : PURPLE_PMP_TYPE_UDP), |
|
16012
77b7fe1bfe69
purple_pmp_create_map() returns a gboolean now, not a pointer
Evan Schoenberg <evands@pidgin.im>
parents:
15963
diff
changeset
|
373 | actual_port, actual_port, PURPLE_PMP_LIFETIME)) |
|
15933
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
374 | { |
|
21549
7436059db33b
Don't map the port used for bonjour file transfers externally. This adds a new function that will go away in 3.0.0 when we can modify purple_network_do_listen to take an additional parameter.
Daniel Atallah <datallah@pidgin.im>
parents:
21389
diff
changeset
|
375 | purple_debug_info("network", "Created NAT-PMP mapping on port %i\n", actual_port); |
|
15933
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
376 | /* We want to return listen_data now, and on the next run loop trigger the cb and destroy listen_data */ |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
377 | purple_timeout_add(0, purple_network_finish_pmp_map_cb, listen_data); |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
378 | } |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
379 | else |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
380 | { |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
381 | /* Attempt a UPnP Mapping */ |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
382 | listen_data->mapping_data = purple_upnp_set_port_mapping( |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
383 | actual_port, |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
384 | (socket_type == SOCK_STREAM) ? "TCP" : "UDP", |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
385 | purple_network_set_upnp_port_mapping_cb, listen_data); |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
386 | } |
|
12909
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
387 | |
|
14329
05c3cc0c1f79
[gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
388 | return listen_data; |
| 8231 | 389 | } |
| 390 | ||
| 15884 | 391 | PurpleNetworkListenData * |
| 392 | purple_network_listen(unsigned short port, int socket_type, | |
| 393 | PurpleNetworkListenCallback cb, gpointer cb_data) | |
|
8246
c83c0421149a
[gaim-migrate @ 8969]
Mark Doliner <markdoliner@pidgin.im>
parents:
8245
diff
changeset
|
394 | { |
|
14329
05c3cc0c1f79
[gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
395 | g_return_val_if_fail(port != 0, NULL); |
|
8250
e855dcce1fa0
[gaim-migrate @ 8973]
Mark Doliner <markdoliner@pidgin.im>
parents:
8248
diff
changeset
|
396 | |
| 15884 | 397 | return purple_network_do_listen(port, socket_type, cb, cb_data); |
|
8246
c83c0421149a
[gaim-migrate @ 8969]
Mark Doliner <markdoliner@pidgin.im>
parents:
8245
diff
changeset
|
398 | } |
|
c83c0421149a
[gaim-migrate @ 8969]
Mark Doliner <markdoliner@pidgin.im>
parents:
8245
diff
changeset
|
399 | |
| 15884 | 400 | PurpleNetworkListenData * |
| 401 | purple_network_listen_range(unsigned short start, unsigned short end, | |
| 402 | int socket_type, PurpleNetworkListenCallback cb, gpointer cb_data) | |
| 8231 | 403 | { |
| 15884 | 404 | PurpleNetworkListenData *ret = NULL; |
| 8231 | 405 | |
|
16478
19107605c565
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@pidgin.im>
parents:
16035
diff
changeset
|
406 | if (purple_prefs_get_bool("/purple/network/ports_range_use")) { |
|
19107605c565
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@pidgin.im>
parents:
16035
diff
changeset
|
407 | start = purple_prefs_get_int("/purple/network/ports_range_start"); |
|
19107605c565
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@pidgin.im>
parents:
16035
diff
changeset
|
408 | end = purple_prefs_get_int("/purple/network/ports_range_end"); |
|
8250
e855dcce1fa0
[gaim-migrate @ 8973]
Mark Doliner <markdoliner@pidgin.im>
parents:
8248
diff
changeset
|
409 | } else { |
|
e855dcce1fa0
[gaim-migrate @ 8973]
Mark Doliner <markdoliner@pidgin.im>
parents:
8248
diff
changeset
|
410 | if (end < start) |
|
e855dcce1fa0
[gaim-migrate @ 8973]
Mark Doliner <markdoliner@pidgin.im>
parents:
8248
diff
changeset
|
411 | end = start; |
|
8239
d19f1c66720c
[gaim-migrate @ 8962]
Mark Doliner <markdoliner@pidgin.im>
parents:
8231
diff
changeset
|
412 | } |
| 8231 | 413 | |
| 414 | for (; start <= end; start++) { | |
| 15884 | 415 | ret = purple_network_do_listen(start, socket_type, cb, cb_data); |
|
14329
05c3cc0c1f79
[gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
416 | if (ret != NULL) |
| 8231 | 417 | break; |
| 418 | } | |
| 419 | ||
| 420 | return ret; | |
| 421 | } | |
| 422 | ||
| 15884 | 423 | void purple_network_listen_cancel(PurpleNetworkListenData *listen_data) |
|
14329
05c3cc0c1f79
[gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
424 | { |
|
15502
250802f80d94
Fix a crash when a network_listen_range process is canceled before its UPnP port mapping completes, which occurs regularly on certain routers when file transfers are initiated and then quickly finished. Much thanks to Elliott Harris and Eric Richie for their hard work with me hunting this down and fixing it.
Evan Schoenberg <evands@pidgin.im>
parents:
15435
diff
changeset
|
425 | if (listen_data->mapping_data != NULL) |
| 15884 | 426 | purple_upnp_cancel_port_mapping(listen_data->mapping_data); |
|
15502
250802f80d94
Fix a crash when a network_listen_range process is canceled before its UPnP port mapping completes, which occurs regularly on certain routers when file transfers are initiated and then quickly finished. Much thanks to Elliott Harris and Eric Richie for their hard work with me hunting this down and fixing it.
Evan Schoenberg <evands@pidgin.im>
parents:
15435
diff
changeset
|
427 | |
|
14329
05c3cc0c1f79
[gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
428 | g_free(listen_data); |
|
05c3cc0c1f79
[gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
429 | } |
|
05c3cc0c1f79
[gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
430 | |
|
8834
0a798e3d2b84
[gaim-migrate @ 9598]
Mark Doliner <markdoliner@pidgin.im>
parents:
8251
diff
changeset
|
431 | unsigned short |
| 15884 | 432 | purple_network_get_port_from_fd(int fd) |
| 8231 | 433 | { |
| 434 | struct sockaddr_in addr; | |
| 435 | socklen_t len; | |
| 436 | ||
|
9449
8c5a1697bca6
[gaim-migrate @ 10273]
Mark Doliner <markdoliner@pidgin.im>
parents:
8981
diff
changeset
|
437 | g_return_val_if_fail(fd >= 0, 0); |
| 8231 | 438 | |
| 439 | len = sizeof(addr); | |
| 440 | if (getsockname(fd, (struct sockaddr *) &addr, &len) == -1) { | |
|
21389
e1dd8142bb87
replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents:
20239
diff
changeset
|
441 | purple_debug_warning("network", "getsockname: %s\n", g_strerror(errno)); |
| 8231 | 442 | return 0; |
| 443 | } | |
| 444 | ||
| 445 | return ntohs(addr.sin_port); | |
| 446 | } | |
| 447 | ||
|
14784
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
448 | #ifdef _WIN32 |
|
14853
d06b1f28a8b2
[gaim-migrate @ 17556]
Daniel Atallah <datallah@pidgin.im>
parents:
14842
diff
changeset
|
449 | #ifndef NS_NLA |
|
d06b1f28a8b2
[gaim-migrate @ 17556]
Daniel Atallah <datallah@pidgin.im>
parents:
14842
diff
changeset
|
450 | #define NS_NLA 15 |
|
d06b1f28a8b2
[gaim-migrate @ 17556]
Daniel Atallah <datallah@pidgin.im>
parents:
14842
diff
changeset
|
451 | #endif |
|
14842
fe08ba80d369
[gaim-migrate @ 17544]
Daniel Atallah <datallah@pidgin.im>
parents:
14839
diff
changeset
|
452 | static gint |
| 15884 | 453 | wpurple_get_connected_network_count(void) |
|
14784
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
454 | { |
|
19585
14b519abcc26
Fix some conversion warnings about using negative values with unsigned types. There are more, but these were easy fixes. You may think that I'm changing the API, but I'm really not - it was just wrong.
Daniel Atallah <datallah@pidgin.im>
parents:
18555
diff
changeset
|
455 | gint net_cnt = 0; |
|
14784
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
456 | |
|
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
457 | WSAQUERYSET qs; |
|
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
458 | HANDLE h; |
|
14957
1519e663dd9b
[gaim-migrate @ 17667]
Daniel Atallah <datallah@pidgin.im>
parents:
14877
diff
changeset
|
459 | gint retval; |
|
1519e663dd9b
[gaim-migrate @ 17667]
Daniel Atallah <datallah@pidgin.im>
parents:
14877
diff
changeset
|
460 | int errorid; |
|
14784
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
461 | |
|
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
462 | memset(&qs, 0, sizeof(WSAQUERYSET)); |
|
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
463 | qs.dwSize = sizeof(WSAQUERYSET); |
|
14853
d06b1f28a8b2
[gaim-migrate @ 17556]
Daniel Atallah <datallah@pidgin.im>
parents:
14842
diff
changeset
|
464 | qs.dwNameSpace = NS_NLA; |
|
14784
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
465 | |
|
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
466 | retval = WSALookupServiceBegin(&qs, LUP_RETURN_ALL, &h); |
|
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
467 | if (retval != ERROR_SUCCESS) { |
|
14957
1519e663dd9b
[gaim-migrate @ 17667]
Daniel Atallah <datallah@pidgin.im>
parents:
14877
diff
changeset
|
468 | gchar *msg; |
|
1519e663dd9b
[gaim-migrate @ 17667]
Daniel Atallah <datallah@pidgin.im>
parents:
14877
diff
changeset
|
469 | errorid = WSAGetLastError(); |
|
1519e663dd9b
[gaim-migrate @ 17667]
Daniel Atallah <datallah@pidgin.im>
parents:
14877
diff
changeset
|
470 | msg = g_win32_error_message(errorid); |
| 15884 | 471 | purple_debug_warning("network", "Couldn't retrieve NLA SP lookup handle. " |
|
14853
d06b1f28a8b2
[gaim-migrate @ 17556]
Daniel Atallah <datallah@pidgin.im>
parents:
14842
diff
changeset
|
472 | "NLA service is probably not running. Message: %s (%d).\n", |
|
d06b1f28a8b2
[gaim-migrate @ 17556]
Daniel Atallah <datallah@pidgin.im>
parents:
14842
diff
changeset
|
473 | msg, errorid); |
|
14784
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
474 | g_free(msg); |
|
14838
40cc5f858426
[gaim-migrate @ 17540]
Daniel Atallah <datallah@pidgin.im>
parents:
14784
diff
changeset
|
475 | |
|
14842
fe08ba80d369
[gaim-migrate @ 17544]
Daniel Atallah <datallah@pidgin.im>
parents:
14839
diff
changeset
|
476 | return -1; |
|
14784
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
477 | } else { |
|
14959
eb5cf3522fda
[gaim-migrate @ 17669]
Daniel Atallah <datallah@pidgin.im>
parents:
14957
diff
changeset
|
478 | char buf[4096]; |
|
14784
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
479 | WSAQUERYSET *res = (LPWSAQUERYSET) buf; |
|
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
480 | DWORD size = sizeof(buf); |
|
14957
1519e663dd9b
[gaim-migrate @ 17667]
Daniel Atallah <datallah@pidgin.im>
parents:
14877
diff
changeset
|
481 | while ((retval = WSALookupServiceNext(h, 0, &size, res)) == ERROR_SUCCESS) { |
|
14784
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
482 | net_cnt++; |
| 15884 | 483 | purple_debug_info("network", "found network '%s'\n", |
|
14784
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
484 | res->lpszServiceInstanceName ? res->lpszServiceInstanceName : "(NULL)"); |
|
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
485 | size = sizeof(buf); |
|
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
486 | } |
|
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
487 | |
|
14957
1519e663dd9b
[gaim-migrate @ 17667]
Daniel Atallah <datallah@pidgin.im>
parents:
14877
diff
changeset
|
488 | errorid = WSAGetLastError(); |
|
1519e663dd9b
[gaim-migrate @ 17667]
Daniel Atallah <datallah@pidgin.im>
parents:
14877
diff
changeset
|
489 | if (!(errorid == WSA_E_NO_MORE || errorid == WSAENOMORE)) { |
|
1519e663dd9b
[gaim-migrate @ 17667]
Daniel Atallah <datallah@pidgin.im>
parents:
14877
diff
changeset
|
490 | gchar *msg = g_win32_error_message(errorid); |
| 15884 | 491 | purple_debug_error("network", "got unexpected NLA response %s (%d)\n", msg, errorid); |
|
14957
1519e663dd9b
[gaim-migrate @ 17667]
Daniel Atallah <datallah@pidgin.im>
parents:
14877
diff
changeset
|
492 | g_free(msg); |
|
1519e663dd9b
[gaim-migrate @ 17667]
Daniel Atallah <datallah@pidgin.im>
parents:
14877
diff
changeset
|
493 | |
|
1519e663dd9b
[gaim-migrate @ 17667]
Daniel Atallah <datallah@pidgin.im>
parents:
14877
diff
changeset
|
494 | net_cnt = -1; |
|
1519e663dd9b
[gaim-migrate @ 17667]
Daniel Atallah <datallah@pidgin.im>
parents:
14877
diff
changeset
|
495 | } |
|
1519e663dd9b
[gaim-migrate @ 17667]
Daniel Atallah <datallah@pidgin.im>
parents:
14877
diff
changeset
|
496 | |
|
1519e663dd9b
[gaim-migrate @ 17667]
Daniel Atallah <datallah@pidgin.im>
parents:
14877
diff
changeset
|
497 | retval = WSALookupServiceEnd(h); |
|
14784
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
498 | } |
|
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
499 | |
|
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
500 | return net_cnt; |
|
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
501 | |
|
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
502 | } |
|
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
503 | |
| 15884 | 504 | static gboolean wpurple_network_change_thread_cb(gpointer data) |
|
14784
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
505 | { |
|
14842
fe08ba80d369
[gaim-migrate @ 17544]
Daniel Atallah <datallah@pidgin.im>
parents:
14839
diff
changeset
|
506 | gint new_count; |
| 15884 | 507 | PurpleConnectionUiOps *ui_ops = purple_connections_get_ui_ops(); |
|
14784
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
508 | |
| 15884 | 509 | new_count = wpurple_get_connected_network_count(); |
|
14784
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
510 | |
|
14842
fe08ba80d369
[gaim-migrate @ 17544]
Daniel Atallah <datallah@pidgin.im>
parents:
14839
diff
changeset
|
511 | if (new_count < 0) |
|
fe08ba80d369
[gaim-migrate @ 17544]
Daniel Atallah <datallah@pidgin.im>
parents:
14839
diff
changeset
|
512 | return FALSE; |
|
fe08ba80d369
[gaim-migrate @ 17544]
Daniel Atallah <datallah@pidgin.im>
parents:
14839
diff
changeset
|
513 | |
| 15884 | 514 | purple_debug_info("network", "Received Network Change Notification. Current network count is %d, previous count was %d.\n", new_count, current_network_count); |
|
14784
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
515 | |
|
16035
eb4eda79a147
The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents:
16012
diff
changeset
|
516 | purple_signal_emit(purple_network_get_handle(), "network-configuration-changed", NULL); |
|
eb4eda79a147
The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents:
16012
diff
changeset
|
517 | |
|
14877
084d14fe0445
[gaim-migrate @ 17581]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
14864
diff
changeset
|
518 | if (new_count > 0 && ui_ops != NULL && ui_ops->network_connected != NULL) { |
|
14784
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
519 | ui_ops->network_connected(); |
|
14877
084d14fe0445
[gaim-migrate @ 17581]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
14864
diff
changeset
|
520 | } else if (new_count == 0 && current_network_count > 0 && |
|
084d14fe0445
[gaim-migrate @ 17581]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
14864
diff
changeset
|
521 | ui_ops != NULL && ui_ops->network_disconnected != NULL) { |
|
14784
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
522 | ui_ops->network_disconnected(); |
|
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
523 | } |
|
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
524 | |
|
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
525 | current_network_count = new_count; |
|
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
526 | |
|
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
527 | return FALSE; |
|
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
528 | } |
|
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
529 | |
| 15884 | 530 | static gpointer wpurple_network_change_thread(gpointer data) |
|
14784
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
531 | { |
|
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
532 | HANDLE h; |
|
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
533 | WSAQUERYSET qs; |
|
14842
fe08ba80d369
[gaim-migrate @ 17544]
Daniel Atallah <datallah@pidgin.im>
parents:
14839
diff
changeset
|
534 | time_t last_trigger = time(NULL); |
|
14784
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
535 | |
|
18555
ececd1bd99e3
Fix up some linkage to compile on Visual Studio. He claims this doesn't
Nick Hebner <hebnern@gmail.com>
parents:
17636
diff
changeset
|
536 | int (WSAAPI *MyWSANSPIoctl) ( |
|
14853
d06b1f28a8b2
[gaim-migrate @ 17556]
Daniel Atallah <datallah@pidgin.im>
parents:
14842
diff
changeset
|
537 | HANDLE hLookup, DWORD dwControlCode, LPVOID lpvInBuffer, |
|
d06b1f28a8b2
[gaim-migrate @ 17556]
Daniel Atallah <datallah@pidgin.im>
parents:
14842
diff
changeset
|
538 | DWORD cbInBuffer, LPVOID lpvOutBuffer, DWORD cbOutBuffer, |
|
d06b1f28a8b2
[gaim-migrate @ 17556]
Daniel Atallah <datallah@pidgin.im>
parents:
14842
diff
changeset
|
539 | LPDWORD lpcbBytesReturned, LPWSACOMPLETION lpCompletion) = NULL; |
|
19585
14b519abcc26
Fix some conversion warnings about using negative values with unsigned types. There are more, but these were easy fixes. You may think that I'm changing the API, but I'm really not - it was just wrong.
Daniel Atallah <datallah@pidgin.im>
parents:
18555
diff
changeset
|
540 | |
| 15884 | 541 | if (!(MyWSANSPIoctl = (void*) wpurple_find_and_loadproc("ws2_32.dll", "WSANSPIoctl"))) { |
|
14784
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
542 | g_thread_exit(NULL); |
|
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
543 | return NULL; |
|
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
544 | } |
|
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
545 | |
|
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
546 | while (TRUE) { |
|
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
547 | int retval; |
|
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
548 | DWORD retLen = 0; |
|
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
549 | |
|
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
550 | memset(&qs, 0, sizeof(WSAQUERYSET)); |
|
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
551 | qs.dwSize = sizeof(WSAQUERYSET); |
|
14853
d06b1f28a8b2
[gaim-migrate @ 17556]
Daniel Atallah <datallah@pidgin.im>
parents:
14842
diff
changeset
|
552 | qs.dwNameSpace = NS_NLA; |
|
d06b1f28a8b2
[gaim-migrate @ 17556]
Daniel Atallah <datallah@pidgin.im>
parents:
14842
diff
changeset
|
553 | if (WSALookupServiceBegin(&qs, 0, &h) == SOCKET_ERROR) { |
|
d06b1f28a8b2
[gaim-migrate @ 17556]
Daniel Atallah <datallah@pidgin.im>
parents:
14842
diff
changeset
|
554 | int errorid = WSAGetLastError(); |
|
d06b1f28a8b2
[gaim-migrate @ 17556]
Daniel Atallah <datallah@pidgin.im>
parents:
14842
diff
changeset
|
555 | gchar *msg = g_win32_error_message(errorid); |
| 15884 | 556 | purple_debug_warning("network", "Couldn't retrieve NLA SP lookup handle. " |
|
14853
d06b1f28a8b2
[gaim-migrate @ 17556]
Daniel Atallah <datallah@pidgin.im>
parents:
14842
diff
changeset
|
557 | "NLA service is probably not running. Message: %s (%d).\n", |
|
d06b1f28a8b2
[gaim-migrate @ 17556]
Daniel Atallah <datallah@pidgin.im>
parents:
14842
diff
changeset
|
558 | msg, errorid); |
|
d06b1f28a8b2
[gaim-migrate @ 17556]
Daniel Atallah <datallah@pidgin.im>
parents:
14842
diff
changeset
|
559 | g_free(msg); |
|
d06b1f28a8b2
[gaim-migrate @ 17556]
Daniel Atallah <datallah@pidgin.im>
parents:
14842
diff
changeset
|
560 | g_thread_exit(NULL); |
|
d06b1f28a8b2
[gaim-migrate @ 17556]
Daniel Atallah <datallah@pidgin.im>
parents:
14842
diff
changeset
|
561 | return NULL; |
|
d06b1f28a8b2
[gaim-migrate @ 17556]
Daniel Atallah <datallah@pidgin.im>
parents:
14842
diff
changeset
|
562 | } |
|
14784
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
563 | |
|
14842
fe08ba80d369
[gaim-migrate @ 17544]
Daniel Atallah <datallah@pidgin.im>
parents:
14839
diff
changeset
|
564 | /* Make sure at least 30 seconds have elapsed since the last |
|
fe08ba80d369
[gaim-migrate @ 17544]
Daniel Atallah <datallah@pidgin.im>
parents:
14839
diff
changeset
|
565 | * notification so we don't peg the cpu if this keeps changing. */ |
|
fe08ba80d369
[gaim-migrate @ 17544]
Daniel Atallah <datallah@pidgin.im>
parents:
14839
diff
changeset
|
566 | if ((time(NULL) - last_trigger) < 30) |
|
fe08ba80d369
[gaim-migrate @ 17544]
Daniel Atallah <datallah@pidgin.im>
parents:
14839
diff
changeset
|
567 | Sleep(30000); |
|
fe08ba80d369
[gaim-migrate @ 17544]
Daniel Atallah <datallah@pidgin.im>
parents:
14839
diff
changeset
|
568 | |
|
fe08ba80d369
[gaim-migrate @ 17544]
Daniel Atallah <datallah@pidgin.im>
parents:
14839
diff
changeset
|
569 | last_trigger = time(NULL); |
|
fe08ba80d369
[gaim-migrate @ 17544]
Daniel Atallah <datallah@pidgin.im>
parents:
14839
diff
changeset
|
570 | |
|
14784
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
571 | /* This will block until there is a network change */ |
|
14853
d06b1f28a8b2
[gaim-migrate @ 17556]
Daniel Atallah <datallah@pidgin.im>
parents:
14842
diff
changeset
|
572 | if (MyWSANSPIoctl(h, SIO_NSP_NOTIFY_CHANGE, NULL, 0, NULL, 0, &retLen, NULL) == SOCKET_ERROR) { |
|
d06b1f28a8b2
[gaim-migrate @ 17556]
Daniel Atallah <datallah@pidgin.im>
parents:
14842
diff
changeset
|
573 | int errorid = WSAGetLastError(); |
|
d06b1f28a8b2
[gaim-migrate @ 17556]
Daniel Atallah <datallah@pidgin.im>
parents:
14842
diff
changeset
|
574 | gchar *msg = g_win32_error_message(errorid); |
| 15884 | 575 | purple_debug_warning("network", "Unable to wait for changes. Message: %s (%d).\n", |
|
14853
d06b1f28a8b2
[gaim-migrate @ 17556]
Daniel Atallah <datallah@pidgin.im>
parents:
14842
diff
changeset
|
576 | msg, errorid); |
|
d06b1f28a8b2
[gaim-migrate @ 17556]
Daniel Atallah <datallah@pidgin.im>
parents:
14842
diff
changeset
|
577 | g_free(msg); |
|
d06b1f28a8b2
[gaim-migrate @ 17556]
Daniel Atallah <datallah@pidgin.im>
parents:
14842
diff
changeset
|
578 | } |
|
14784
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
579 | |
|
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
580 | retval = WSALookupServiceEnd(h); |
|
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
581 | |
|
21549
7436059db33b
Don't map the port used for bonjour file transfers externally. This adds a new function that will go away in 3.0.0 when we can modify purple_network_do_listen to take an additional parameter.
Daniel Atallah <datallah@pidgin.im>
parents:
21389
diff
changeset
|
582 | purple_timeout_add(0, wpurple_network_change_thread_cb, NULL); |
|
14842
fe08ba80d369
[gaim-migrate @ 17544]
Daniel Atallah <datallah@pidgin.im>
parents:
14839
diff
changeset
|
583 | |
|
14784
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
584 | } |
|
14853
d06b1f28a8b2
[gaim-migrate @ 17556]
Daniel Atallah <datallah@pidgin.im>
parents:
14842
diff
changeset
|
585 | |
|
d06b1f28a8b2
[gaim-migrate @ 17556]
Daniel Atallah <datallah@pidgin.im>
parents:
14842
diff
changeset
|
586 | g_thread_exit(NULL); |
|
d06b1f28a8b2
[gaim-migrate @ 17556]
Daniel Atallah <datallah@pidgin.im>
parents:
14842
diff
changeset
|
587 | return NULL; |
|
14784
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
588 | } |
|
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
589 | #endif |
|
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
590 | |
| 14758 | 591 | gboolean |
| 15884 | 592 | purple_network_is_available(void) |
| 14758 | 593 | { |
| 594 | #ifdef HAVE_LIBNM | |
| 595 | /* Try NetworkManager first, maybe we'll get lucky */ | |
| 596 | int libnm_retval = -1; | |
| 597 | ||
| 598 | if (nm_context) | |
| 599 | { | |
| 600 | if ((libnm_retval = libnm_glib_get_network_state(nm_context)) == LIBNM_NO_NETWORK_CONNECTION) | |
| 601 | { | |
| 15884 | 602 | purple_debug_warning("network", "NetworkManager not active or reports no connection (retval = %i)\n", libnm_retval); |
| 14758 | 603 | return FALSE; |
| 604 | } | |
| 605 | if (libnm_retval == LIBNM_ACTIVE_NETWORK_CONNECTION) return TRUE; | |
| 606 | } | |
|
14839
221c60cc76e0
[gaim-migrate @ 17541]
Daniel Atallah <datallah@pidgin.im>
parents:
14838
diff
changeset
|
607 | #elif defined _WIN32 |
|
14784
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
608 | return (current_network_count > 0); |
| 14758 | 609 | #endif |
| 610 | return TRUE; | |
| 611 | } | |
| 612 | ||
| 613 | #ifdef HAVE_LIBNM | |
| 614 | void | |
| 615 | nm_callback_func(libnm_glib_ctx* ctx, gpointer user_data) | |
| 616 | { | |
| 617 | static libnm_glib_state prev = LIBNM_NO_DBUS; | |
| 618 | libnm_glib_state current; | |
| 15884 | 619 | PurpleConnectionUiOps *ui_ops = purple_connections_get_ui_ops(); |
| 14758 | 620 | |
| 621 | current = libnm_glib_get_network_state(ctx); | |
| 15884 | 622 | purple_debug_info("network","Entering nm_callback_func!\n"); |
| 14758 | 623 | |
|
16035
eb4eda79a147
The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents:
16012
diff
changeset
|
624 | purple_signal_emit(purple_network_get_handle(), "network-configuration-changed", NULL); |
|
eb4eda79a147
The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents:
16012
diff
changeset
|
625 | |
| 14758 | 626 | switch(current) |
| 627 | { | |
| 628 | case LIBNM_ACTIVE_NETWORK_CONNECTION: | |
| 14862 | 629 | /* Call res_init in case DNS servers have changed */ |
| 630 | res_init(); | |
|
14877
084d14fe0445
[gaim-migrate @ 17581]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
14864
diff
changeset
|
631 | if (ui_ops != NULL && ui_ops->network_connected != NULL) |
|
084d14fe0445
[gaim-migrate @ 17581]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
14864
diff
changeset
|
632 | ui_ops->network_connected(); |
| 14758 | 633 | prev = current; |
| 634 | break; | |
| 635 | case LIBNM_NO_NETWORK_CONNECTION: | |
| 636 | if (prev != LIBNM_ACTIVE_NETWORK_CONNECTION) | |
| 637 | break; | |
|
14877
084d14fe0445
[gaim-migrate @ 17581]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
14864
diff
changeset
|
638 | if (ui_ops != NULL && ui_ops->network_disconnected != NULL) |
|
084d14fe0445
[gaim-migrate @ 17581]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
14864
diff
changeset
|
639 | ui_ops->network_disconnected(); |
| 14758 | 640 | prev = current; |
| 641 | break; | |
| 642 | case LIBNM_NO_DBUS: | |
| 643 | case LIBNM_NO_NETWORKMANAGER: | |
| 644 | case LIBNM_INVALID_CONTEXT: | |
| 645 | default: | |
| 646 | break; | |
| 647 | } | |
| 648 | } | |
| 649 | #endif | |
| 650 | ||
|
16035
eb4eda79a147
The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents:
16012
diff
changeset
|
651 | void * |
|
eb4eda79a147
The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents:
16012
diff
changeset
|
652 | purple_network_get_handle(void) |
|
eb4eda79a147
The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents:
16012
diff
changeset
|
653 | { |
|
eb4eda79a147
The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents:
16012
diff
changeset
|
654 | static int handle; |
|
19585
14b519abcc26
Fix some conversion warnings about using negative values with unsigned types. There are more, but these were easy fixes. You may think that I'm changing the API, but I'm really not - it was just wrong.
Daniel Atallah <datallah@pidgin.im>
parents:
18555
diff
changeset
|
655 | |
|
16035
eb4eda79a147
The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents:
16012
diff
changeset
|
656 | return &handle; |
|
eb4eda79a147
The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents:
16012
diff
changeset
|
657 | } |
|
eb4eda79a147
The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents:
16012
diff
changeset
|
658 | |
| 8231 | 659 | void |
| 15884 | 660 | purple_network_init(void) |
| 8231 | 661 | { |
|
14784
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
662 | #ifdef _WIN32 |
|
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
663 | GError *err = NULL; |
| 15884 | 664 | gint cnt = wpurple_get_connected_network_count(); |
|
14842
fe08ba80d369
[gaim-migrate @ 17544]
Daniel Atallah <datallah@pidgin.im>
parents:
14839
diff
changeset
|
665 | |
|
fe08ba80d369
[gaim-migrate @ 17544]
Daniel Atallah <datallah@pidgin.im>
parents:
14839
diff
changeset
|
666 | if (cnt < 0) /* Assume there is a network */ |
|
fe08ba80d369
[gaim-migrate @ 17544]
Daniel Atallah <datallah@pidgin.im>
parents:
14839
diff
changeset
|
667 | current_network_count = 1; |
|
fe08ba80d369
[gaim-migrate @ 17544]
Daniel Atallah <datallah@pidgin.im>
parents:
14839
diff
changeset
|
668 | /* Don't listen for network changes if we can't tell anyway */ |
|
fe08ba80d369
[gaim-migrate @ 17544]
Daniel Atallah <datallah@pidgin.im>
parents:
14839
diff
changeset
|
669 | else |
|
fe08ba80d369
[gaim-migrate @ 17544]
Daniel Atallah <datallah@pidgin.im>
parents:
14839
diff
changeset
|
670 | { |
|
fe08ba80d369
[gaim-migrate @ 17544]
Daniel Atallah <datallah@pidgin.im>
parents:
14839
diff
changeset
|
671 | current_network_count = cnt; |
| 15884 | 672 | if (!g_thread_create(wpurple_network_change_thread, NULL, FALSE, &err)) |
| 673 | purple_debug_error("network", "Couldn't create Network Monitor thread: %s\n", err ? err->message : ""); | |
|
14842
fe08ba80d369
[gaim-migrate @ 17544]
Daniel Atallah <datallah@pidgin.im>
parents:
14839
diff
changeset
|
674 | } |
|
14784
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
675 | #endif |
|
3a82321f46f2
[gaim-migrate @ 17476]
Daniel Atallah <datallah@pidgin.im>
parents:
14758
diff
changeset
|
676 | |
|
16478
19107605c565
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@pidgin.im>
parents:
16035
diff
changeset
|
677 | purple_prefs_add_none ("/purple/network"); |
|
19107605c565
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@pidgin.im>
parents:
16035
diff
changeset
|
678 | purple_prefs_add_bool ("/purple/network/auto_ip", TRUE); |
|
19107605c565
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@pidgin.im>
parents:
16035
diff
changeset
|
679 | purple_prefs_add_string("/purple/network/public_ip", ""); |
|
21810
0b5181178201
Allow UPnP and NAT-PMP port mapping to be disabled via a pref. This means that UPnP discovery will not occur if this new pref and the "Autodetect IP Address" pref are both unchecked. Fixes #4157.
Daniel Atallah <datallah@pidgin.im>
parents:
21549
diff
changeset
|
680 | purple_prefs_add_bool ("/purple/network/map_ports", TRUE); |
|
16478
19107605c565
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@pidgin.im>
parents:
16035
diff
changeset
|
681 | purple_prefs_add_bool ("/purple/network/ports_range_use", FALSE); |
|
19107605c565
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@pidgin.im>
parents:
16035
diff
changeset
|
682 | purple_prefs_add_int ("/purple/network/ports_range_start", 1024); |
|
19107605c565
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@pidgin.im>
parents:
16035
diff
changeset
|
683 | purple_prefs_add_int ("/purple/network/ports_range_end", 2048); |
|
12909
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
684 | |
|
21810
0b5181178201
Allow UPnP and NAT-PMP port mapping to be disabled via a pref. This means that UPnP discovery will not occur if this new pref and the "Autodetect IP Address" pref are both unchecked. Fixes #4157.
Daniel Atallah <datallah@pidgin.im>
parents:
21549
diff
changeset
|
685 | if(purple_prefs_get_bool("/purple/network/map_ports") || purple_prefs_get_bool("/purple/network/auto_ip")) |
|
0b5181178201
Allow UPnP and NAT-PMP port mapping to be disabled via a pref. This means that UPnP discovery will not occur if this new pref and the "Autodetect IP Address" pref are both unchecked. Fixes #4157.
Daniel Atallah <datallah@pidgin.im>
parents:
21549
diff
changeset
|
686 | purple_upnp_discover(NULL, NULL); |
| 14758 | 687 | |
| 688 | #ifdef HAVE_LIBNM | |
| 689 | nm_context = libnm_glib_init(); | |
| 690 | if(nm_context) | |
| 691 | nm_callback_idx = libnm_glib_register_callback(nm_context, nm_callback_func, NULL, g_main_context_default()); | |
| 692 | #endif | |
|
16035
eb4eda79a147
The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents:
16012
diff
changeset
|
693 | |
|
eb4eda79a147
The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents:
16012
diff
changeset
|
694 | purple_signal_register(purple_network_get_handle(), "network-configuration-changed", |
|
eb4eda79a147
The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents:
16012
diff
changeset
|
695 | purple_marshal_VOID, NULL, 0); |
|
19585
14b519abcc26
Fix some conversion warnings about using negative values with unsigned types. There are more, but these were easy fixes. You may think that I'm changing the API, but I'm really not - it was just wrong.
Daniel Atallah <datallah@pidgin.im>
parents:
18555
diff
changeset
|
696 | |
|
16035
eb4eda79a147
The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents:
16012
diff
changeset
|
697 | purple_pmp_init(); |
|
eb4eda79a147
The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents:
16012
diff
changeset
|
698 | purple_upnp_init(); |
| 8231 | 699 | } |
| 14758 | 700 | |
| 701 | void | |
| 15884 | 702 | purple_network_uninit(void) |
| 14758 | 703 | { |
| 704 | #ifdef HAVE_LIBNM | |
| 705 | /* FIXME: If anyone can think of a more clever way to shut down libnm without | |
| 706 | * using a global variable + this function, please do. */ | |
| 707 | if(nm_context && nm_callback_idx) | |
| 708 | libnm_glib_unregister_callback(nm_context, nm_callback_idx); | |
| 709 | ||
| 710 | if(nm_context) | |
| 711 | libnm_glib_shutdown(nm_context); | |
| 712 | #endif | |
|
21143
239b2f43bef5
Make purple_xfers_uninit, purple_network_uninit, and purple_plugins_uninit
Etan Reisner <deryni@pidgin.im>
parents:
20239
diff
changeset
|
713 | |
|
239b2f43bef5
Make purple_xfers_uninit, purple_network_uninit, and purple_plugins_uninit
Etan Reisner <deryni@pidgin.im>
parents:
20239
diff
changeset
|
714 | purple_signal_unregister(purple_network_get_handle(), |
|
239b2f43bef5
Make purple_xfers_uninit, purple_network_uninit, and purple_plugins_uninit
Etan Reisner <deryni@pidgin.im>
parents:
20239
diff
changeset
|
715 | "network-configuration-changed"); |
| 14758 | 716 | } |