annotate src/stun.c @ 13685:039cc76492b0

[gaim-migrate @ 16088] SF Patch #1474731 from Casey Harkins "This patch increases the time (from 3 sec to 5 sec) that gaim waits for a message from the notification area that the docklet icon was created successfully. It should fix bug #1466092." 5 seconds doesn't seem too bad and it should help people with slower systems. committer: Tailor Script <tailor@pidgin.im>
author Richard Laager <rlaager@wiktel.com>
date Mon, 24 Apr 2006 20:05:48 +0000
parents 8e3b85fe4a55
children c3167a1dd817
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11225
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
1 /**
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
2 * @file stun.c STUN (RFC3489) Implementation
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
3 * @ingroup core
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
4 *
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
5 * gaim
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
6 *
11336
7d7dd22215ec [gaim-migrate @ 13549]
Thomas Butter <tbutter>
parents: 11300
diff changeset
7 * STUN implementation inspired by jstun [http://jstun.javawi.de/]
7d7dd22215ec [gaim-migrate @ 13549]
Thomas Butter <tbutter>
parents: 11300
diff changeset
8 *
11225
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
9 * Gaim is the legal property of its developers, whose names are too numerous
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
10 * to list here. Please refer to the COPYRIGHT file distributed with this
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
11 * source distribution.
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
12 *
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
13 * This program is free software; you can redistribute it and/or modify
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
14 * it under the terms of the GNU General Public License as published by
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
15 * the Free Software Foundation; either version 2 of the License, or
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
16 * (at your option) any later version.
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
17 *
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
18 * This program is distributed in the hope that it will be useful,
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
21 * GNU General Public License for more details.
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
22 *
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
23 * You should have received a copy of the GNU General Public License
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
24 * along with this program; if not, write to the Free Software
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
26 *
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
27 */
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
28
11898
8d019c4bf454 [gaim-migrate @ 14189]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11677
diff changeset
29 #include "internal.h"
8d019c4bf454 [gaim-migrate @ 14189]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11677
diff changeset
30
11364
e1840eb860e7 [gaim-migrate @ 13588]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11354
diff changeset
31 #ifndef _WIN32
11225
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
32 #include <net/if.h>
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
33 #include <sys/ioctl.h>
11364
e1840eb860e7 [gaim-migrate @ 13588]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11354
diff changeset
34 #endif
11225
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
35
12700
cf0d9e207cdc [gaim-migrate @ 15043]
Richard Laager <rlaager@wiktel.com>
parents: 12686
diff changeset
36 /* Solaris */
cf0d9e207cdc [gaim-migrate @ 15043]
Richard Laager <rlaager@wiktel.com>
parents: 12686
diff changeset
37 #if defined (__SVR4) && defined (__sun)
cf0d9e207cdc [gaim-migrate @ 15043]
Richard Laager <rlaager@wiktel.com>
parents: 12686
diff changeset
38 #include <sys/sockio.h>
cf0d9e207cdc [gaim-migrate @ 15043]
Richard Laager <rlaager@wiktel.com>
parents: 12686
diff changeset
39 #endif
cf0d9e207cdc [gaim-migrate @ 15043]
Richard Laager <rlaager@wiktel.com>
parents: 12686
diff changeset
40
11225
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
41 #include "debug.h"
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
42 #include "account.h"
11424
e1ab173ef3b5 [gaim-migrate @ 13661]
Thomas Butter <tbutter>
parents: 11371
diff changeset
43 #include "dnssrv.h"
12756
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
44 #include "network.h"
11429
835dbb1b3337 [gaim-migrate @ 13666]
Thomas Butter <tbutter>
parents: 11425
diff changeset
45 #include "proxy.h"
11225
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
46 #include "stun.h"
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
47 #include "prefs.h"
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
48
12756
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
49 #define MSGTYPE_BINDINGREQUEST 0x0001
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
50 #define MSGTYPE_BINDINGRESPONSE 0x0101
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
51
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
52 #define ATTRIB_MAPPEDADDRESS 0x0001
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
53
12686
5f65a0cca87c [gaim-migrate @ 15029]
Richard Laager <rlaager@wiktel.com>
parents: 11898
diff changeset
54 struct stun_header {
12756
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
55 guint16 type;
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
56 guint16 len;
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
57 guint32 transid[4];
12686
5f65a0cca87c [gaim-migrate @ 15029]
Richard Laager <rlaager@wiktel.com>
parents: 11898
diff changeset
58 };
5f65a0cca87c [gaim-migrate @ 15029]
Richard Laager <rlaager@wiktel.com>
parents: 11898
diff changeset
59
5f65a0cca87c [gaim-migrate @ 15029]
Richard Laager <rlaager@wiktel.com>
parents: 11898
diff changeset
60 struct stun_attrib {
12756
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
61 guint16 type;
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
62 guint16 len;
12686
5f65a0cca87c [gaim-migrate @ 15029]
Richard Laager <rlaager@wiktel.com>
parents: 11898
diff changeset
63 };
5f65a0cca87c [gaim-migrate @ 15029]
Richard Laager <rlaager@wiktel.com>
parents: 11898
diff changeset
64
12756
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
65 #ifdef NOTYET
12686
5f65a0cca87c [gaim-migrate @ 15029]
Richard Laager <rlaager@wiktel.com>
parents: 11898
diff changeset
66 struct stun_change {
5f65a0cca87c [gaim-migrate @ 15029]
Richard Laager <rlaager@wiktel.com>
parents: 11898
diff changeset
67 struct stun_header hdr;
5f65a0cca87c [gaim-migrate @ 15029]
Richard Laager <rlaager@wiktel.com>
parents: 11898
diff changeset
68 struct stun_attrib attrib;
5f65a0cca87c [gaim-migrate @ 15029]
Richard Laager <rlaager@wiktel.com>
parents: 11898
diff changeset
69 char value[4];
5f65a0cca87c [gaim-migrate @ 15029]
Richard Laager <rlaager@wiktel.com>
parents: 11898
diff changeset
70 };
12756
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
71 #endif
12686
5f65a0cca87c [gaim-migrate @ 15029]
Richard Laager <rlaager@wiktel.com>
parents: 11898
diff changeset
72
12756
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
73 struct stun_conn {
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
74 int fd;
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
75 struct sockaddr_in addr;
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
76 int test;
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
77 int retry;
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
78 guint incb;
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
79 guint timeout;
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
80 struct stun_header *packet;
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
81 size_t packetsize;
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
82 };
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
83
12877
a7bf698eb37c [gaim-migrate @ 15229]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12757
diff changeset
84 static GaimStunNatDiscovery nattype = {
a7bf698eb37c [gaim-migrate @ 15229]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12757
diff changeset
85 GAIM_STUN_STATUS_UNDISCOVERED,
a7bf698eb37c [gaim-migrate @ 15229]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12757
diff changeset
86 GAIM_STUN_NAT_TYPE_PUBLIC_IP,
a7bf698eb37c [gaim-migrate @ 15229]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12757
diff changeset
87 "\0", NULL, 0};
11225
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
88
12877
a7bf698eb37c [gaim-migrate @ 15229]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12757
diff changeset
89 static GSList *callbacks = NULL;
12756
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
90
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
91 static void close_stun_conn(struct stun_conn *sc) {
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
92
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
93 if (sc->incb)
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
94 gaim_input_remove(sc->incb);
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
95
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
96 if (sc->timeout)
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
97 gaim_timeout_remove(sc->timeout);
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
98
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
99 if (sc->fd)
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
100 close(sc->fd);
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
101
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
102 g_free(sc);
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
103 }
11225
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
104
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
105 static void do_callbacks() {
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
106 while(callbacks) {
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
107 StunCallback cb = callbacks->data;
11336
7d7dd22215ec [gaim-migrate @ 13549]
Thomas Butter <tbutter>
parents: 11300
diff changeset
108 if(cb)
7d7dd22215ec [gaim-migrate @ 13549]
Thomas Butter <tbutter>
parents: 11300
diff changeset
109 cb(&nattype);
11225
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
110 callbacks = g_slist_remove(callbacks, cb);
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
111 }
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
112 }
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
113
12756
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
114 static gboolean timeoutfunc(gpointer data) {
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
115 struct stun_conn *sc = data;
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
116 if(sc->retry >= 2) {
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
117 gaim_debug_info("stun", "request timed out, giving up.\n");
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
118 if(sc->test == 2)
12686
5f65a0cca87c [gaim-migrate @ 15029]
Richard Laager <rlaager@wiktel.com>
parents: 11898
diff changeset
119 nattype.type = GAIM_STUN_NAT_TYPE_SYMMETRIC;
5f65a0cca87c [gaim-migrate @ 15029]
Richard Laager <rlaager@wiktel.com>
parents: 11898
diff changeset
120
11354
97028c1c69e9 [gaim-migrate @ 13573]
Thomas Butter <tbutter>
parents: 11336
diff changeset
121 /* set unknown */
12686
5f65a0cca87c [gaim-migrate @ 15029]
Richard Laager <rlaager@wiktel.com>
parents: 11898
diff changeset
122 nattype.status = GAIM_STUN_STATUS_UNKNOWN;
11354
97028c1c69e9 [gaim-migrate @ 13573]
Thomas Butter <tbutter>
parents: 11336
diff changeset
123
12756
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
124 nattype.lookup_time = time(NULL);
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
125
11354
97028c1c69e9 [gaim-migrate @ 13573]
Thomas Butter <tbutter>
parents: 11336
diff changeset
126 /* callbacks */
97028c1c69e9 [gaim-migrate @ 13573]
Thomas Butter <tbutter>
parents: 11336
diff changeset
127 do_callbacks();
97028c1c69e9 [gaim-migrate @ 13573]
Thomas Butter <tbutter>
parents: 11336
diff changeset
128
12756
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
129 /* we don't need to remove the timeout (returning FALSE) */
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
130 sc->timeout = 0;
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
131 close_stun_conn(sc);
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
132
11354
97028c1c69e9 [gaim-migrate @ 13573]
Thomas Butter <tbutter>
parents: 11336
diff changeset
133 return FALSE;
97028c1c69e9 [gaim-migrate @ 13573]
Thomas Butter <tbutter>
parents: 11336
diff changeset
134 }
12756
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
135 gaim_debug_info("stun", "request timed out, retrying.\n");
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
136 sc->retry++;
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
137 sendto(sc->fd, sc->packet, sc->packetsize, 0,
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
138 (struct sockaddr *)&(sc->addr), sizeof(struct sockaddr_in));
11354
97028c1c69e9 [gaim-migrate @ 13573]
Thomas Butter <tbutter>
parents: 11336
diff changeset
139 return TRUE;
97028c1c69e9 [gaim-migrate @ 13573]
Thomas Butter <tbutter>
parents: 11336
diff changeset
140 }
97028c1c69e9 [gaim-migrate @ 13573]
Thomas Butter <tbutter>
parents: 11336
diff changeset
141
97028c1c69e9 [gaim-migrate @ 13573]
Thomas Butter <tbutter>
parents: 11336
diff changeset
142 #ifdef NOTYET
12756
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
143 static void do_test2(struct stun_conn *sc) {
11354
97028c1c69e9 [gaim-migrate @ 13573]
Thomas Butter <tbutter>
parents: 11336
diff changeset
144 struct stun_change data;
11431
d2e44c8085e0 [gaim-migrate @ 13668]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11429
diff changeset
145 data.hdr.type = htons(0x0001);
d2e44c8085e0 [gaim-migrate @ 13668]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11429
diff changeset
146 data.hdr.len = 0;
d2e44c8085e0 [gaim-migrate @ 13668]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11429
diff changeset
147 data.hdr.transid[0] = rand();
d2e44c8085e0 [gaim-migrate @ 13668]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11429
diff changeset
148 data.hdr.transid[1] = ntohl(((int)'g' << 24) + ((int)'a' << 16) + ((int)'i' << 8) + (int)'m');
d2e44c8085e0 [gaim-migrate @ 13668]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11429
diff changeset
149 data.hdr.transid[2] = rand();
d2e44c8085e0 [gaim-migrate @ 13668]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11429
diff changeset
150 data.hdr.transid[3] = rand();
d2e44c8085e0 [gaim-migrate @ 13668]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11429
diff changeset
151 data.attrib.type = htons(0x003);
11354
97028c1c69e9 [gaim-migrate @ 13573]
Thomas Butter <tbutter>
parents: 11336
diff changeset
152 data.attrib.len = htons(4);
97028c1c69e9 [gaim-migrate @ 13573]
Thomas Butter <tbutter>
parents: 11336
diff changeset
153 data.value[3] = 6;
12756
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
154 sc->packet = (struct stun_header*)&data;
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
155 sc->packetsize = sizeof(struct stun_change);
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
156 sc->retry = 0;
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
157 sc->test = 2;
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
158 sendto(sc->fd, sc->packet, sc->packetsize, 0, (struct sockaddr *)&(sc->addr), sizeof(struct sockaddr_in));
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
159 sc->timeout = gaim_timeout_add(500, (GSourceFunc) timeoutfunc, sc);
11354
97028c1c69e9 [gaim-migrate @ 13573]
Thomas Butter <tbutter>
parents: 11336
diff changeset
160 }
97028c1c69e9 [gaim-migrate @ 13573]
Thomas Butter <tbutter>
parents: 11336
diff changeset
161 #endif
97028c1c69e9 [gaim-migrate @ 13573]
Thomas Butter <tbutter>
parents: 11336
diff changeset
162
11225
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
163 static void reply_cb(gpointer data, gint source, GaimInputCondition cond) {
12756
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
164 struct stun_conn *sc = data;
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
165 char buffer[65536];
11225
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
166 char *tmp;
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
167 int len;
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
168 struct in_addr in;
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
169 struct stun_attrib *attrib;
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
170 struct stun_header *hdr;
11300
dd1a5969b2e5 [gaim-migrate @ 13500]
Richard Laager <rlaager@wiktel.com>
parents: 11229
diff changeset
171 struct ifconf ifc;
dd1a5969b2e5 [gaim-migrate @ 13500]
Richard Laager <rlaager@wiktel.com>
parents: 11229
diff changeset
172 struct ifreq *ifr;
dd1a5969b2e5 [gaim-migrate @ 13500]
Richard Laager <rlaager@wiktel.com>
parents: 11229
diff changeset
173 struct sockaddr_in *sinptr;
11431
d2e44c8085e0 [gaim-migrate @ 13668]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11429
diff changeset
174
12756
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
175 len = recv(source, buffer, sizeof(buffer) - 1, 0);
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
176 if (!len) {
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
177 gaim_debug_info("stun", "unable to read stun response\n");
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
178 return;
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
179 }
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
180 buffer[len] = '\0';
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
181
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
182 if (len < sizeof(struct stun_header)) {
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
183 gaim_debug_info("stun", "got invalid response\n");
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
184 return;
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
185 }
11225
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
186
12756
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
187 hdr = (struct stun_header*) buffer;
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
188 if (len != (ntohs(hdr->len) + sizeof(struct stun_header))) {
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
189 gaim_debug_info("stun", "got incomplete response\n");
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
190 return;
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
191 }
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
192
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
193 /* wrong transaction */
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
194 if(hdr->transid[0] != sc->packet->transid[0]
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
195 || hdr->transid[1] != sc->packet->transid[1]
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
196 || hdr->transid[2] != sc->packet->transid[2]
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
197 || hdr->transid[3] != sc->packet->transid[3]) {
11371
6e02e20e3a58 [gaim-migrate @ 13596]
Richard Laager <rlaager@wiktel.com>
parents: 11364
diff changeset
198 gaim_debug_info("stun", "got wrong transid\n");
11225
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
199 return;
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
200 }
12756
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
201
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
202 if(sc->test==1) {
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
203 if (hdr->type != MSGTYPE_BINDINGRESPONSE) {
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
204 gaim_debug_info("stun",
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
205 "Expected Binding Response, got %d\n",
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
206 hdr->type);
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
207 return;
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
208 }
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
209
11354
97028c1c69e9 [gaim-migrate @ 13573]
Thomas Butter <tbutter>
parents: 11336
diff changeset
210 tmp = buffer + sizeof(struct stun_header);
12756
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
211 while((buffer + len) > (tmp + sizeof(struct stun_attrib))) {
11354
97028c1c69e9 [gaim-migrate @ 13573]
Thomas Butter <tbutter>
parents: 11336
diff changeset
212 attrib = (struct stun_attrib*) tmp;
12756
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
213 tmp += sizeof(struct stun_attrib);
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
214
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
215 if (!((buffer + len) > (tmp + ntohs(attrib->len))))
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
216 break;
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
217
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
218 if(attrib->type == htons(ATTRIB_MAPPEDADDRESS)
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
219 && ntohs(attrib->len) == 8) {
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
220 char *ip;
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
221 /* Skip the first unused byte,
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
222 * the family(1 byte), and the port(2 bytes);
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
223 * then read the 4 byte IPv4 address */
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
224 memcpy(&in.s_addr, tmp + 4, 4);
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
225 ip = inet_ntoa(in);
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
226 if(ip)
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
227 strcpy(nattype.publicip, ip);
11354
97028c1c69e9 [gaim-migrate @ 13573]
Thomas Butter <tbutter>
parents: 11336
diff changeset
228 }
12756
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
229
12757
e2f1f49fad1a [gaim-migrate @ 15104]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12756
diff changeset
230 tmp += ntohs(attrib->len);
11225
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
231 }
11371
6e02e20e3a58 [gaim-migrate @ 13596]
Richard Laager <rlaager@wiktel.com>
parents: 11364
diff changeset
232 gaim_debug_info("stun", "got public ip %s\n", nattype.publicip);
12686
5f65a0cca87c [gaim-migrate @ 15029]
Richard Laager <rlaager@wiktel.com>
parents: 11898
diff changeset
233 nattype.status = GAIM_STUN_STATUS_DISCOVERED;
5f65a0cca87c [gaim-migrate @ 15029]
Richard Laager <rlaager@wiktel.com>
parents: 11898
diff changeset
234 nattype.type = GAIM_STUN_NAT_TYPE_UNKNOWN_NAT;
12756
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
235 nattype.lookup_time = time(NULL);
11354
97028c1c69e9 [gaim-migrate @ 13573]
Thomas Butter <tbutter>
parents: 11336
diff changeset
236
11371
6e02e20e3a58 [gaim-migrate @ 13596]
Richard Laager <rlaager@wiktel.com>
parents: 11364
diff changeset
237 /* is it a NAT? */
11225
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
238
11354
97028c1c69e9 [gaim-migrate @ 13573]
Thomas Butter <tbutter>
parents: 11336
diff changeset
239 ifc.ifc_len = sizeof(buffer);
97028c1c69e9 [gaim-migrate @ 13573]
Thomas Butter <tbutter>
parents: 11336
diff changeset
240 ifc.ifc_req = (struct ifreq *) buffer;
97028c1c69e9 [gaim-migrate @ 13573]
Thomas Butter <tbutter>
parents: 11336
diff changeset
241 ioctl(source, SIOCGIFCONF, &ifc);
11225
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
242
11354
97028c1c69e9 [gaim-migrate @ 13573]
Thomas Butter <tbutter>
parents: 11336
diff changeset
243 tmp = buffer;
97028c1c69e9 [gaim-migrate @ 13573]
Thomas Butter <tbutter>
parents: 11336
diff changeset
244 while(tmp < buffer + ifc.ifc_len) {
97028c1c69e9 [gaim-migrate @ 13573]
Thomas Butter <tbutter>
parents: 11336
diff changeset
245 ifr = (struct ifreq *) tmp;
11225
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
246
11364
e1840eb860e7 [gaim-migrate @ 13588]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11354
diff changeset
247 tmp += sizeof(struct ifreq);
11225
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
248
11354
97028c1c69e9 [gaim-migrate @ 13573]
Thomas Butter <tbutter>
parents: 11336
diff changeset
249 if(ifr->ifr_addr.sa_family == AF_INET) {
11371
6e02e20e3a58 [gaim-migrate @ 13596]
Richard Laager <rlaager@wiktel.com>
parents: 11364
diff changeset
250 /* we only care about ipv4 interfaces */
11354
97028c1c69e9 [gaim-migrate @ 13573]
Thomas Butter <tbutter>
parents: 11336
diff changeset
251 sinptr = (struct sockaddr_in *) &ifr->ifr_addr;
97028c1c69e9 [gaim-migrate @ 13573]
Thomas Butter <tbutter>
parents: 11336
diff changeset
252 if(sinptr->sin_addr.s_addr == in.s_addr) {
11371
6e02e20e3a58 [gaim-migrate @ 13596]
Richard Laager <rlaager@wiktel.com>
parents: 11364
diff changeset
253 /* no NAT */
6e02e20e3a58 [gaim-migrate @ 13596]
Richard Laager <rlaager@wiktel.com>
parents: 11364
diff changeset
254 gaim_debug_info("stun", "no nat");
12686
5f65a0cca87c [gaim-migrate @ 15029]
Richard Laager <rlaager@wiktel.com>
parents: 11898
diff changeset
255 nattype.type = GAIM_STUN_NAT_TYPE_PUBLIC_IP;
11354
97028c1c69e9 [gaim-migrate @ 13573]
Thomas Butter <tbutter>
parents: 11336
diff changeset
256 }
11225
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
257 }
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
258 }
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
259
12756
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
260 #ifndef NOTYET
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
261 close_stun_conn(sc);
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
262 do_callbacks();
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
263 #else
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
264 gaim_timeout_remove(sc->timeout);
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
265 sc->timeout = 0;
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
266
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
267 do_test2(sc);
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
268 } else if(sc->test == 2) {
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
269 close_stun_conn(sc);
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
270 nattype.type = GAIM_STUN_NAT_TYPE_FULL_CONE;
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
271 do_callbacks();
11354
97028c1c69e9 [gaim-migrate @ 13573]
Thomas Butter <tbutter>
parents: 11336
diff changeset
272 #endif
97028c1c69e9 [gaim-migrate @ 13573]
Thomas Butter <tbutter>
parents: 11336
diff changeset
273 }
11336
7d7dd22215ec [gaim-migrate @ 13549]
Thomas Butter <tbutter>
parents: 11300
diff changeset
274 }
11424
e1ab173ef3b5 [gaim-migrate @ 13661]
Thomas Butter <tbutter>
parents: 11371
diff changeset
275
12909
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12877
diff changeset
276
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12877
diff changeset
277 static void hbn_listen_cb(int fd, gpointer data) {
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12877
diff changeset
278 GSList *hosts = data;
12756
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
279 struct stun_conn *sc;
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
280 static struct stun_header hdr_data;
12909
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12877
diff changeset
281 int ret;
11425
54fa445aff32 [gaim-migrate @ 13662]
Thomas Butter <tbutter>
parents: 11424
diff changeset
282
12909
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12877
diff changeset
283 if(fd < 0) {
12686
5f65a0cca87c [gaim-migrate @ 15029]
Richard Laager <rlaager@wiktel.com>
parents: 11898
diff changeset
284 nattype.status = GAIM_STUN_STATUS_UNKNOWN;
12756
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
285 nattype.lookup_time = time(NULL);
11431
d2e44c8085e0 [gaim-migrate @ 13668]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11429
diff changeset
286 do_callbacks();
11424
e1ab173ef3b5 [gaim-migrate @ 13661]
Thomas Butter <tbutter>
parents: 11371
diff changeset
287 return;
11225
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
288 }
12756
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
289
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
290 sc = g_new0(struct stun_conn, 1);
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
291 sc->fd = fd;
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
292
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
293 sc->addr.sin_family = AF_INET;
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
294 sc->addr.sin_port = htons(gaim_network_get_port_from_fd(fd));
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
295 sc->addr.sin_addr.s_addr = INADDR_ANY;
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
296
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
297 sc->incb = gaim_input_add(fd, GAIM_INPUT_READ, reply_cb, sc);
11225
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
298
11429
835dbb1b3337 [gaim-migrate @ 13666]
Thomas Butter <tbutter>
parents: 11425
diff changeset
299 ret = GPOINTER_TO_INT(hosts->data);
835dbb1b3337 [gaim-migrate @ 13666]
Thomas Butter <tbutter>
parents: 11425
diff changeset
300 hosts = g_slist_remove(hosts, hosts->data);
12756
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
301 memcpy(&(sc->addr), hosts->data, sizeof(struct sockaddr_in));
11429
835dbb1b3337 [gaim-migrate @ 13666]
Thomas Butter <tbutter>
parents: 11425
diff changeset
302 g_free(hosts->data);
835dbb1b3337 [gaim-migrate @ 13666]
Thomas Butter <tbutter>
parents: 11425
diff changeset
303 hosts = g_slist_remove(hosts, hosts->data);
835dbb1b3337 [gaim-migrate @ 13666]
Thomas Butter <tbutter>
parents: 11425
diff changeset
304 while(hosts) {
835dbb1b3337 [gaim-migrate @ 13666]
Thomas Butter <tbutter>
parents: 11425
diff changeset
305 hosts = g_slist_remove(hosts, hosts->data);
835dbb1b3337 [gaim-migrate @ 13666]
Thomas Butter <tbutter>
parents: 11425
diff changeset
306 g_free(hosts->data);
835dbb1b3337 [gaim-migrate @ 13666]
Thomas Butter <tbutter>
parents: 11425
diff changeset
307 hosts = g_slist_remove(hosts, hosts->data);
835dbb1b3337 [gaim-migrate @ 13666]
Thomas Butter <tbutter>
parents: 11425
diff changeset
308 }
11431
d2e44c8085e0 [gaim-migrate @ 13668]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11429
diff changeset
309
12756
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
310 hdr_data.type = htons(MSGTYPE_BINDINGREQUEST);
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
311 hdr_data.len = 0;
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
312 hdr_data.transid[0] = rand();
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
313 hdr_data.transid[1] = ntohl(((int)'g' << 24) + ((int)'a' << 16) + ((int)'i' << 8) + (int)'m');
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
314 hdr_data.transid[2] = rand();
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
315 hdr_data.transid[3] = rand();
11431
d2e44c8085e0 [gaim-migrate @ 13668]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11429
diff changeset
316
12756
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
317 if(sendto(sc->fd, &hdr_data, sizeof(struct stun_header), 0,
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
318 (struct sockaddr *)&(sc->addr),
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
319 sizeof(struct sockaddr_in)) < sizeof(struct stun_header)) {
12686
5f65a0cca87c [gaim-migrate @ 15029]
Richard Laager <rlaager@wiktel.com>
parents: 11898
diff changeset
320 nattype.status = GAIM_STUN_STATUS_UNKNOWN;
12756
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
321 nattype.lookup_time = time(NULL);
11431
d2e44c8085e0 [gaim-migrate @ 13668]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11429
diff changeset
322 do_callbacks();
12756
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
323 close_stun_conn(sc);
11431
d2e44c8085e0 [gaim-migrate @ 13668]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11429
diff changeset
324 return;
11225
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
325 }
12756
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
326 sc->test = 1;
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
327 sc->packet = &hdr_data;
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
328 sc->packetsize = sizeof(struct stun_header);
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
329 sc->timeout = gaim_timeout_add(500, (GSourceFunc) timeoutfunc, sc);
11429
835dbb1b3337 [gaim-migrate @ 13666]
Thomas Butter <tbutter>
parents: 11425
diff changeset
330 }
835dbb1b3337 [gaim-migrate @ 13666]
Thomas Butter <tbutter>
parents: 11425
diff changeset
331
12909
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12877
diff changeset
332 static void hbn_cb(GSList *hosts, gpointer data, const char *error_message) {
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12877
diff changeset
333
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12877
diff changeset
334 if(!hosts || !hosts->data) {
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12877
diff changeset
335 nattype.status = GAIM_STUN_STATUS_UNDISCOVERED;
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12877
diff changeset
336 nattype.lookup_time = time(NULL);
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12877
diff changeset
337 do_callbacks();
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12877
diff changeset
338 return;
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12877
diff changeset
339 }
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12877
diff changeset
340
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12877
diff changeset
341 if (!gaim_network_listen_range(12108, 12208, SOCK_DGRAM, hbn_listen_cb, hosts)) {
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12877
diff changeset
342 nattype.status = GAIM_STUN_STATUS_UNKNOWN;
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12877
diff changeset
343 nattype.lookup_time = time(NULL);
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12877
diff changeset
344 do_callbacks();
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12877
diff changeset
345 return;
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12877
diff changeset
346 }
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12877
diff changeset
347
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12877
diff changeset
348
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12877
diff changeset
349 }
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12877
diff changeset
350
12686
5f65a0cca87c [gaim-migrate @ 15029]
Richard Laager <rlaager@wiktel.com>
parents: 11898
diff changeset
351 static void do_test1(GaimSrvResponse *resp, int results, gpointer sdata) {
11431
d2e44c8085e0 [gaim-migrate @ 13668]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11429
diff changeset
352 const char *servername = sdata;
11429
835dbb1b3337 [gaim-migrate @ 13666]
Thomas Butter <tbutter>
parents: 11425
diff changeset
353 int port = 3478;
11431
d2e44c8085e0 [gaim-migrate @ 13668]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11429
diff changeset
354
11429
835dbb1b3337 [gaim-migrate @ 13666]
Thomas Butter <tbutter>
parents: 11425
diff changeset
355 if(results) {
835dbb1b3337 [gaim-migrate @ 13666]
Thomas Butter <tbutter>
parents: 11425
diff changeset
356 servername = resp[0].hostname;
835dbb1b3337 [gaim-migrate @ 13666]
Thomas Butter <tbutter>
parents: 11425
diff changeset
357 port = resp[0].port;
835dbb1b3337 [gaim-migrate @ 13666]
Thomas Butter <tbutter>
parents: 11425
diff changeset
358 }
12756
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
359 gaim_debug_info("stun", "got %d SRV responses, server: %s, port: %d\n",
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
360 results, servername, port);
11429
835dbb1b3337 [gaim-migrate @ 13666]
Thomas Butter <tbutter>
parents: 11425
diff changeset
361
835dbb1b3337 [gaim-migrate @ 13666]
Thomas Butter <tbutter>
parents: 11425
diff changeset
362 gaim_gethostbyname_async(servername, port, hbn_cb, NULL);
11424
e1ab173ef3b5 [gaim-migrate @ 13661]
Thomas Butter <tbutter>
parents: 11371
diff changeset
363 g_free(resp);
11225
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
364 }
11424
e1ab173ef3b5 [gaim-migrate @ 13661]
Thomas Butter <tbutter>
parents: 11371
diff changeset
365
12756
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
366 static gboolean call_callback(gpointer data) {
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
367 StunCallback cb = data;
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
368 cb(&nattype);
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
369 return FALSE;
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
370 }
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
371
12686
5f65a0cca87c [gaim-migrate @ 15029]
Richard Laager <rlaager@wiktel.com>
parents: 11898
diff changeset
372 GaimStunNatDiscovery *gaim_stun_discover(StunCallback cb) {
11431
d2e44c8085e0 [gaim-migrate @ 13668]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11429
diff changeset
373 const char *servername = gaim_prefs_get_string("/core/network/stun_server");
11424
e1ab173ef3b5 [gaim-migrate @ 13661]
Thomas Butter <tbutter>
parents: 11371
diff changeset
374
e1ab173ef3b5 [gaim-migrate @ 13661]
Thomas Butter <tbutter>
parents: 11371
diff changeset
375 gaim_debug_info("stun", "using server %s\n", servername);
12686
5f65a0cca87c [gaim-migrate @ 15029]
Richard Laager <rlaager@wiktel.com>
parents: 11898
diff changeset
376
5f65a0cca87c [gaim-migrate @ 15029]
Richard Laager <rlaager@wiktel.com>
parents: 11898
diff changeset
377 if(nattype.status == GAIM_STUN_STATUS_DISCOVERING) {
5f65a0cca87c [gaim-migrate @ 15029]
Richard Laager <rlaager@wiktel.com>
parents: 11898
diff changeset
378 if(cb)
5f65a0cca87c [gaim-migrate @ 15029]
Richard Laager <rlaager@wiktel.com>
parents: 11898
diff changeset
379 callbacks = g_slist_append(callbacks, cb);
12756
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
380 return &nattype;
11424
e1ab173ef3b5 [gaim-migrate @ 13661]
Thomas Butter <tbutter>
parents: 11371
diff changeset
381 }
12686
5f65a0cca87c [gaim-migrate @ 15029]
Richard Laager <rlaager@wiktel.com>
parents: 11898
diff changeset
382
5f65a0cca87c [gaim-migrate @ 15029]
Richard Laager <rlaager@wiktel.com>
parents: 11898
diff changeset
383 if(nattype.status != GAIM_STUN_STATUS_UNDISCOVERED) {
12756
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
384 gboolean use_cached_result = TRUE;
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
385
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
386 /** Deal with the server name having changed since we did the
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
387 lookup */
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
388 if (servername && strlen(servername) > 1
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
389 && ((nattype.servername
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
390 && strcmp(servername, nattype.servername))
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
391 || !nattype.servername)) {
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
392 use_cached_result = FALSE;
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
393 }
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
394
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
395 /* If we don't have a successful status and it has been 5
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
396 minutes since we last did a lookup, redo the lookup */
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
397 if (nattype.status != GAIM_STUN_STATUS_DISCOVERED
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
398 && (time(NULL) - nattype.lookup_time) > 300) {
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
399 use_cached_result = FALSE;
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
400 }
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
401
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
402 if (use_cached_result) {
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
403 if(cb)
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
404 gaim_timeout_add(10, call_callback, cb);
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
405 return &nattype;
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
406 }
11424
e1ab173ef3b5 [gaim-migrate @ 13661]
Thomas Butter <tbutter>
parents: 11371
diff changeset
407 }
e1ab173ef3b5 [gaim-migrate @ 13661]
Thomas Butter <tbutter>
parents: 11371
diff changeset
408
12686
5f65a0cca87c [gaim-migrate @ 15029]
Richard Laager <rlaager@wiktel.com>
parents: 11898
diff changeset
409 if(!servername || (strlen(servername) < 2)) {
5f65a0cca87c [gaim-migrate @ 15029]
Richard Laager <rlaager@wiktel.com>
parents: 11898
diff changeset
410 nattype.status = GAIM_STUN_STATUS_UNKNOWN;
12756
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
411 nattype.lookup_time = time(NULL);
12686
5f65a0cca87c [gaim-migrate @ 15029]
Richard Laager <rlaager@wiktel.com>
parents: 11898
diff changeset
412 if(cb)
12756
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
413 gaim_timeout_add(10, call_callback, cb);
11424
e1ab173ef3b5 [gaim-migrate @ 13661]
Thomas Butter <tbutter>
parents: 11371
diff changeset
414 return &nattype;
e1ab173ef3b5 [gaim-migrate @ 13661]
Thomas Butter <tbutter>
parents: 11371
diff changeset
415 }
12756
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
416
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
417 nattype.status = GAIM_STUN_STATUS_DISCOVERING;
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
418 nattype.publicip[0] = '\0';
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
419 g_free(nattype.servername);
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
420 nattype.servername = g_strdup(servername);
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
421
11424
e1ab173ef3b5 [gaim-migrate @ 13661]
Thomas Butter <tbutter>
parents: 11371
diff changeset
422 callbacks = g_slist_append(callbacks, cb);
12686
5f65a0cca87c [gaim-migrate @ 15029]
Richard Laager <rlaager@wiktel.com>
parents: 11898
diff changeset
423 gaim_srv_resolve("stun", "udp", servername, do_test1,
11431
d2e44c8085e0 [gaim-migrate @ 13668]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11429
diff changeset
424 (gpointer) servername);
12756
6ef1cdc26b40 [gaim-migrate @ 15103]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12700
diff changeset
425
11424
e1ab173ef3b5 [gaim-migrate @ 13661]
Thomas Butter <tbutter>
parents: 11371
diff changeset
426 return &nattype;
e1ab173ef3b5 [gaim-migrate @ 13661]
Thomas Butter <tbutter>
parents: 11371
diff changeset
427 }
e1ab173ef3b5 [gaim-migrate @ 13661]
Thomas Butter <tbutter>
parents: 11371
diff changeset
428
e1ab173ef3b5 [gaim-migrate @ 13661]
Thomas Butter <tbutter>
parents: 11371
diff changeset
429 void gaim_stun_init() {
e1ab173ef3b5 [gaim-migrate @ 13661]
Thomas Butter <tbutter>
parents: 11371
diff changeset
430 gaim_prefs_add_string("/core/network/stun_server", "");
12909
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12877
diff changeset
431 gaim_stun_discover(NULL);
11424
e1ab173ef3b5 [gaim-migrate @ 13661]
Thomas Butter <tbutter>
parents: 11371
diff changeset
432 }