Mercurial > pidgin
annotate libgaim/network.c @ 14911:9f3be32d0913
[gaim-migrate @ 17683]
I meant to remove this a revision or three ago
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Mon, 06 Nov 2006 07:52:17 +0000 |
parents | e429c4ebbae5 |
children | f58283ce58ea |
rev | line source |
---|---|
14192 | 1 /** |
2 * @file network.c Network Implementation | |
3 * @ingroup core | |
4 * | |
5 * gaim | |
6 * | |
7 * Gaim is the legal property of its developers, whose names are too numerous | |
8 * to list here. Please refer to the COPYRIGHT file distributed with this | |
9 * source distribution. | |
10 * | |
11 * This program is free software; you can redistribute it and/or modify | |
12 * it under the terms of the GNU General Public License as published by | |
13 * the Free Software Foundation; either version 2 of the License, or | |
14 * (at your option) any later version. | |
15 * | |
16 * This program is distributed in the hope that it will be useful, | |
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 * GNU General Public License for more details. | |
20 * | |
21 * You should have received a copy of the GNU General Public License | |
22 * along with this program; if not, write to the Free Software | |
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
24 */ | |
25 | |
26 #include "internal.h" | |
27 | |
28 #ifndef _WIN32 | |
14802 | 29 #include <resolv.h> |
30 #include <netinet/in.h> | |
31 #include <arpa/nameser.h> | |
14192 | 32 #include <net/if.h> |
33 #include <sys/ioctl.h> | |
14722
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
34 #else |
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
35 #include <nspapi.h> |
14192 | 36 #endif |
37 | |
38 /* Solaris */ | |
39 #if defined (__SVR4) && defined (__sun) | |
40 #include <sys/sockio.h> | |
41 #endif | |
42 | |
43 #include "debug.h" | |
44 #include "account.h" | |
45 #include "network.h" | |
46 #include "prefs.h" | |
47 #include "stun.h" | |
48 #include "upnp.h" | |
49 | |
14696 | 50 #ifdef HAVE_LIBNM |
51 #include <libnm_glib.h> | |
52 | |
53 libnm_glib_ctx *nm_context = NULL; | |
54 guint nm_callback_idx = 0; | |
55 | |
14722
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
56 #elif defined _WIN32 |
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
57 static int current_network_count; |
14696 | 58 #endif |
59 | |
14267 | 60 struct _GaimNetworkListenData { |
14192 | 61 int listenfd; |
62 int socket_type; | |
63 gboolean retry; | |
64 gboolean adding; | |
65 GaimNetworkListenCallback cb; | |
66 gpointer cb_data; | |
14267 | 67 }; |
14192 | 68 |
14696 | 69 #ifdef HAVE_LIBNM |
70 void nm_callback_func(libnm_glib_ctx* ctx, gpointer user_data); | |
71 #endif | |
72 | |
14192 | 73 const unsigned char * |
74 gaim_network_ip_atoi(const char *ip) | |
75 { | |
76 static unsigned char ret[4]; | |
77 gchar *delimiter = "."; | |
78 gchar **split; | |
79 int i; | |
80 | |
81 g_return_val_if_fail(ip != NULL, NULL); | |
82 | |
83 split = g_strsplit(ip, delimiter, 4); | |
84 for (i = 0; split[i] != NULL; i++) | |
85 ret[i] = atoi(split[i]); | |
86 g_strfreev(split); | |
87 | |
88 /* i should always be 4 */ | |
89 if (i != 4) | |
90 return NULL; | |
91 | |
92 return ret; | |
93 } | |
94 | |
95 void | |
96 gaim_network_set_public_ip(const char *ip) | |
97 { | |
98 g_return_if_fail(ip != NULL); | |
99 | |
100 /* XXX - Ensure the IP address is valid */ | |
101 | |
102 gaim_prefs_set_string("/core/network/public_ip", ip); | |
103 } | |
104 | |
105 const char * | |
106 gaim_network_get_public_ip(void) | |
107 { | |
108 return gaim_prefs_get_string("/core/network/public_ip"); | |
109 } | |
110 | |
111 const char * | |
112 gaim_network_get_local_system_ip(int fd) | |
113 { | |
114 char buffer[1024]; | |
115 static char ip[16]; | |
116 char *tmp; | |
117 struct ifconf ifc; | |
118 struct ifreq *ifr; | |
119 struct sockaddr_in *sinptr; | |
120 guint32 lhost = htonl(127 * 256 * 256 * 256 + 1); | |
121 long unsigned int add; | |
122 int source = fd; | |
123 | |
124 if (fd < 0) | |
125 source = socket(PF_INET,SOCK_STREAM, 0); | |
126 | |
127 ifc.ifc_len = sizeof(buffer); | |
128 ifc.ifc_req = (struct ifreq *)buffer; | |
129 ioctl(source, SIOCGIFCONF, &ifc); | |
130 | |
131 if (fd < 0) | |
132 close(source); | |
133 | |
134 tmp = buffer; | |
135 while (tmp < buffer + ifc.ifc_len) | |
136 { | |
137 ifr = (struct ifreq *)tmp; | |
138 tmp += sizeof(struct ifreq); | |
139 | |
140 if (ifr->ifr_addr.sa_family == AF_INET) | |
141 { | |
142 sinptr = (struct sockaddr_in *)&ifr->ifr_addr; | |
143 if (sinptr->sin_addr.s_addr != lhost) | |
144 { | |
145 add = ntohl(sinptr->sin_addr.s_addr); | |
146 g_snprintf(ip, 16, "%lu.%lu.%lu.%lu", | |
147 ((add >> 24) & 255), | |
148 ((add >> 16) & 255), | |
149 ((add >> 8) & 255), | |
150 add & 255); | |
151 | |
152 return ip; | |
153 } | |
154 } | |
155 } | |
156 | |
157 return "0.0.0.0"; | |
158 } | |
159 | |
160 const char * | |
161 gaim_network_get_my_ip(int fd) | |
162 { | |
163 const char *ip = NULL; | |
164 GaimStunNatDiscovery *stun; | |
165 | |
166 /* Check if the user specified an IP manually */ | |
167 if (!gaim_prefs_get_bool("/core/network/auto_ip")) { | |
168 ip = gaim_network_get_public_ip(); | |
169 if ((ip != NULL) && (*ip != '\0')) | |
170 return ip; | |
171 } | |
172 | |
173 /* Check if STUN discovery was already done */ | |
174 stun = gaim_stun_discover(NULL); | |
175 if ((stun != NULL) && (stun->status == GAIM_STUN_STATUS_DISCOVERED)) | |
176 return stun->publicip; | |
177 | |
178 /* Attempt to get the IP from a NAT device using UPnP */ | |
179 ip = gaim_upnp_get_public_ip(); | |
180 if (ip != NULL) | |
181 return ip; | |
182 | |
183 /* Just fetch the IP of the local system */ | |
184 return gaim_network_get_local_system_ip(fd); | |
185 } | |
186 | |
187 | |
188 static void | |
189 gaim_network_set_upnp_port_mapping_cb(gboolean success, gpointer data) | |
190 { | |
14267 | 191 GaimNetworkListenData *listen_data; |
192 | |
193 listen_data = data; | |
194 /* TODO: Once we're keeping track of upnp requests... */ | |
195 /* listen_data->pnp_data = NULL; */ | |
14192 | 196 |
197 if (!success) { | |
198 gaim_debug_info("network", "Couldn't create UPnP mapping\n"); | |
14267 | 199 if (listen_data->retry) { |
200 listen_data->retry = FALSE; | |
201 listen_data->adding = FALSE; | |
202 /* TODO: Need to keep track of this return value! */ | |
14192 | 203 gaim_upnp_remove_port_mapping( |
14267 | 204 gaim_network_get_port_from_fd(listen_data->listenfd), |
205 (listen_data->socket_type == SOCK_STREAM) ? "TCP" : "UDP", | |
206 gaim_network_set_upnp_port_mapping_cb, listen_data); | |
14192 | 207 return; |
208 } | |
14267 | 209 } else if (!listen_data->adding) { |
14192 | 210 /* We've tried successfully to remove the port mapping. |
211 * Try to add it again */ | |
14267 | 212 listen_data->adding = TRUE; |
213 /* TODO: Need to keep track of this return value! */ | |
14192 | 214 gaim_upnp_set_port_mapping( |
14267 | 215 gaim_network_get_port_from_fd(listen_data->listenfd), |
216 (listen_data->socket_type == SOCK_STREAM) ? "TCP" : "UDP", | |
217 gaim_network_set_upnp_port_mapping_cb, listen_data); | |
14192 | 218 return; |
219 } | |
220 | |
14267 | 221 if (listen_data->cb) |
222 listen_data->cb(listen_data->listenfd, listen_data->cb_data); | |
14192 | 223 |
14267 | 224 gaim_network_listen_cancel(listen_data); |
14192 | 225 } |
226 | |
227 | |
14267 | 228 static GaimNetworkListenData * |
14192 | 229 gaim_network_do_listen(unsigned short port, int socket_type, GaimNetworkListenCallback cb, gpointer cb_data) |
230 { | |
231 int listenfd = -1; | |
232 const int on = 1; | |
14267 | 233 GaimNetworkListenData *listen_data; |
14192 | 234 #ifdef HAVE_GETADDRINFO |
235 int errnum; | |
236 struct addrinfo hints, *res, *next; | |
237 char serv[6]; | |
238 | |
239 /* | |
240 * Get a list of addresses on this machine. | |
241 */ | |
242 snprintf(serv, sizeof(serv), "%hu", port); | |
243 memset(&hints, 0, sizeof(struct addrinfo)); | |
244 hints.ai_flags = AI_PASSIVE; | |
245 hints.ai_family = AF_UNSPEC; | |
246 hints.ai_socktype = socket_type; | |
247 errnum = getaddrinfo(NULL /* any IP */, serv, &hints, &res); | |
248 if (errnum != 0) { | |
249 #ifndef _WIN32 | |
250 gaim_debug_warning("network", "getaddrinfo: %s\n", gai_strerror(errnum)); | |
251 if (errnum == EAI_SYSTEM) | |
252 gaim_debug_warning("network", "getaddrinfo: system error: %s\n", strerror(errno)); | |
253 #else | |
254 gaim_debug_warning("network", "getaddrinfo: Error Code = %d\n", errnum); | |
255 #endif | |
14267 | 256 return NULL; |
14192 | 257 } |
258 | |
259 /* | |
260 * Go through the list of addresses and attempt to listen on | |
261 * one of them. | |
262 * XXX - Try IPv6 addresses first? | |
263 */ | |
264 for (next = res; next != NULL; next = next->ai_next) { | |
265 listenfd = socket(next->ai_family, next->ai_socktype, next->ai_protocol); | |
266 if (listenfd < 0) | |
267 continue; | |
268 if (setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) != 0) | |
269 gaim_debug_warning("network", "setsockopt: %s\n", strerror(errno)); | |
270 if (bind(listenfd, next->ai_addr, next->ai_addrlen) == 0) | |
271 break; /* success */ | |
272 /* XXX - It is unclear to me (datallah) whether we need to be | |
273 using a new socket each time */ | |
274 close(listenfd); | |
275 } | |
276 | |
277 freeaddrinfo(res); | |
278 | |
279 if (next == NULL) | |
14267 | 280 return NULL; |
14192 | 281 #else |
282 struct sockaddr_in sockin; | |
283 | |
284 if ((listenfd = socket(AF_INET, socket_type, 0)) < 0) { | |
285 gaim_debug_warning("network", "socket: %s\n", strerror(errno)); | |
14267 | 286 return NULL; |
14192 | 287 } |
288 | |
289 if (setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) != 0) | |
290 gaim_debug_warning("network", "setsockopt: %s\n", strerror(errno)); | |
291 | |
292 memset(&sockin, 0, sizeof(struct sockaddr_in)); | |
293 sockin.sin_family = PF_INET; | |
294 sockin.sin_port = htons(port); | |
295 | |
296 if (bind(listenfd, (struct sockaddr *)&sockin, sizeof(struct sockaddr_in)) != 0) { | |
297 gaim_debug_warning("network", "bind: %s\n", strerror(errno)); | |
298 close(listenfd); | |
14267 | 299 return NULL; |
14192 | 300 } |
301 #endif | |
302 | |
303 if (socket_type == SOCK_STREAM && listen(listenfd, 4) != 0) { | |
304 gaim_debug_warning("network", "listen: %s\n", strerror(errno)); | |
305 close(listenfd); | |
14267 | 306 return NULL; |
14192 | 307 } |
308 fcntl(listenfd, F_SETFL, O_NONBLOCK); | |
309 | |
310 gaim_debug_info("network", "Listening on port: %hu\n", gaim_network_get_port_from_fd(listenfd)); | |
311 | |
14267 | 312 listen_data = g_new0(GaimNetworkListenData, 1); |
313 listen_data->listenfd = listenfd; | |
314 listen_data->adding = TRUE; | |
315 listen_data->retry = TRUE; | |
316 listen_data->cb = cb; | |
317 listen_data->cb_data = cb_data; | |
14192 | 318 |
14267 | 319 /* TODO: Need to keep track of this return value! */ |
14192 | 320 gaim_upnp_set_port_mapping( |
321 gaim_network_get_port_from_fd(listenfd), | |
322 (socket_type == SOCK_STREAM) ? "TCP" : "UDP", | |
14267 | 323 gaim_network_set_upnp_port_mapping_cb, listen_data); |
14192 | 324 |
14267 | 325 return listen_data; |
14192 | 326 } |
327 | |
14267 | 328 GaimNetworkListenData * |
14192 | 329 gaim_network_listen(unsigned short port, int socket_type, |
330 GaimNetworkListenCallback cb, gpointer cb_data) | |
331 { | |
14267 | 332 g_return_val_if_fail(port != 0, NULL); |
14192 | 333 |
334 return gaim_network_do_listen(port, socket_type, cb, cb_data); | |
335 } | |
336 | |
14267 | 337 GaimNetworkListenData * |
14192 | 338 gaim_network_listen_range(unsigned short start, unsigned short end, |
339 int socket_type, GaimNetworkListenCallback cb, gpointer cb_data) | |
340 { | |
14267 | 341 GaimNetworkListenData *ret = NULL; |
14192 | 342 |
343 if (gaim_prefs_get_bool("/core/network/ports_range_use")) { | |
344 start = gaim_prefs_get_int("/core/network/ports_range_start"); | |
345 end = gaim_prefs_get_int("/core/network/ports_range_end"); | |
346 } else { | |
347 if (end < start) | |
348 end = start; | |
349 } | |
350 | |
351 for (; start <= end; start++) { | |
352 ret = gaim_network_do_listen(start, socket_type, cb, cb_data); | |
14267 | 353 if (ret != NULL) |
14192 | 354 break; |
355 } | |
356 | |
357 return ret; | |
358 } | |
359 | |
14267 | 360 void gaim_network_listen_cancel(GaimNetworkListenData *listen_data) |
361 { | |
362 g_free(listen_data); | |
363 } | |
364 | |
14192 | 365 unsigned short |
366 gaim_network_get_port_from_fd(int fd) | |
367 { | |
368 struct sockaddr_in addr; | |
369 socklen_t len; | |
370 | |
371 g_return_val_if_fail(fd >= 0, 0); | |
372 | |
373 len = sizeof(addr); | |
374 if (getsockname(fd, (struct sockaddr *) &addr, &len) == -1) { | |
375 gaim_debug_warning("network", "getsockname: %s\n", strerror(errno)); | |
376 return 0; | |
377 } | |
378 | |
379 return ntohs(addr.sin_port); | |
380 } | |
381 | |
14722
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
382 #ifdef _WIN32 |
14791
2727e465602f
[gaim-migrate @ 17556]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14780
diff
changeset
|
383 #ifndef NS_NLA |
2727e465602f
[gaim-migrate @ 17556]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14780
diff
changeset
|
384 #define NS_NLA 15 |
2727e465602f
[gaim-migrate @ 17556]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14780
diff
changeset
|
385 #endif |
14780
ec9cc2219e55
[gaim-migrate @ 17544]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14777
diff
changeset
|
386 static gint |
14722
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
387 wgaim_get_connected_network_count(void) |
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
388 { |
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
389 guint net_cnt = 0; |
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
390 |
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
391 WSAQUERYSET qs; |
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
392 HANDLE h; |
14895
717ea4589f8d
[gaim-migrate @ 17667]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14815
diff
changeset
|
393 gint retval; |
717ea4589f8d
[gaim-migrate @ 17667]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14815
diff
changeset
|
394 int errorid; |
14722
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
395 |
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
396 memset(&qs, 0, sizeof(WSAQUERYSET)); |
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
397 qs.dwSize = sizeof(WSAQUERYSET); |
14791
2727e465602f
[gaim-migrate @ 17556]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14780
diff
changeset
|
398 qs.dwNameSpace = NS_NLA; |
14722
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
399 |
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
400 retval = WSALookupServiceBegin(&qs, LUP_RETURN_ALL, &h); |
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
401 if (retval != ERROR_SUCCESS) { |
14895
717ea4589f8d
[gaim-migrate @ 17667]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14815
diff
changeset
|
402 gchar *msg; |
717ea4589f8d
[gaim-migrate @ 17667]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14815
diff
changeset
|
403 errorid = WSAGetLastError(); |
717ea4589f8d
[gaim-migrate @ 17667]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14815
diff
changeset
|
404 msg = g_win32_error_message(errorid); |
14791
2727e465602f
[gaim-migrate @ 17556]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14780
diff
changeset
|
405 gaim_debug_warning("network", "Couldn't retrieve NLA SP lookup handle. " |
2727e465602f
[gaim-migrate @ 17556]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14780
diff
changeset
|
406 "NLA service is probably not running. Message: %s (%d).\n", |
2727e465602f
[gaim-migrate @ 17556]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14780
diff
changeset
|
407 msg, errorid); |
14722
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
408 g_free(msg); |
14776
a87c53e7b1e2
[gaim-migrate @ 17540]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14722
diff
changeset
|
409 |
14780
ec9cc2219e55
[gaim-migrate @ 17544]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14777
diff
changeset
|
410 return -1; |
14722
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
411 } else { |
14897
e429c4ebbae5
[gaim-migrate @ 17669]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14895
diff
changeset
|
412 char buf[4096]; |
14722
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
413 WSAQUERYSET *res = (LPWSAQUERYSET) buf; |
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
414 DWORD size = sizeof(buf); |
14895
717ea4589f8d
[gaim-migrate @ 17667]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14815
diff
changeset
|
415 while ((retval = WSALookupServiceNext(h, 0, &size, res)) == ERROR_SUCCESS) { |
14722
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
416 net_cnt++; |
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
417 gaim_debug_info("network", "found network '%s'\n", |
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
418 res->lpszServiceInstanceName ? res->lpszServiceInstanceName : "(NULL)"); |
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
419 size = sizeof(buf); |
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
420 } |
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
421 |
14895
717ea4589f8d
[gaim-migrate @ 17667]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14815
diff
changeset
|
422 errorid = WSAGetLastError(); |
717ea4589f8d
[gaim-migrate @ 17667]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14815
diff
changeset
|
423 if (!(errorid == WSA_E_NO_MORE || errorid == WSAENOMORE)) { |
717ea4589f8d
[gaim-migrate @ 17667]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14815
diff
changeset
|
424 gchar *msg = g_win32_error_message(errorid); |
717ea4589f8d
[gaim-migrate @ 17667]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14815
diff
changeset
|
425 gaim_debug_error("network", "got unexpected NLA response %s (%d)\n", msg, errorid); |
717ea4589f8d
[gaim-migrate @ 17667]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14815
diff
changeset
|
426 g_free(msg); |
717ea4589f8d
[gaim-migrate @ 17667]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14815
diff
changeset
|
427 |
717ea4589f8d
[gaim-migrate @ 17667]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14815
diff
changeset
|
428 net_cnt = -1; |
717ea4589f8d
[gaim-migrate @ 17667]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14815
diff
changeset
|
429 } |
717ea4589f8d
[gaim-migrate @ 17667]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14815
diff
changeset
|
430 |
717ea4589f8d
[gaim-migrate @ 17667]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14815
diff
changeset
|
431 retval = WSALookupServiceEnd(h); |
14722
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
432 } |
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
433 |
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
434 return net_cnt; |
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
435 |
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
436 } |
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
437 |
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
438 static gboolean wgaim_network_change_thread_cb(gpointer data) |
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
439 { |
14780
ec9cc2219e55
[gaim-migrate @ 17544]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14777
diff
changeset
|
440 gint new_count; |
14722
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
441 GaimConnectionUiOps *ui_ops = gaim_connections_get_ui_ops(); |
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
442 |
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
443 new_count = wgaim_get_connected_network_count(); |
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
444 |
14780
ec9cc2219e55
[gaim-migrate @ 17544]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14777
diff
changeset
|
445 if (new_count < 0) |
ec9cc2219e55
[gaim-migrate @ 17544]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14777
diff
changeset
|
446 return FALSE; |
ec9cc2219e55
[gaim-migrate @ 17544]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14777
diff
changeset
|
447 |
14722
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
448 gaim_debug_info("network", "Received Network Change Notification. Current network count is %d, previous count was %d.\n", new_count, current_network_count); |
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
449 |
14815 | 450 if (new_count > 0 && ui_ops != NULL && ui_ops->network_connected != NULL) { |
14722
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
451 ui_ops->network_connected(); |
14815 | 452 } else if (new_count == 0 && current_network_count > 0 && |
453 ui_ops != NULL && ui_ops->network_disconnected != NULL) { | |
14722
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
454 ui_ops->network_disconnected(); |
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
455 } |
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
456 |
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
457 current_network_count = new_count; |
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
458 |
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
459 return FALSE; |
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
460 } |
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
461 |
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
462 static gpointer wgaim_network_change_thread(gpointer data) |
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
463 { |
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
464 HANDLE h; |
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
465 WSAQUERYSET qs; |
14780
ec9cc2219e55
[gaim-migrate @ 17544]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14777
diff
changeset
|
466 time_t last_trigger = time(NULL); |
14722
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
467 |
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
468 int WSAAPI (*MyWSANSPIoctl) ( |
14791
2727e465602f
[gaim-migrate @ 17556]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14780
diff
changeset
|
469 HANDLE hLookup, DWORD dwControlCode, LPVOID lpvInBuffer, |
2727e465602f
[gaim-migrate @ 17556]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14780
diff
changeset
|
470 DWORD cbInBuffer, LPVOID lpvOutBuffer, DWORD cbOutBuffer, |
2727e465602f
[gaim-migrate @ 17556]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14780
diff
changeset
|
471 LPDWORD lpcbBytesReturned, LPWSACOMPLETION lpCompletion) = NULL; |
14722
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
472 |
14791
2727e465602f
[gaim-migrate @ 17556]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14780
diff
changeset
|
473 if (!(MyWSANSPIoctl = (void*) wgaim_find_and_loadproc("ws2_32.dll", "WSANSPIoctl"))) { |
14722
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
474 g_thread_exit(NULL); |
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
475 return NULL; |
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
476 } |
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
477 |
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
478 while (TRUE) { |
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
479 int retval; |
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
480 DWORD retLen = 0; |
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
481 |
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
482 memset(&qs, 0, sizeof(WSAQUERYSET)); |
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
483 qs.dwSize = sizeof(WSAQUERYSET); |
14791
2727e465602f
[gaim-migrate @ 17556]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14780
diff
changeset
|
484 qs.dwNameSpace = NS_NLA; |
2727e465602f
[gaim-migrate @ 17556]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14780
diff
changeset
|
485 if (WSALookupServiceBegin(&qs, 0, &h) == SOCKET_ERROR) { |
2727e465602f
[gaim-migrate @ 17556]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14780
diff
changeset
|
486 int errorid = WSAGetLastError(); |
2727e465602f
[gaim-migrate @ 17556]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14780
diff
changeset
|
487 gchar *msg = g_win32_error_message(errorid); |
2727e465602f
[gaim-migrate @ 17556]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14780
diff
changeset
|
488 gaim_debug_warning("network", "Couldn't retrieve NLA SP lookup handle. " |
2727e465602f
[gaim-migrate @ 17556]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14780
diff
changeset
|
489 "NLA service is probably not running. Message: %s (%d).\n", |
2727e465602f
[gaim-migrate @ 17556]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14780
diff
changeset
|
490 msg, errorid); |
2727e465602f
[gaim-migrate @ 17556]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14780
diff
changeset
|
491 g_free(msg); |
2727e465602f
[gaim-migrate @ 17556]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14780
diff
changeset
|
492 g_thread_exit(NULL); |
2727e465602f
[gaim-migrate @ 17556]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14780
diff
changeset
|
493 return NULL; |
2727e465602f
[gaim-migrate @ 17556]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14780
diff
changeset
|
494 } |
14722
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
495 |
14780
ec9cc2219e55
[gaim-migrate @ 17544]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14777
diff
changeset
|
496 /* Make sure at least 30 seconds have elapsed since the last |
ec9cc2219e55
[gaim-migrate @ 17544]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14777
diff
changeset
|
497 * notification so we don't peg the cpu if this keeps changing. */ |
ec9cc2219e55
[gaim-migrate @ 17544]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14777
diff
changeset
|
498 if ((time(NULL) - last_trigger) < 30) |
ec9cc2219e55
[gaim-migrate @ 17544]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14777
diff
changeset
|
499 Sleep(30000); |
ec9cc2219e55
[gaim-migrate @ 17544]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14777
diff
changeset
|
500 |
ec9cc2219e55
[gaim-migrate @ 17544]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14777
diff
changeset
|
501 last_trigger = time(NULL); |
ec9cc2219e55
[gaim-migrate @ 17544]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14777
diff
changeset
|
502 |
14722
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
503 /* This will block until there is a network change */ |
14791
2727e465602f
[gaim-migrate @ 17556]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14780
diff
changeset
|
504 if (MyWSANSPIoctl(h, SIO_NSP_NOTIFY_CHANGE, NULL, 0, NULL, 0, &retLen, NULL) == SOCKET_ERROR) { |
2727e465602f
[gaim-migrate @ 17556]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14780
diff
changeset
|
505 int errorid = WSAGetLastError(); |
2727e465602f
[gaim-migrate @ 17556]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14780
diff
changeset
|
506 gchar *msg = g_win32_error_message(errorid); |
2727e465602f
[gaim-migrate @ 17556]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14780
diff
changeset
|
507 gaim_debug_warning("network", "Unable to wait for changes. Message: %s (%d).\n", |
2727e465602f
[gaim-migrate @ 17556]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14780
diff
changeset
|
508 msg, errorid); |
2727e465602f
[gaim-migrate @ 17556]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14780
diff
changeset
|
509 g_free(msg); |
2727e465602f
[gaim-migrate @ 17556]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14780
diff
changeset
|
510 } |
14722
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
511 |
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
512 retval = WSALookupServiceEnd(h); |
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
513 |
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
514 g_idle_add(wgaim_network_change_thread_cb, NULL); |
14780
ec9cc2219e55
[gaim-migrate @ 17544]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14777
diff
changeset
|
515 |
14722
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
516 } |
14791
2727e465602f
[gaim-migrate @ 17556]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14780
diff
changeset
|
517 |
2727e465602f
[gaim-migrate @ 17556]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14780
diff
changeset
|
518 g_thread_exit(NULL); |
2727e465602f
[gaim-migrate @ 17556]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14780
diff
changeset
|
519 return NULL; |
14722
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
520 } |
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
521 #endif |
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
522 |
14696 | 523 gboolean |
524 gaim_network_is_available(void) | |
525 { | |
526 #ifdef HAVE_LIBNM | |
527 /* Try NetworkManager first, maybe we'll get lucky */ | |
528 int libnm_retval = -1; | |
529 | |
530 if (nm_context) | |
531 { | |
532 if ((libnm_retval = libnm_glib_get_network_state(nm_context)) == LIBNM_NO_NETWORK_CONNECTION) | |
533 { | |
534 gaim_debug_warning("network", "NetworkManager not active or reports no connection (retval = %i)\n", libnm_retval); | |
535 return FALSE; | |
536 } | |
537 if (libnm_retval == LIBNM_ACTIVE_NETWORK_CONNECTION) return TRUE; | |
538 } | |
14777
182f77347680
[gaim-migrate @ 17541]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14776
diff
changeset
|
539 #elif defined _WIN32 |
14722
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
540 return (current_network_count > 0); |
14696 | 541 #endif |
542 return TRUE; | |
543 } | |
544 | |
545 #ifdef HAVE_LIBNM | |
546 void | |
547 nm_callback_func(libnm_glib_ctx* ctx, gpointer user_data) | |
548 { | |
549 GList *l; | |
550 GaimAccount *account; | |
551 static libnm_glib_state prev = LIBNM_NO_DBUS; | |
552 libnm_glib_state current; | |
553 GaimConnectionUiOps *ui_ops = gaim_connections_get_ui_ops(); | |
554 | |
555 current = libnm_glib_get_network_state(ctx); | |
556 gaim_debug_info("network","Entering nm_callback_func!\n"); | |
557 | |
558 switch(current) | |
559 { | |
560 case LIBNM_ACTIVE_NETWORK_CONNECTION: | |
14800 | 561 /* Call res_init in case DNS servers have changed */ |
562 res_init(); | |
14815 | 563 if (ui_ops != NULL && ui_ops->network_connected != NULL) |
564 ui_ops->network_connected(); | |
14696 | 565 prev = current; |
566 break; | |
567 case LIBNM_NO_NETWORK_CONNECTION: | |
568 if (prev != LIBNM_ACTIVE_NETWORK_CONNECTION) | |
569 break; | |
14815 | 570 if (ui_ops != NULL && ui_ops->network_disconnected != NULL) |
571 ui_ops->network_disconnected(); | |
14696 | 572 prev = current; |
573 break; | |
574 case LIBNM_NO_DBUS: | |
575 case LIBNM_NO_NETWORKMANAGER: | |
576 case LIBNM_INVALID_CONTEXT: | |
577 default: | |
578 break; | |
579 } | |
580 } | |
581 #endif | |
582 | |
14192 | 583 void |
584 gaim_network_init(void) | |
585 { | |
14722
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
586 #ifdef _WIN32 |
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
587 GError *err = NULL; |
14780
ec9cc2219e55
[gaim-migrate @ 17544]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14777
diff
changeset
|
588 gint cnt = wgaim_get_connected_network_count(); |
ec9cc2219e55
[gaim-migrate @ 17544]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14777
diff
changeset
|
589 |
ec9cc2219e55
[gaim-migrate @ 17544]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14777
diff
changeset
|
590 if (cnt < 0) /* Assume there is a network */ |
ec9cc2219e55
[gaim-migrate @ 17544]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14777
diff
changeset
|
591 current_network_count = 1; |
ec9cc2219e55
[gaim-migrate @ 17544]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14777
diff
changeset
|
592 /* Don't listen for network changes if we can't tell anyway */ |
ec9cc2219e55
[gaim-migrate @ 17544]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14777
diff
changeset
|
593 else |
ec9cc2219e55
[gaim-migrate @ 17544]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14777
diff
changeset
|
594 { |
ec9cc2219e55
[gaim-migrate @ 17544]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14777
diff
changeset
|
595 current_network_count = cnt; |
ec9cc2219e55
[gaim-migrate @ 17544]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14777
diff
changeset
|
596 if (!g_thread_create(wgaim_network_change_thread, NULL, FALSE, &err)) |
ec9cc2219e55
[gaim-migrate @ 17544]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14777
diff
changeset
|
597 gaim_debug_error("network", "Couldn't create Network Monitor thread: %s\n", err ? err->message : ""); |
ec9cc2219e55
[gaim-migrate @ 17544]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14777
diff
changeset
|
598 } |
14722
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
599 #endif |
51685370de57
[gaim-migrate @ 17476]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14696
diff
changeset
|
600 |
14192 | 601 gaim_prefs_add_none ("/core/network"); |
602 gaim_prefs_add_bool ("/core/network/auto_ip", TRUE); | |
603 gaim_prefs_add_string("/core/network/public_ip", ""); | |
604 gaim_prefs_add_bool ("/core/network/ports_range_use", FALSE); | |
605 gaim_prefs_add_int ("/core/network/ports_range_start", 1024); | |
606 gaim_prefs_add_int ("/core/network/ports_range_end", 2048); | |
607 | |
608 gaim_upnp_discover(NULL, NULL); | |
14696 | 609 |
610 #ifdef HAVE_LIBNM | |
611 nm_context = libnm_glib_init(); | |
612 if(nm_context) | |
613 nm_callback_idx = libnm_glib_register_callback(nm_context, nm_callback_func, NULL, g_main_context_default()); | |
614 #endif | |
14192 | 615 } |
14696 | 616 |
617 void | |
618 gaim_network_uninit(void) | |
619 { | |
620 #ifdef HAVE_LIBNM | |
621 /* FIXME: If anyone can think of a more clever way to shut down libnm without | |
622 * using a global variable + this function, please do. */ | |
623 if(nm_context && nm_callback_idx) | |
624 libnm_glib_unregister_callback(nm_context, nm_callback_idx); | |
625 | |
626 if(nm_context) | |
627 libnm_glib_shutdown(nm_context); | |
628 #endif | |
629 } |