annotate libgaim/network.c @ 14769:61aa08fcd315

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