Sun, 25 Jun 2017 18:17:08 -0500
stun: Fix detecting public IP address
A while ago, the stun code was updated to fix invalid alignment
warnings [1], but the patch missed renaming one of the uses of
the buffer variable. This caused it to look through the stun
response data, instead of the local interface data, when comparing
it to the IP address retrieved in the stun response. This patch
renames said buffer variable.
[1] https://bitbucket.org/pidgin/main/commits/8b6b8a3b5039348f08ad7a689343dcfae5cf716c
|
20147
66f05a854eee
applied changes from 8a731bbd0197fbcc91a705c2d8f528154216defa
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
1 | /* purple |
|
11225
e888c207b994
[gaim-migrate @ 13361]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
2 | * |
|
11336
d2033b2756e2
[gaim-migrate @ 13549]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11300
diff
changeset
|
3 | * STUN implementation inspired by jstun [http://jstun.javawi.de/] |
|
d2033b2756e2
[gaim-migrate @ 13549]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11300
diff
changeset
|
4 | * |
| 15884 | 5 | * Purple is the legal property of its developers, whose names are too numerous |
|
11225
e888c207b994
[gaim-migrate @ 13361]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
6 | * to list here. Please refer to the COPYRIGHT file distributed with this |
|
e888c207b994
[gaim-migrate @ 13361]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
7 | * source distribution. |
|
e888c207b994
[gaim-migrate @ 13361]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
8 | * |
|
e888c207b994
[gaim-migrate @ 13361]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
9 | * This program is free software; you can redistribute it and/or modify |
|
e888c207b994
[gaim-migrate @ 13361]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
10 | * it under the terms of the GNU General Public License as published by |
|
e888c207b994
[gaim-migrate @ 13361]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
11 | * the Free Software Foundation; either version 2 of the License, or |
|
e888c207b994
[gaim-migrate @ 13361]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
12 | * (at your option) any later version. |
|
e888c207b994
[gaim-migrate @ 13361]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
13 | * |
|
e888c207b994
[gaim-migrate @ 13361]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
14 | * This program is distributed in the hope that it will be useful, |
|
e888c207b994
[gaim-migrate @ 13361]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
e888c207b994
[gaim-migrate @ 13361]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
e888c207b994
[gaim-migrate @ 13361]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
17 | * GNU General Public License for more details. |
|
e888c207b994
[gaim-migrate @ 13361]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
18 | * |
|
e888c207b994
[gaim-migrate @ 13361]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
19 | * You should have received a copy of the GNU General Public License |
|
e888c207b994
[gaim-migrate @ 13361]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
20 | * along with this program; if not, write to the Free Software |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19770
diff
changeset
|
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
|
11225
e888c207b994
[gaim-migrate @ 13361]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
22 | * |
|
e888c207b994
[gaim-migrate @ 13361]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
23 | */ |
|
e888c207b994
[gaim-migrate @ 13361]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
24 | |
|
11898
a40601f1aed2
[gaim-migrate @ 14189]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11677
diff
changeset
|
25 | #include "internal.h" |
|
a40601f1aed2
[gaim-migrate @ 14189]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11677
diff
changeset
|
26 | |
|
11364
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
11354
diff
changeset
|
27 | #ifndef _WIN32 |
|
11225
e888c207b994
[gaim-migrate @ 13361]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
28 | #include <net/if.h> |
|
e888c207b994
[gaim-migrate @ 13361]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
29 | #include <sys/ioctl.h> |
|
11364
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
11354
diff
changeset
|
30 | #endif |
|
11225
e888c207b994
[gaim-migrate @ 13361]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
31 | |
|
37452
dafefd7bb115
This should do it for the libpurple dns stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37227
diff
changeset
|
32 | #include <gio/gio.h> |
|
dafefd7bb115
This should do it for the libpurple dns stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37227
diff
changeset
|
33 | |
| 12700 | 34 | /* Solaris */ |
| 35 | #if defined (__SVR4) && defined (__sun) | |
| 36 | #include <sys/sockio.h> | |
| 37 | #endif | |
| 38 | ||
|
11225
e888c207b994
[gaim-migrate @ 13361]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
39 | #include "debug.h" |
|
e888c207b994
[gaim-migrate @ 13361]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
40 | #include "account.h" |
|
12756
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
41 | #include "network.h" |
|
11429
3f7f01e88e77
[gaim-migrate @ 13666]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11425
diff
changeset
|
42 | #include "proxy.h" |
|
11225
e888c207b994
[gaim-migrate @ 13361]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
43 | #include "stun.h" |
|
e888c207b994
[gaim-migrate @ 13361]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
44 | #include "prefs.h" |
|
e888c207b994
[gaim-migrate @ 13361]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
45 | |
|
12756
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
46 | #define MSGTYPE_BINDINGREQUEST 0x0001 |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
47 | #define MSGTYPE_BINDINGRESPONSE 0x0101 |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
48 | |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
49 | #define ATTRIB_MAPPEDADDRESS 0x0001 |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
50 | |
|
35683
8b6b8a3b5039
Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35499
diff
changeset
|
51 | #ifndef _SIZEOF_ADDR_IFREQ |
|
8b6b8a3b5039
Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35499
diff
changeset
|
52 | # define _SIZEOF_ADDR_IFREQ(a) sizeof(a) |
|
8b6b8a3b5039
Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35499
diff
changeset
|
53 | #endif |
|
8b6b8a3b5039
Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35499
diff
changeset
|
54 | |
|
12686
ec3e7c4ff045
[gaim-migrate @ 15029]
Richard Laager <rlaager@pidgin.im>
parents:
11898
diff
changeset
|
55 | struct stun_header { |
|
12756
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
56 | guint16 type; |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
57 | guint16 len; |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
58 | guint32 transid[4]; |
|
12686
ec3e7c4ff045
[gaim-migrate @ 15029]
Richard Laager <rlaager@pidgin.im>
parents:
11898
diff
changeset
|
59 | }; |
|
ec3e7c4ff045
[gaim-migrate @ 15029]
Richard Laager <rlaager@pidgin.im>
parents:
11898
diff
changeset
|
60 | |
|
ec3e7c4ff045
[gaim-migrate @ 15029]
Richard Laager <rlaager@pidgin.im>
parents:
11898
diff
changeset
|
61 | struct stun_attrib { |
|
12756
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
62 | guint16 type; |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
63 | guint16 len; |
|
12686
ec3e7c4ff045
[gaim-migrate @ 15029]
Richard Laager <rlaager@pidgin.im>
parents:
11898
diff
changeset
|
64 | }; |
|
ec3e7c4ff045
[gaim-migrate @ 15029]
Richard Laager <rlaager@pidgin.im>
parents:
11898
diff
changeset
|
65 | |
|
37227
17bdb1daf323
Change '#if NOTYET' to '#if 0' for clarity.
Michael McConville <mmcconville@mykolab.com>
parents:
36257
diff
changeset
|
66 | #if 0 |
|
12686
ec3e7c4ff045
[gaim-migrate @ 15029]
Richard Laager <rlaager@pidgin.im>
parents:
11898
diff
changeset
|
67 | struct stun_change { |
|
ec3e7c4ff045
[gaim-migrate @ 15029]
Richard Laager <rlaager@pidgin.im>
parents:
11898
diff
changeset
|
68 | struct stun_header hdr; |
|
ec3e7c4ff045
[gaim-migrate @ 15029]
Richard Laager <rlaager@pidgin.im>
parents:
11898
diff
changeset
|
69 | struct stun_attrib attrib; |
|
ec3e7c4ff045
[gaim-migrate @ 15029]
Richard Laager <rlaager@pidgin.im>
parents:
11898
diff
changeset
|
70 | char value[4]; |
|
ec3e7c4ff045
[gaim-migrate @ 15029]
Richard Laager <rlaager@pidgin.im>
parents:
11898
diff
changeset
|
71 | }; |
|
37227
17bdb1daf323
Change '#if NOTYET' to '#if 0' for clarity.
Michael McConville <mmcconville@mykolab.com>
parents:
36257
diff
changeset
|
72 | #endif /* 0 */ |
|
12686
ec3e7c4ff045
[gaim-migrate @ 15029]
Richard Laager <rlaager@pidgin.im>
parents:
11898
diff
changeset
|
73 | |
|
12756
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
74 | struct stun_conn { |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
75 | int fd; |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
76 | struct sockaddr_in addr; |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
77 | int test; |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
78 | int retry; |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
79 | guint incb; |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
80 | guint timeout; |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
81 | struct stun_header *packet; |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
82 | size_t packetsize; |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
83 | }; |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
84 | |
|
37465
2b3189543b1f
Clean up some gross I forgot about
Gary Kramlich <grim@reaperworld.com>
parents:
37452
diff
changeset
|
85 | typedef struct { |
|
2b3189543b1f
Clean up some gross I forgot about
Gary Kramlich <grim@reaperworld.com>
parents:
37452
diff
changeset
|
86 | gint port; |
|
2b3189543b1f
Clean up some gross I forgot about
Gary Kramlich <grim@reaperworld.com>
parents:
37452
diff
changeset
|
87 | GList *addresses; |
|
2b3189543b1f
Clean up some gross I forgot about
Gary Kramlich <grim@reaperworld.com>
parents:
37452
diff
changeset
|
88 | } StunHBNListenData; |
|
2b3189543b1f
Clean up some gross I forgot about
Gary Kramlich <grim@reaperworld.com>
parents:
37452
diff
changeset
|
89 | |
| 15884 | 90 | static PurpleStunNatDiscovery nattype = { |
| 91 | PURPLE_STUN_STATUS_UNDISCOVERED, | |
| 92 | PURPLE_STUN_NAT_TYPE_PUBLIC_IP, | |
|
12877
aebd8924bc4b
[gaim-migrate @ 15229]
Daniel Atallah <datallah@pidgin.im>
parents:
12757
diff
changeset
|
93 | "\0", NULL, 0}; |
|
11225
e888c207b994
[gaim-migrate @ 13361]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
94 | |
|
12877
aebd8924bc4b
[gaim-migrate @ 15229]
Daniel Atallah <datallah@pidgin.im>
parents:
12757
diff
changeset
|
95 | static GSList *callbacks = NULL; |
|
12756
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
96 | |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
97 | static void close_stun_conn(struct stun_conn *sc) { |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
98 | |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
99 | if (sc->incb) |
| 15884 | 100 | purple_input_remove(sc->incb); |
|
12756
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
101 | |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
102 | if (sc->timeout) |
| 15884 | 103 | purple_timeout_remove(sc->timeout); |
|
12756
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
104 | |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
105 | if (sc->fd) |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
106 | close(sc->fd); |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
107 | |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
108 | g_free(sc); |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
109 | } |
|
11225
e888c207b994
[gaim-migrate @ 13361]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
110 | |
|
22104
56970903b8e9
Probe for -Wstrict-prototypes to get some more warnings. I then cleaned up
Richard Laager <rlaager@pidgin.im>
parents:
20147
diff
changeset
|
111 | static void do_callbacks(void) { |
|
30704
a07bc8a6c401
Optimize just a teensy-tiny bit.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
27497
diff
changeset
|
112 | while (callbacks) { |
|
35499
c4c5e0a670b1
Fix namespaces issues in libpurple.
Ankit Vani <a@nevitus.org>
parents:
35466
diff
changeset
|
113 | PurpleStunCallback cb = callbacks->data; |
|
30704
a07bc8a6c401
Optimize just a teensy-tiny bit.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
27497
diff
changeset
|
114 | if (cb) |
|
11336
d2033b2756e2
[gaim-migrate @ 13549]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11300
diff
changeset
|
115 | cb(&nattype); |
|
30704
a07bc8a6c401
Optimize just a teensy-tiny bit.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
27497
diff
changeset
|
116 | callbacks = g_slist_delete_link(callbacks, callbacks); |
|
11225
e888c207b994
[gaim-migrate @ 13361]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
117 | } |
|
e888c207b994
[gaim-migrate @ 13361]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
118 | } |
|
e888c207b994
[gaim-migrate @ 13361]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
119 | |
|
12756
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
120 | static gboolean timeoutfunc(gpointer data) { |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
121 | struct stun_conn *sc = data; |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
122 | if(sc->retry >= 2) { |
|
27497
2dc5a0e0c4c2
Increase the logging level of some debugging messages that seemed to be a
Mauro Brasil <mauro.brasil@tqi.com.br>
parents:
26782
diff
changeset
|
123 | purple_debug_warning("stun", "request timed out, giving up.\n"); |
|
12756
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
124 | if(sc->test == 2) |
| 15884 | 125 | nattype.type = PURPLE_STUN_NAT_TYPE_SYMMETRIC; |
|
12686
ec3e7c4ff045
[gaim-migrate @ 15029]
Richard Laager <rlaager@pidgin.im>
parents:
11898
diff
changeset
|
126 | |
|
11354
265f44ed44bc
[gaim-migrate @ 13573]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11336
diff
changeset
|
127 | /* set unknown */ |
| 15884 | 128 | nattype.status = PURPLE_STUN_STATUS_UNKNOWN; |
|
11354
265f44ed44bc
[gaim-migrate @ 13573]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11336
diff
changeset
|
129 | |
|
12756
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
130 | nattype.lookup_time = time(NULL); |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
131 | |
|
11354
265f44ed44bc
[gaim-migrate @ 13573]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11336
diff
changeset
|
132 | /* callbacks */ |
|
265f44ed44bc
[gaim-migrate @ 13573]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11336
diff
changeset
|
133 | do_callbacks(); |
|
265f44ed44bc
[gaim-migrate @ 13573]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11336
diff
changeset
|
134 | |
|
12756
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
135 | /* we don't need to remove the timeout (returning FALSE) */ |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
136 | sc->timeout = 0; |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
137 | close_stun_conn(sc); |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
138 | |
|
11354
265f44ed44bc
[gaim-migrate @ 13573]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11336
diff
changeset
|
139 | return FALSE; |
|
265f44ed44bc
[gaim-migrate @ 13573]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11336
diff
changeset
|
140 | } |
| 15884 | 141 | purple_debug_info("stun", "request timed out, retrying.\n"); |
|
12756
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
142 | sc->retry++; |
|
35991
e6937e52930b
Fix some CWE-252 coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35968
diff
changeset
|
143 | if (sendto(sc->fd, sc->packet, sc->packetsize, 0, |
|
e6937e52930b
Fix some CWE-252 coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35968
diff
changeset
|
144 | (struct sockaddr *)&(sc->addr), sizeof(struct sockaddr_in)) != |
|
36256
a437550a9308
Remove -Wno-sign-compare and backport fixes from default.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
35991
diff
changeset
|
145 | (gssize)sc->packetsize) |
|
35991
e6937e52930b
Fix some CWE-252 coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35968
diff
changeset
|
146 | { |
|
e6937e52930b
Fix some CWE-252 coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35968
diff
changeset
|
147 | purple_debug_warning("stun", "sendto failed\n"); |
|
e6937e52930b
Fix some CWE-252 coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35968
diff
changeset
|
148 | return FALSE; |
|
e6937e52930b
Fix some CWE-252 coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35968
diff
changeset
|
149 | } |
|
11354
265f44ed44bc
[gaim-migrate @ 13573]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11336
diff
changeset
|
150 | return TRUE; |
|
265f44ed44bc
[gaim-migrate @ 13573]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11336
diff
changeset
|
151 | } |
|
265f44ed44bc
[gaim-migrate @ 13573]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11336
diff
changeset
|
152 | |
|
37227
17bdb1daf323
Change '#if NOTYET' to '#if 0' for clarity.
Michael McConville <mmcconville@mykolab.com>
parents:
36257
diff
changeset
|
153 | #if 0 |
|
12756
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
154 | static void do_test2(struct stun_conn *sc) { |
|
11354
265f44ed44bc
[gaim-migrate @ 13573]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11336
diff
changeset
|
155 | struct stun_change data; |
|
11431
60971f504319
[gaim-migrate @ 13668]
Daniel Atallah <datallah@pidgin.im>
parents:
11429
diff
changeset
|
156 | data.hdr.type = htons(0x0001); |
|
60971f504319
[gaim-migrate @ 13668]
Daniel Atallah <datallah@pidgin.im>
parents:
11429
diff
changeset
|
157 | data.hdr.len = 0; |
|
60971f504319
[gaim-migrate @ 13668]
Daniel Atallah <datallah@pidgin.im>
parents:
11429
diff
changeset
|
158 | data.hdr.transid[0] = rand(); |
|
60971f504319
[gaim-migrate @ 13668]
Daniel Atallah <datallah@pidgin.im>
parents:
11429
diff
changeset
|
159 | data.hdr.transid[1] = ntohl(((int)'g' << 24) + ((int)'a' << 16) + ((int)'i' << 8) + (int)'m'); |
|
60971f504319
[gaim-migrate @ 13668]
Daniel Atallah <datallah@pidgin.im>
parents:
11429
diff
changeset
|
160 | data.hdr.transid[2] = rand(); |
|
60971f504319
[gaim-migrate @ 13668]
Daniel Atallah <datallah@pidgin.im>
parents:
11429
diff
changeset
|
161 | data.hdr.transid[3] = rand(); |
|
60971f504319
[gaim-migrate @ 13668]
Daniel Atallah <datallah@pidgin.im>
parents:
11429
diff
changeset
|
162 | data.attrib.type = htons(0x003); |
|
11354
265f44ed44bc
[gaim-migrate @ 13573]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11336
diff
changeset
|
163 | data.attrib.len = htons(4); |
|
265f44ed44bc
[gaim-migrate @ 13573]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11336
diff
changeset
|
164 | data.value[3] = 6; |
|
12756
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
165 | sc->packet = (struct stun_header*)&data; |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
166 | sc->packetsize = sizeof(struct stun_change); |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
167 | sc->retry = 0; |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
168 | sc->test = 2; |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
169 | sendto(sc->fd, sc->packet, sc->packetsize, 0, (struct sockaddr *)&(sc->addr), sizeof(struct sockaddr_in)); |
| 15884 | 170 | sc->timeout = purple_timeout_add(500, (GSourceFunc) timeoutfunc, sc); |
|
11354
265f44ed44bc
[gaim-migrate @ 13573]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11336
diff
changeset
|
171 | } |
|
37227
17bdb1daf323
Change '#if NOTYET' to '#if 0' for clarity.
Michael McConville <mmcconville@mykolab.com>
parents:
36257
diff
changeset
|
172 | #endif /* 0 */ |
|
11354
265f44ed44bc
[gaim-migrate @ 13573]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11336
diff
changeset
|
173 | |
| 15884 | 174 | static void reply_cb(gpointer data, gint source, PurpleInputCondition cond) { |
|
12756
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
175 | struct stun_conn *sc = data; |
|
35683
8b6b8a3b5039
Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35499
diff
changeset
|
176 | guchar buffer[65536]; |
|
8b6b8a3b5039
Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35499
diff
changeset
|
177 | struct ifreq buffer_ifr[1000]; |
|
8b6b8a3b5039
Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35499
diff
changeset
|
178 | guchar *it, *it_end; |
|
36256
a437550a9308
Remove -Wno-sign-compare and backport fixes from default.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
35991
diff
changeset
|
179 | gssize len; |
|
11225
e888c207b994
[gaim-migrate @ 13361]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
180 | struct in_addr in; |
|
35683
8b6b8a3b5039
Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35499
diff
changeset
|
181 | struct stun_attrib attrib; |
|
8b6b8a3b5039
Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35499
diff
changeset
|
182 | struct stun_header hdr; |
|
11300
11bc6db394e6
[gaim-migrate @ 13500]
Richard Laager <rlaager@pidgin.im>
parents:
11229
diff
changeset
|
183 | struct ifconf ifc; |
|
11bc6db394e6
[gaim-migrate @ 13500]
Richard Laager <rlaager@pidgin.im>
parents:
11229
diff
changeset
|
184 | struct ifreq *ifr; |
|
11bc6db394e6
[gaim-migrate @ 13500]
Richard Laager <rlaager@pidgin.im>
parents:
11229
diff
changeset
|
185 | struct sockaddr_in *sinptr; |
|
11431
60971f504319
[gaim-migrate @ 13668]
Daniel Atallah <datallah@pidgin.im>
parents:
11429
diff
changeset
|
186 | |
|
35968
3e04feabcbfb
Fix some Coverity CWE-457 bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35200
diff
changeset
|
187 | memset(&in, 0, sizeof(in)); |
|
3e04feabcbfb
Fix some Coverity CWE-457 bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35200
diff
changeset
|
188 | |
|
12756
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
189 | len = recv(source, buffer, sizeof(buffer) - 1, 0); |
|
34304
faf0414a8b51
Fix most of libpurple warnings about -Wsign-compare
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
32983
diff
changeset
|
190 | if (len <= 0) { |
|
27497
2dc5a0e0c4c2
Increase the logging level of some debugging messages that seemed to be a
Mauro Brasil <mauro.brasil@tqi.com.br>
parents:
26782
diff
changeset
|
191 | purple_debug_warning("stun", "unable to read stun response\n"); |
|
12756
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
192 | return; |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
193 | } |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
194 | buffer[len] = '\0'; |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
195 | |
|
36256
a437550a9308
Remove -Wno-sign-compare and backport fixes from default.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
35991
diff
changeset
|
196 | if ((gsize)len < sizeof(struct stun_header)) { |
|
27497
2dc5a0e0c4c2
Increase the logging level of some debugging messages that seemed to be a
Mauro Brasil <mauro.brasil@tqi.com.br>
parents:
26782
diff
changeset
|
197 | purple_debug_warning("stun", "got invalid response\n"); |
|
12756
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
198 | return; |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
199 | } |
|
11225
e888c207b994
[gaim-migrate @ 13361]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
200 | |
|
35683
8b6b8a3b5039
Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35499
diff
changeset
|
201 | memcpy(&hdr, buffer, sizeof(hdr)); |
|
8b6b8a3b5039
Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35499
diff
changeset
|
202 | if ((gsize)len != (ntohs(hdr.len) + sizeof(struct stun_header))) { |
|
27497
2dc5a0e0c4c2
Increase the logging level of some debugging messages that seemed to be a
Mauro Brasil <mauro.brasil@tqi.com.br>
parents:
26782
diff
changeset
|
203 | purple_debug_warning("stun", "got incomplete response\n"); |
|
12756
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
204 | return; |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
205 | } |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
206 | |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
207 | /* wrong transaction */ |
|
35683
8b6b8a3b5039
Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35499
diff
changeset
|
208 | if(hdr.transid[0] != sc->packet->transid[0] |
|
8b6b8a3b5039
Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35499
diff
changeset
|
209 | || hdr.transid[1] != sc->packet->transid[1] |
|
8b6b8a3b5039
Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35499
diff
changeset
|
210 | || hdr.transid[2] != sc->packet->transid[2] |
|
8b6b8a3b5039
Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35499
diff
changeset
|
211 | || hdr.transid[3] != sc->packet->transid[3]) { |
|
27497
2dc5a0e0c4c2
Increase the logging level of some debugging messages that seemed to be a
Mauro Brasil <mauro.brasil@tqi.com.br>
parents:
26782
diff
changeset
|
212 | purple_debug_warning("stun", "got wrong transid\n"); |
|
11225
e888c207b994
[gaim-migrate @ 13361]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
213 | return; |
|
e888c207b994
[gaim-migrate @ 13361]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
214 | } |
|
12756
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
215 | |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
216 | if(sc->test==1) { |
|
35683
8b6b8a3b5039
Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35499
diff
changeset
|
217 | if (hdr.type != MSGTYPE_BINDINGRESPONSE) { |
|
27497
2dc5a0e0c4c2
Increase the logging level of some debugging messages that seemed to be a
Mauro Brasil <mauro.brasil@tqi.com.br>
parents:
26782
diff
changeset
|
218 | purple_debug_warning("stun", |
|
12756
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
219 | "Expected Binding Response, got %d\n", |
|
35683
8b6b8a3b5039
Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35499
diff
changeset
|
220 | hdr.type); |
|
12756
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
221 | return; |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
222 | } |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
223 | |
|
35683
8b6b8a3b5039
Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35499
diff
changeset
|
224 | it = buffer + sizeof(struct stun_header); |
|
8b6b8a3b5039
Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35499
diff
changeset
|
225 | while((buffer + len) > (it + sizeof(struct stun_attrib))) { |
|
8b6b8a3b5039
Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35499
diff
changeset
|
226 | memcpy(&attrib, it, sizeof(attrib)); |
|
8b6b8a3b5039
Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35499
diff
changeset
|
227 | it += sizeof(struct stun_attrib); |
|
12756
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
228 | |
|
35683
8b6b8a3b5039
Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35499
diff
changeset
|
229 | if (!((buffer + len) > (it + ntohs(attrib.len)))) |
|
12756
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
230 | break; |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
231 | |
|
35683
8b6b8a3b5039
Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35499
diff
changeset
|
232 | if(attrib.type == htons(ATTRIB_MAPPEDADDRESS) |
|
8b6b8a3b5039
Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35499
diff
changeset
|
233 | && ntohs(attrib.len) == 8) { |
|
12756
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
234 | char *ip; |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
235 | /* Skip the first unused byte, |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
236 | * the family(1 byte), and the port(2 bytes); |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
237 | * then read the 4 byte IPv4 address */ |
|
35683
8b6b8a3b5039
Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35499
diff
changeset
|
238 | memcpy(&in.s_addr, it + 4, 4); |
|
12756
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
239 | ip = inet_ntoa(in); |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
240 | if(ip) |
|
32002
a577544f30d7
Almost certainly not an issue, but bounds check a strcpy in stun.c (EFF)
Ethan Blanton <elb@pidgin.im>
parents:
31680
diff
changeset
|
241 | g_strlcpy(nattype.publicip, ip, sizeof(nattype.publicip)); |
|
11354
265f44ed44bc
[gaim-migrate @ 13573]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11336
diff
changeset
|
242 | } |
|
12756
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
243 | |
|
35683
8b6b8a3b5039
Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35499
diff
changeset
|
244 | it += ntohs(attrib.len); |
|
11225
e888c207b994
[gaim-migrate @ 13361]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
245 | } |
| 15884 | 246 | purple_debug_info("stun", "got public ip %s\n", nattype.publicip); |
| 247 | nattype.status = PURPLE_STUN_STATUS_DISCOVERED; | |
| 248 | nattype.type = PURPLE_STUN_NAT_TYPE_UNKNOWN_NAT; | |
|
12756
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
249 | nattype.lookup_time = time(NULL); |
|
11354
265f44ed44bc
[gaim-migrate @ 13573]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11336
diff
changeset
|
250 | |
|
11371
363713bfd3d1
[gaim-migrate @ 13596]
Richard Laager <rlaager@pidgin.im>
parents:
11364
diff
changeset
|
251 | /* is it a NAT? */ |
|
11225
e888c207b994
[gaim-migrate @ 13361]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
252 | |
|
35683
8b6b8a3b5039
Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35499
diff
changeset
|
253 | ifc.ifc_len = sizeof(buffer_ifr); |
|
8b6b8a3b5039
Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35499
diff
changeset
|
254 | ifc.ifc_req = buffer_ifr; |
|
11354
265f44ed44bc
[gaim-migrate @ 13573]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11336
diff
changeset
|
255 | ioctl(source, SIOCGIFCONF, &ifc); |
|
11225
e888c207b994
[gaim-migrate @ 13361]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
256 | |
|
38380
19e137cf32f5
stun: Fix detecting public IP address
Mike Ruprecht <cmaiku@gmail.com>
parents:
38195
diff
changeset
|
257 | it = (guchar *)buffer_ifr; |
|
35683
8b6b8a3b5039
Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35499
diff
changeset
|
258 | it_end = it + ifc.ifc_len; |
|
8b6b8a3b5039
Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35499
diff
changeset
|
259 | while (it < it_end) { |
|
8b6b8a3b5039
Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35499
diff
changeset
|
260 | ifr = (struct ifreq*)(gpointer)it; |
|
8b6b8a3b5039
Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35499
diff
changeset
|
261 | it += _SIZEOF_ADDR_IFREQ(*ifr); |
|
11225
e888c207b994
[gaim-migrate @ 13361]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
262 | |
|
11354
265f44ed44bc
[gaim-migrate @ 13573]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11336
diff
changeset
|
263 | if(ifr->ifr_addr.sa_family == AF_INET) { |
|
11371
363713bfd3d1
[gaim-migrate @ 13596]
Richard Laager <rlaager@pidgin.im>
parents:
11364
diff
changeset
|
264 | /* we only care about ipv4 interfaces */ |
|
35683
8b6b8a3b5039
Fix most of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35499
diff
changeset
|
265 | sinptr = (struct sockaddr_in *)(gpointer)&ifr->ifr_addr; |
|
11354
265f44ed44bc
[gaim-migrate @ 13573]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11336
diff
changeset
|
266 | if(sinptr->sin_addr.s_addr == in.s_addr) { |
|
11371
363713bfd3d1
[gaim-migrate @ 13596]
Richard Laager <rlaager@pidgin.im>
parents:
11364
diff
changeset
|
267 | /* no NAT */ |
|
19770
9184bfee0172
Add a missing newline to the end of a purple_debug_info call.
Richard Laager <rlaager@pidgin.im>
parents:
19048
diff
changeset
|
268 | purple_debug_info("stun", "no nat\n"); |
| 15884 | 269 | nattype.type = PURPLE_STUN_NAT_TYPE_PUBLIC_IP; |
|
11354
265f44ed44bc
[gaim-migrate @ 13573]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11336
diff
changeset
|
270 | } |
|
11225
e888c207b994
[gaim-migrate @ 13361]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
271 | } |
|
e888c207b994
[gaim-migrate @ 13361]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
272 | } |
|
e888c207b994
[gaim-migrate @ 13361]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
273 | |
|
37227
17bdb1daf323
Change '#if NOTYET' to '#if 0' for clarity.
Michael McConville <mmcconville@mykolab.com>
parents:
36257
diff
changeset
|
274 | #if 1 |
|
12756
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
275 | close_stun_conn(sc); |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
276 | do_callbacks(); |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
277 | #else |
| 15884 | 278 | purple_timeout_remove(sc->timeout); |
|
12756
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
279 | sc->timeout = 0; |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
280 | |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
281 | do_test2(sc); |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
282 | } else if(sc->test == 2) { |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
283 | close_stun_conn(sc); |
| 15884 | 284 | nattype.type = PURPLE_STUN_NAT_TYPE_FULL_CONE; |
|
12756
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
285 | do_callbacks(); |
|
37227
17bdb1daf323
Change '#if NOTYET' to '#if 0' for clarity.
Michael McConville <mmcconville@mykolab.com>
parents:
36257
diff
changeset
|
286 | #endif /* 1 */ |
|
11354
265f44ed44bc
[gaim-migrate @ 13573]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11336
diff
changeset
|
287 | } |
|
11336
d2033b2756e2
[gaim-migrate @ 13549]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11300
diff
changeset
|
288 | } |
|
11424
b0f8535daa74
[gaim-migrate @ 13661]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11371
diff
changeset
|
289 | |
|
12909
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12877
diff
changeset
|
290 | |
|
37452
dafefd7bb115
This should do it for the libpurple dns stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37227
diff
changeset
|
291 | static void |
|
dafefd7bb115
This should do it for the libpurple dns stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37227
diff
changeset
|
292 | hbn_listen_cb(int fd, gpointer data) { |
|
37465
2b3189543b1f
Clean up some gross I forgot about
Gary Kramlich <grim@reaperworld.com>
parents:
37452
diff
changeset
|
293 | StunHBNListenData *ld = (StunHBNListenData *)data; |
|
37452
dafefd7bb115
This should do it for the libpurple dns stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37227
diff
changeset
|
294 | GInetAddress *address = NULL; |
|
dafefd7bb115
This should do it for the libpurple dns stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37227
diff
changeset
|
295 | GSocketAddress *socket_address = NULL; |
|
12756
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
296 | struct stun_conn *sc; |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
297 | static struct stun_header hdr_data; |
|
11425
668f93d8c3a2
[gaim-migrate @ 13662]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11424
diff
changeset
|
298 | |
|
12909
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12877
diff
changeset
|
299 | if(fd < 0) { |
| 15884 | 300 | nattype.status = PURPLE_STUN_STATUS_UNKNOWN; |
|
12756
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
301 | nattype.lookup_time = time(NULL); |
|
11431
60971f504319
[gaim-migrate @ 13668]
Daniel Atallah <datallah@pidgin.im>
parents:
11429
diff
changeset
|
302 | do_callbacks(); |
|
11424
b0f8535daa74
[gaim-migrate @ 13661]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11371
diff
changeset
|
303 | return; |
|
11225
e888c207b994
[gaim-migrate @ 13361]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
304 | } |
|
12756
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
305 | |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
306 | sc = g_new0(struct stun_conn, 1); |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
307 | sc->fd = fd; |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
308 | |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
309 | sc->addr.sin_family = AF_INET; |
| 15884 | 310 | sc->addr.sin_port = htons(purple_network_get_port_from_fd(fd)); |
|
12756
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
311 | sc->addr.sin_addr.s_addr = INADDR_ANY; |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
312 | |
| 15884 | 313 | sc->incb = purple_input_add(fd, PURPLE_INPUT_READ, reply_cb, sc); |
|
11225
e888c207b994
[gaim-migrate @ 13361]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
314 | |
|
37969
61c6cf7a1184
stun: Fix g_object_unref assertion due to double free
Mike Ruprecht <cmaiku@gmail.com>
parents:
37518
diff
changeset
|
315 | address = g_object_ref(G_INET_ADDRESS(ld->addresses->data)); |
|
37465
2b3189543b1f
Clean up some gross I forgot about
Gary Kramlich <grim@reaperworld.com>
parents:
37452
diff
changeset
|
316 | socket_address = g_inet_socket_address_new(address, ld->port); |
|
37452
dafefd7bb115
This should do it for the libpurple dns stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37227
diff
changeset
|
317 | |
|
dafefd7bb115
This should do it for the libpurple dns stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37227
diff
changeset
|
318 | g_socket_address_to_native(socket_address, &(sc->addr), g_socket_address_get_native_size(socket_address), NULL); |
|
37465
2b3189543b1f
Clean up some gross I forgot about
Gary Kramlich <grim@reaperworld.com>
parents:
37452
diff
changeset
|
319 | |
|
37452
dafefd7bb115
This should do it for the libpurple dns stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37227
diff
changeset
|
320 | g_object_unref(G_OBJECT(address)); |
|
dafefd7bb115
This should do it for the libpurple dns stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37227
diff
changeset
|
321 | g_object_unref(G_OBJECT(socket_address)); |
|
37465
2b3189543b1f
Clean up some gross I forgot about
Gary Kramlich <grim@reaperworld.com>
parents:
37452
diff
changeset
|
322 | g_resolver_free_addresses(ld->addresses); |
|
2b3189543b1f
Clean up some gross I forgot about
Gary Kramlich <grim@reaperworld.com>
parents:
37452
diff
changeset
|
323 | g_free(ld); |
|
11431
60971f504319
[gaim-migrate @ 13668]
Daniel Atallah <datallah@pidgin.im>
parents:
11429
diff
changeset
|
324 | |
|
12756
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
325 | hdr_data.type = htons(MSGTYPE_BINDINGREQUEST); |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
326 | hdr_data.len = 0; |
|
38195
89e9e2f435ef
Fix coverity 1255951
Gary Kramlich <grim@reaperworld.com>
parents:
37969
diff
changeset
|
327 | hdr_data.transid[0] = g_random_int(); |
|
12756
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
328 | hdr_data.transid[1] = ntohl(((int)'g' << 24) + ((int)'a' << 16) + ((int)'i' << 8) + (int)'m'); |
|
38195
89e9e2f435ef
Fix coverity 1255951
Gary Kramlich <grim@reaperworld.com>
parents:
37969
diff
changeset
|
329 | hdr_data.transid[2] = g_random_int(); |
|
89e9e2f435ef
Fix coverity 1255951
Gary Kramlich <grim@reaperworld.com>
parents:
37969
diff
changeset
|
330 | hdr_data.transid[3] = g_random_int(); |
|
11431
60971f504319
[gaim-migrate @ 13668]
Daniel Atallah <datallah@pidgin.im>
parents:
11429
diff
changeset
|
331 | |
|
12756
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
332 | if(sendto(sc->fd, &hdr_data, sizeof(struct stun_header), 0, |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
333 | (struct sockaddr *)&(sc->addr), |
|
36256
a437550a9308
Remove -Wno-sign-compare and backport fixes from default.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
35991
diff
changeset
|
334 | sizeof(struct sockaddr_in)) < (gssize)sizeof(struct stun_header)) { |
| 15884 | 335 | nattype.status = PURPLE_STUN_STATUS_UNKNOWN; |
|
12756
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
336 | nattype.lookup_time = time(NULL); |
|
11431
60971f504319
[gaim-migrate @ 13668]
Daniel Atallah <datallah@pidgin.im>
parents:
11429
diff
changeset
|
337 | do_callbacks(); |
|
12756
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
338 | close_stun_conn(sc); |
|
11431
60971f504319
[gaim-migrate @ 13668]
Daniel Atallah <datallah@pidgin.im>
parents:
11429
diff
changeset
|
339 | return; |
|
11225
e888c207b994
[gaim-migrate @ 13361]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
340 | } |
|
12756
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
341 | sc->test = 1; |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
342 | sc->packet = &hdr_data; |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
343 | sc->packetsize = sizeof(struct stun_header); |
| 15884 | 344 | sc->timeout = purple_timeout_add(500, (GSourceFunc) timeoutfunc, sc); |
|
11429
3f7f01e88e77
[gaim-migrate @ 13666]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11425
diff
changeset
|
345 | } |
|
3f7f01e88e77
[gaim-migrate @ 13666]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11425
diff
changeset
|
346 | |
|
37452
dafefd7bb115
This should do it for the libpurple dns stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37227
diff
changeset
|
347 | static void |
|
dafefd7bb115
This should do it for the libpurple dns stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37227
diff
changeset
|
348 | hbn_cb(GObject *sender, GAsyncResult *res, gpointer data) { |
|
37465
2b3189543b1f
Clean up some gross I forgot about
Gary Kramlich <grim@reaperworld.com>
parents:
37452
diff
changeset
|
349 | StunHBNListenData *ld = NULL; |
|
37452
dafefd7bb115
This should do it for the libpurple dns stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37227
diff
changeset
|
350 | GError *error = NULL; |
|
12909
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12877
diff
changeset
|
351 | |
|
37465
2b3189543b1f
Clean up some gross I forgot about
Gary Kramlich <grim@reaperworld.com>
parents:
37452
diff
changeset
|
352 | ld = g_new0(StunHBNListenData, 1); |
|
2b3189543b1f
Clean up some gross I forgot about
Gary Kramlich <grim@reaperworld.com>
parents:
37452
diff
changeset
|
353 | |
|
37517
a67be31f9c7e
Use the GResolver which was passed to g_resolver_lookup_*_async()
Mike Ruprecht <cmaiku@gmail.com>
parents:
37469
diff
changeset
|
354 | ld->addresses = g_resolver_lookup_by_name_finish(G_RESOLVER(sender), |
|
a67be31f9c7e
Use the GResolver which was passed to g_resolver_lookup_*_async()
Mike Ruprecht <cmaiku@gmail.com>
parents:
37469
diff
changeset
|
355 | res, &error); |
|
37452
dafefd7bb115
This should do it for the libpurple dns stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37227
diff
changeset
|
356 | if(error != NULL) { |
| 15884 | 357 | nattype.status = PURPLE_STUN_STATUS_UNDISCOVERED; |
|
12909
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12877
diff
changeset
|
358 | nattype.lookup_time = time(NULL); |
|
37452
dafefd7bb115
This should do it for the libpurple dns stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37227
diff
changeset
|
359 | |
|
12909
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12877
diff
changeset
|
360 | do_callbacks(); |
|
37452
dafefd7bb115
This should do it for the libpurple dns stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37227
diff
changeset
|
361 | |
|
12909
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12877
diff
changeset
|
362 | return; |
|
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12877
diff
changeset
|
363 | } |
|
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12877
diff
changeset
|
364 | |
|
37469
f238b0a5ee69
Masca has some good eyes
Gary Kramlich <grim@reaperworld.com>
parents:
37465
diff
changeset
|
365 | ld->port = GPOINTER_TO_INT(data); |
|
37465
2b3189543b1f
Clean up some gross I forgot about
Gary Kramlich <grim@reaperworld.com>
parents:
37452
diff
changeset
|
366 | if (!purple_network_listen_range(12108, 12208, AF_UNSPEC, SOCK_DGRAM, TRUE, hbn_listen_cb, ld)) { |
| 15884 | 367 | nattype.status = PURPLE_STUN_STATUS_UNKNOWN; |
|
12909
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12877
diff
changeset
|
368 | nattype.lookup_time = time(NULL); |
|
37452
dafefd7bb115
This should do it for the libpurple dns stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37227
diff
changeset
|
369 | |
|
12909
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12877
diff
changeset
|
370 | do_callbacks(); |
|
37452
dafefd7bb115
This should do it for the libpurple dns stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37227
diff
changeset
|
371 | |
|
12909
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12877
diff
changeset
|
372 | return; |
|
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12877
diff
changeset
|
373 | } |
|
37452
dafefd7bb115
This should do it for the libpurple dns stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37227
diff
changeset
|
374 | } |
|
dafefd7bb115
This should do it for the libpurple dns stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37227
diff
changeset
|
375 | |
|
dafefd7bb115
This should do it for the libpurple dns stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37227
diff
changeset
|
376 | static void |
|
dafefd7bb115
This should do it for the libpurple dns stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37227
diff
changeset
|
377 | do_test1(GObject *sender, GAsyncResult *res, gpointer data) { |
|
dafefd7bb115
This should do it for the libpurple dns stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37227
diff
changeset
|
378 | GList *services = NULL; |
|
dafefd7bb115
This should do it for the libpurple dns stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37227
diff
changeset
|
379 | GError *error = NULL; |
|
37518
53c9ebedf2b7
Plug g_resolver_get_default() leaks
Mike Ruprecht <cmaiku@gmail.com>
parents:
37517
diff
changeset
|
380 | GResolver *resolver; |
|
37452
dafefd7bb115
This should do it for the libpurple dns stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37227
diff
changeset
|
381 | const char *servername = data; |
|
dafefd7bb115
This should do it for the libpurple dns stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37227
diff
changeset
|
382 | int port = 3478; |
|
dafefd7bb115
This should do it for the libpurple dns stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37227
diff
changeset
|
383 | |
|
37517
a67be31f9c7e
Use the GResolver which was passed to g_resolver_lookup_*_async()
Mike Ruprecht <cmaiku@gmail.com>
parents:
37469
diff
changeset
|
384 | services = g_resolver_lookup_service_finish(G_RESOLVER(sender), |
|
a67be31f9c7e
Use the GResolver which was passed to g_resolver_lookup_*_async()
Mike Ruprecht <cmaiku@gmail.com>
parents:
37469
diff
changeset
|
385 | res, &error); |
|
37452
dafefd7bb115
This should do it for the libpurple dns stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37227
diff
changeset
|
386 | if(error != NULL) { |
|
dafefd7bb115
This should do it for the libpurple dns stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37227
diff
changeset
|
387 | purple_debug_info("stun", "Failed to look up srv record : %s\n", error->message); |
|
dafefd7bb115
This should do it for the libpurple dns stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37227
diff
changeset
|
388 | |
|
dafefd7bb115
This should do it for the libpurple dns stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37227
diff
changeset
|
389 | g_error_free(error); |
|
dafefd7bb115
This should do it for the libpurple dns stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37227
diff
changeset
|
390 | } else { |
|
dafefd7bb115
This should do it for the libpurple dns stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37227
diff
changeset
|
391 | servername = g_srv_target_get_hostname((GSrvTarget *)services->data); |
|
dafefd7bb115
This should do it for the libpurple dns stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37227
diff
changeset
|
392 | port = g_srv_target_get_port((GSrvTarget *)services->data); |
|
dafefd7bb115
This should do it for the libpurple dns stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37227
diff
changeset
|
393 | } |
|
12909
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12877
diff
changeset
|
394 | |
|
37452
dafefd7bb115
This should do it for the libpurple dns stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37227
diff
changeset
|
395 | purple_debug_info("stun", "connecting to %s:%d\n", servername, port); |
|
11431
60971f504319
[gaim-migrate @ 13668]
Daniel Atallah <datallah@pidgin.im>
parents:
11429
diff
changeset
|
396 | |
|
37518
53c9ebedf2b7
Plug g_resolver_get_default() leaks
Mike Ruprecht <cmaiku@gmail.com>
parents:
37517
diff
changeset
|
397 | resolver = g_resolver_get_default(); |
|
53c9ebedf2b7
Plug g_resolver_get_default() leaks
Mike Ruprecht <cmaiku@gmail.com>
parents:
37517
diff
changeset
|
398 | g_resolver_lookup_by_name_async(resolver, |
|
37452
dafefd7bb115
This should do it for the libpurple dns stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37227
diff
changeset
|
399 | servername, |
|
dafefd7bb115
This should do it for the libpurple dns stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37227
diff
changeset
|
400 | NULL, |
|
dafefd7bb115
This should do it for the libpurple dns stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37227
diff
changeset
|
401 | hbn_cb, |
|
dafefd7bb115
This should do it for the libpurple dns stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37227
diff
changeset
|
402 | GINT_TO_POINTER(port)); |
|
37518
53c9ebedf2b7
Plug g_resolver_get_default() leaks
Mike Ruprecht <cmaiku@gmail.com>
parents:
37517
diff
changeset
|
403 | g_object_unref(resolver); |
|
11429
3f7f01e88e77
[gaim-migrate @ 13666]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11425
diff
changeset
|
404 | |
|
37452
dafefd7bb115
This should do it for the libpurple dns stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37227
diff
changeset
|
405 | g_resolver_free_targets(services); |
|
11225
e888c207b994
[gaim-migrate @ 13361]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff
changeset
|
406 | } |
|
11424
b0f8535daa74
[gaim-migrate @ 13661]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11371
diff
changeset
|
407 | |
|
12756
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
408 | static gboolean call_callback(gpointer data) { |
|
35499
c4c5e0a670b1
Fix namespaces issues in libpurple.
Ankit Vani <a@nevitus.org>
parents:
35466
diff
changeset
|
409 | PurpleStunCallback cb = data; |
|
12756
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
410 | cb(&nattype); |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
411 | return FALSE; |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
412 | } |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
413 | |
|
35499
c4c5e0a670b1
Fix namespaces issues in libpurple.
Ankit Vani <a@nevitus.org>
parents:
35466
diff
changeset
|
414 | PurpleStunNatDiscovery *purple_stun_discover(PurpleStunCallback cb) { |
|
16478
19107605c565
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@pidgin.im>
parents:
15884
diff
changeset
|
415 | const char *servername = purple_prefs_get_string("/purple/network/stun_server"); |
|
37518
53c9ebedf2b7
Plug g_resolver_get_default() leaks
Mike Ruprecht <cmaiku@gmail.com>
parents:
37517
diff
changeset
|
416 | GResolver *resolver; |
|
11424
b0f8535daa74
[gaim-migrate @ 13661]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11371
diff
changeset
|
417 | |
| 15884 | 418 | purple_debug_info("stun", "using server %s\n", servername); |
|
12686
ec3e7c4ff045
[gaim-migrate @ 15029]
Richard Laager <rlaager@pidgin.im>
parents:
11898
diff
changeset
|
419 | |
| 15884 | 420 | if(nattype.status == PURPLE_STUN_STATUS_DISCOVERING) { |
|
12686
ec3e7c4ff045
[gaim-migrate @ 15029]
Richard Laager <rlaager@pidgin.im>
parents:
11898
diff
changeset
|
421 | if(cb) |
|
ec3e7c4ff045
[gaim-migrate @ 15029]
Richard Laager <rlaager@pidgin.im>
parents:
11898
diff
changeset
|
422 | callbacks = g_slist_append(callbacks, cb); |
|
12756
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
423 | return &nattype; |
|
11424
b0f8535daa74
[gaim-migrate @ 13661]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11371
diff
changeset
|
424 | } |
|
12686
ec3e7c4ff045
[gaim-migrate @ 15029]
Richard Laager <rlaager@pidgin.im>
parents:
11898
diff
changeset
|
425 | |
| 15884 | 426 | if(nattype.status != PURPLE_STUN_STATUS_UNDISCOVERED) { |
|
12756
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
427 | gboolean use_cached_result = TRUE; |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
428 | |
|
35466
e259e75f1c6f
Fix some gtk-doc warnings till xmlnode.h
Ankit Vani <a@nevitus.org>
parents:
35454
diff
changeset
|
429 | /* Deal with the server name having changed since we did the |
|
e259e75f1c6f
Fix some gtk-doc warnings till xmlnode.h
Ankit Vani <a@nevitus.org>
parents:
35454
diff
changeset
|
430 | lookup */ |
|
12756
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
431 | if (servername && strlen(servername) > 1 |
|
25859
b42be7bb9dac
Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <darkrain42@pidgin.im>
parents:
22104
diff
changeset
|
432 | && !purple_strequal(servername, nattype.servername)) { |
|
12756
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
433 | use_cached_result = FALSE; |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
434 | } |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
435 | |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
436 | /* If we don't have a successful status and it has been 5 |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
437 | minutes since we last did a lookup, redo the lookup */ |
| 15884 | 438 | if (nattype.status != PURPLE_STUN_STATUS_DISCOVERED |
|
12756
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
439 | && (time(NULL) - nattype.lookup_time) > 300) { |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
440 | use_cached_result = FALSE; |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
441 | } |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
442 | |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
443 | if (use_cached_result) { |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
444 | if(cb) |
| 15884 | 445 | purple_timeout_add(10, call_callback, cb); |
|
12756
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
446 | return &nattype; |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
447 | } |
|
11424
b0f8535daa74
[gaim-migrate @ 13661]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11371
diff
changeset
|
448 | } |
|
b0f8535daa74
[gaim-migrate @ 13661]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11371
diff
changeset
|
449 | |
|
12686
ec3e7c4ff045
[gaim-migrate @ 15029]
Richard Laager <rlaager@pidgin.im>
parents:
11898
diff
changeset
|
450 | if(!servername || (strlen(servername) < 2)) { |
| 15884 | 451 | nattype.status = PURPLE_STUN_STATUS_UNKNOWN; |
|
12756
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
452 | nattype.lookup_time = time(NULL); |
|
12686
ec3e7c4ff045
[gaim-migrate @ 15029]
Richard Laager <rlaager@pidgin.im>
parents:
11898
diff
changeset
|
453 | if(cb) |
| 15884 | 454 | purple_timeout_add(10, call_callback, cb); |
|
11424
b0f8535daa74
[gaim-migrate @ 13661]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11371
diff
changeset
|
455 | return &nattype; |
|
b0f8535daa74
[gaim-migrate @ 13661]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11371
diff
changeset
|
456 | } |
|
12756
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
457 | |
| 15884 | 458 | nattype.status = PURPLE_STUN_STATUS_DISCOVERING; |
|
12756
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
459 | nattype.publicip[0] = '\0'; |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
460 | g_free(nattype.servername); |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
461 | nattype.servername = g_strdup(servername); |
|
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
462 | |
|
11424
b0f8535daa74
[gaim-migrate @ 13661]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11371
diff
changeset
|
463 | callbacks = g_slist_append(callbacks, cb); |
|
37452
dafefd7bb115
This should do it for the libpurple dns stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37227
diff
changeset
|
464 | |
|
37518
53c9ebedf2b7
Plug g_resolver_get_default() leaks
Mike Ruprecht <cmaiku@gmail.com>
parents:
37517
diff
changeset
|
465 | resolver = g_resolver_get_default(); |
|
53c9ebedf2b7
Plug g_resolver_get_default() leaks
Mike Ruprecht <cmaiku@gmail.com>
parents:
37517
diff
changeset
|
466 | g_resolver_lookup_service_async(resolver, |
|
37452
dafefd7bb115
This should do it for the libpurple dns stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37227
diff
changeset
|
467 | "stun", |
|
dafefd7bb115
This should do it for the libpurple dns stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37227
diff
changeset
|
468 | "udp", |
|
dafefd7bb115
This should do it for the libpurple dns stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37227
diff
changeset
|
469 | servername, |
|
dafefd7bb115
This should do it for the libpurple dns stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37227
diff
changeset
|
470 | NULL, |
|
dafefd7bb115
This should do it for the libpurple dns stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37227
diff
changeset
|
471 | do_test1, |
|
dafefd7bb115
This should do it for the libpurple dns stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37227
diff
changeset
|
472 | (gpointer)servername); |
|
37518
53c9ebedf2b7
Plug g_resolver_get_default() leaks
Mike Ruprecht <cmaiku@gmail.com>
parents:
37517
diff
changeset
|
473 | g_object_unref(resolver); |
|
12756
b8df02e0c6e5
[gaim-migrate @ 15103]
Daniel Atallah <datallah@pidgin.im>
parents:
12700
diff
changeset
|
474 | |
|
11424
b0f8535daa74
[gaim-migrate @ 13661]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11371
diff
changeset
|
475 | return &nattype; |
|
b0f8535daa74
[gaim-migrate @ 13661]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11371
diff
changeset
|
476 | } |
|
b0f8535daa74
[gaim-migrate @ 13661]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11371
diff
changeset
|
477 | |
| 15884 | 478 | void purple_stun_init() { |
|
16478
19107605c565
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@pidgin.im>
parents:
15884
diff
changeset
|
479 | purple_prefs_add_string("/purple/network/stun_server", ""); |
|
11424
b0f8535daa74
[gaim-migrate @ 13661]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11371
diff
changeset
|
480 | } |