libpurple/nat-pmp.c

Thu, 25 Aug 2022 21:34:53 -0500

author
Gary Kramlich <grim@reaperworld.com>
date
Thu, 25 Aug 2022 21:34:53 -0500
branch
gtk4
changeset 41591
ad6f5ffc2825
parent 41083
590d533cf290
child 41840
fe350460fb1c
permissions
-rw-r--r--

Port the invite dialog to GTK4

Testing Done:
Opened the dialog via conversations -> invite and made sure it worked as expected.

Reviewed at https://reviews.imfreedom.org/r/1644/

20147
66f05a854eee applied changes from 8a731bbd0197fbcc91a705c2d8f528154216defa
Richard Laager <rlaager@pidgin.im>
parents: 19832
diff changeset
1 /* purple
15708
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
2 *
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15708
diff changeset
3 * Purple is the legal property of its developers, whose names are too numerous
15708
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
4 * to list here. Please refer to the COPYRIGHT file distributed with this
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
5 * source distribution.
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
6 *
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
7 * Most code in nat-pmp.c copyright (C) 2007, R. Tyler Ballance, bleep, LLC.
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
8 * This file is distributed under the 3-clause (modified) BSD license:
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
9 * Redistribution and use in source and binary forms, with or without modification, are permitted
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
10 * provided that the following conditions are met:
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
11 *
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
12 * Redistributions of source code must retain the above copyright notice, this list of conditions and
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
13 * the following disclaimer.
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
14 * Neither the name of the bleep. LLC nor the names of its contributors may be used to endorse or promote
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
15 * products derived from this software without specific prior written permission.
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
16 *
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
19 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
20 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
21 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
23 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
24 * OF SUCH DAMAGE.
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
25 */
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
26
37489
cbf9ccc715ab Move everything in libpurple that was using the network-changed signal to use the gio one
Gary Kramlich <grim@reaperworld.com>
parents: 35454
diff changeset
27 #include <gio/gio.h>
cbf9ccc715ab Move everything in libpurple that was using the network-changed signal to use the gio one
Gary Kramlich <grim@reaperworld.com>
parents: 35454
diff changeset
28
28981
4e3922ab4844 Include 'internal.h' before all other headers to make some non-gcc compilers happy.
Paul Aurich <darkrain42@pidgin.im>
parents: 27149
diff changeset
29 #include "internal.h"
15708
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
30 #include "nat-pmp.h"
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
31 #include "debug.h"
16035
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
32 #include "signals.h"
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
33 #include "network.h"
15708
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
34
40512
05663def7b82 Fix some easy compiler warnings
Gary Kramlich <grim@reaperworld.com>
parents: 37489
diff changeset
35 #include <sys/types.h>
23518
228c316f1323 Some header inclusion fixes to help on NetBSD/FreeBSD.
Richard Laager <rlaager@pidgin.im>
parents: 23352
diff changeset
36
16965
d3df125b3196 I expanded your patch, Richard, to also do appropriate header checking in the configure script and then use that information. I removed some other #includes which don't appear to be needed.
Evan Schoenberg <evands@pidgin.im>
parents: 16964
diff changeset
37 #ifdef HAVE_SYS_SYSCTL_H
40512
05663def7b82 Fix some easy compiler warnings
Gary Kramlich <grim@reaperworld.com>
parents: 37489
diff changeset
38 # include <sys/sysctl.h>
16036
d74e95743ae1 fix win32 build for nat-pmp stuff. I haven't tested it, but it compiles.
Daniel Atallah <datallah@pidgin.im>
parents: 16035
diff changeset
39 #endif
d74e95743ae1 fix win32 build for nat-pmp stuff. I haven't tested it, but it compiles.
Daniel Atallah <datallah@pidgin.im>
parents: 16035
diff changeset
40
16965
d3df125b3196 I expanded your patch, Richard, to also do appropriate header checking in the configure script and then use that information. I removed some other #includes which don't appear to be needed.
Evan Schoenberg <evands@pidgin.im>
parents: 16964
diff changeset
41 #ifdef HAVE_SYS_SOCKET_H
40512
05663def7b82 Fix some easy compiler warnings
Gary Kramlich <grim@reaperworld.com>
parents: 37489
diff changeset
42 # include <sys/socket.h>
16965
d3df125b3196 I expanded your patch, Richard, to also do appropriate header checking in the configure script and then use that information. I removed some other #includes which don't appear to be needed.
Evan Schoenberg <evands@pidgin.im>
parents: 16964
diff changeset
43 #endif
15708
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
44
16965
d3df125b3196 I expanded your patch, Richard, to also do appropriate header checking in the configure script and then use that information. I removed some other #includes which don't appear to be needed.
Evan Schoenberg <evands@pidgin.im>
parents: 16964
diff changeset
45 /* We will need sysctl() and NET_RT_DUMP, both of which are not present
d3df125b3196 I expanded your patch, Richard, to also do appropriate header checking in the configure script and then use that information. I removed some other #includes which don't appear to be needed.
Evan Schoenberg <evands@pidgin.im>
parents: 16964
diff changeset
46 * on all platforms, to continue. */
d3df125b3196 I expanded your patch, Richard, to also do appropriate header checking in the configure script and then use that information. I removed some other #includes which don't appear to be needed.
Evan Schoenberg <evands@pidgin.im>
parents: 16964
diff changeset
47 #if defined(HAVE_SYS_SYSCTL_H) && defined(NET_RT_DUMP)
15708
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
48
16965
d3df125b3196 I expanded your patch, Richard, to also do appropriate header checking in the configure script and then use that information. I removed some other #includes which don't appear to be needed.
Evan Schoenberg <evands@pidgin.im>
parents: 16964
diff changeset
49 #include <net/route.h>
15933
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
50
15968
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
51 #define PMP_DEBUG 1
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
52
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
53 typedef struct {
16964
564274a64f4b Change the nat-pmp code to use glib's integer types instead of those from
Richard Laager <rlaager@pidgin.im>
parents: 16413
diff changeset
54 guint8 version;
564274a64f4b Change the nat-pmp code to use glib's integer types instead of those from
Richard Laager <rlaager@pidgin.im>
parents: 16413
diff changeset
55 guint8 opcode;
15968
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
56 } PurplePmpIpRequest;
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
57
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
58 typedef struct {
16964
564274a64f4b Change the nat-pmp code to use glib's integer types instead of those from
Richard Laager <rlaager@pidgin.im>
parents: 16413
diff changeset
59 guint8 version;
564274a64f4b Change the nat-pmp code to use glib's integer types instead of those from
Richard Laager <rlaager@pidgin.im>
parents: 16413
diff changeset
60 guint8 opcode; /* 128 + n */
564274a64f4b Change the nat-pmp code to use glib's integer types instead of those from
Richard Laager <rlaager@pidgin.im>
parents: 16413
diff changeset
61 guint16 resultcode;
564274a64f4b Change the nat-pmp code to use glib's integer types instead of those from
Richard Laager <rlaager@pidgin.im>
parents: 16413
diff changeset
62 guint32 epoch;
564274a64f4b Change the nat-pmp code to use glib's integer types instead of those from
Richard Laager <rlaager@pidgin.im>
parents: 16413
diff changeset
63 guint32 address;
15968
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
64 } PurplePmpIpResponse;
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
65
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
66 typedef struct {
16964
564274a64f4b Change the nat-pmp code to use glib's integer types instead of those from
Richard Laager <rlaager@pidgin.im>
parents: 16413
diff changeset
67 guint8 version;
564274a64f4b Change the nat-pmp code to use glib's integer types instead of those from
Richard Laager <rlaager@pidgin.im>
parents: 16413
diff changeset
68 guint8 opcode;
15968
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
69 char reserved[2];
16964
564274a64f4b Change the nat-pmp code to use glib's integer types instead of those from
Richard Laager <rlaager@pidgin.im>
parents: 16413
diff changeset
70 guint16 privateport;
564274a64f4b Change the nat-pmp code to use glib's integer types instead of those from
Richard Laager <rlaager@pidgin.im>
parents: 16413
diff changeset
71 guint16 publicport;
564274a64f4b Change the nat-pmp code to use glib's integer types instead of those from
Richard Laager <rlaager@pidgin.im>
parents: 16413
diff changeset
72 guint32 lifetime;
15968
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
73 } PurplePmpMapRequest;
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
74
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
75 struct _PurplePmpMapResponse {
16964
564274a64f4b Change the nat-pmp code to use glib's integer types instead of those from
Richard Laager <rlaager@pidgin.im>
parents: 16413
diff changeset
76 guint8 version;
564274a64f4b Change the nat-pmp code to use glib's integer types instead of those from
Richard Laager <rlaager@pidgin.im>
parents: 16413
diff changeset
77 guint8 opcode;
564274a64f4b Change the nat-pmp code to use glib's integer types instead of those from
Richard Laager <rlaager@pidgin.im>
parents: 16413
diff changeset
78 guint16 resultcode;
564274a64f4b Change the nat-pmp code to use glib's integer types instead of those from
Richard Laager <rlaager@pidgin.im>
parents: 16413
diff changeset
79 guint32 epoch;
564274a64f4b Change the nat-pmp code to use glib's integer types instead of those from
Richard Laager <rlaager@pidgin.im>
parents: 16413
diff changeset
80 guint16 privateport;
564274a64f4b Change the nat-pmp code to use glib's integer types instead of those from
Richard Laager <rlaager@pidgin.im>
parents: 16413
diff changeset
81 guint16 publicport;
564274a64f4b Change the nat-pmp code to use glib's integer types instead of those from
Richard Laager <rlaager@pidgin.im>
parents: 16413
diff changeset
82 guint32 lifetime;
15968
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
83 };
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
84
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
85 typedef struct _PurplePmpMapResponse PurplePmpMapResponse;
15933
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
86
16035
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
87 typedef enum {
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
88 PURPLE_PMP_STATUS_UNDISCOVERED = -1,
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
89 PURPLE_PMP_STATUS_UNABLE_TO_DISCOVER,
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
90 PURPLE_PMP_STATUS_DISCOVERING,
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
91 PURPLE_PMP_STATUS_DISCOVERED
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
92 } PurpleUPnPStatus;
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
93
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
94 typedef struct {
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
95 PurpleUPnPStatus status;
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
96 gchar *publicip;
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
97 } PurplePmpInfo;
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
98
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
99 static PurplePmpInfo pmp_info = {PURPLE_PMP_STATUS_UNDISCOVERED, NULL};
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
100
15708
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
101 /*
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
102 * Thanks to R. Matthew Emerson for the fixes on this
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
103 */
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
104
15933
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
105 #define PMP_MAP_OPCODE_UDP 1
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
106 #define PMP_MAP_OPCODE_TCP 2
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
107
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
108 #define PMP_VERSION 0
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
109 #define PMP_PORT 5351
15968
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
110 #define PMP_TIMEOUT 250000 /* 250000 useconds */
15933
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
111
15708
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
112 /* alignment constraint for routing socket */
15933
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
113 #define ROUNDUP(a) ((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
114 #define ADVANCE(x, n) (x += ROUNDUP((n)->sa_len))
15708
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
115
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
116 static void
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
117 get_rtaddrs(int bitmask, struct sockaddr *sa, struct sockaddr *addrs[])
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
118 {
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
119 int i;
15970
0ad12ecb1fe3 Whitespace fixes
Evan Schoenberg <evands@pidgin.im>
parents: 15968
diff changeset
120
0ad12ecb1fe3 Whitespace fixes
Evan Schoenberg <evands@pidgin.im>
parents: 15968
diff changeset
121 for (i = 0; i < RTAX_MAX; i++)
15708
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
122 {
25888
d0fdd378a635 Remove trailing whitespace
Mark Doliner <markdoliner@pidgin.im>
parents: 23518
diff changeset
123 if (bitmask & (1 << i))
15708
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
124 {
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
125 addrs[i] = sa;
23352
9714223ca7a7 A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents: 22668
diff changeset
126 #ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
15708
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
127 sa = (struct sockaddr *)(ROUNDUP(sa->sa_len) + (char *)sa);
23352
9714223ca7a7 A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents: 22668
diff changeset
128 #else
9714223ca7a7 A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents: 22668
diff changeset
129 if (sa->sa_family == AF_INET)
9714223ca7a7 A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents: 22668
diff changeset
130 sa = (struct sockaddr*)(sizeof(struct sockaddr_in) + (char *)sa);
9714223ca7a7 A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents: 22668
diff changeset
131 #ifdef AF_INET6
9714223ca7a7 A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents: 22668
diff changeset
132 else if (sa->sa_family == AF_INET6)
9714223ca7a7 A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents: 22668
diff changeset
133 sa = (struct sockaddr*)(sizeof(struct sockaddr_in6) + (char *)sa);
9714223ca7a7 A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents: 22668
diff changeset
134 #endif
9714223ca7a7 A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents: 22668
diff changeset
135 #endif
25888
d0fdd378a635 Remove trailing whitespace
Mark Doliner <markdoliner@pidgin.im>
parents: 23518
diff changeset
136 }
15708
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
137 else
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
138 {
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
139 addrs[i] = NULL;
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
140 }
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
141 }
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
142 }
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
143
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
144 static int
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
145 is_default_route(struct sockaddr *sa, struct sockaddr *mask)
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
146 {
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
147 struct sockaddr_in *sin;
15970
0ad12ecb1fe3 Whitespace fixes
Evan Schoenberg <evands@pidgin.im>
parents: 15968
diff changeset
148
15708
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
149 if (sa->sa_family != AF_INET)
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
150 return 0;
15970
0ad12ecb1fe3 Whitespace fixes
Evan Schoenberg <evands@pidgin.im>
parents: 15968
diff changeset
151
15708
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
152 sin = (struct sockaddr_in *)sa;
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
153 if ((sin->sin_addr.s_addr == INADDR_ANY) &&
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
154 mask &&
40653
503cfa50c8c3 Use GLib's byte-order macros.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40512
diff changeset
155 (g_ntohl(((struct sockaddr_in *)mask)->sin_addr.s_addr) == 0L ||
23352
9714223ca7a7 A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents: 22668
diff changeset
156 #ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
9714223ca7a7 A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents: 22668
diff changeset
157 mask->sa_len == 0
9714223ca7a7 A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents: 22668
diff changeset
158 #else
9714223ca7a7 A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents: 22668
diff changeset
159 0
9714223ca7a7 A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents: 22668
diff changeset
160 #endif
9714223ca7a7 A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents: 22668
diff changeset
161 ))
15708
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
162 return 1;
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
163 else
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
164 return 0;
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
165 }
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
166
15933
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
167 /*!
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
168 * The return sockaddr_in must be g_free()'d when no longer needed
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
169 */
15708
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
170 static struct sockaddr_in *
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
171 default_gw()
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
172 {
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
173 int mib[6];
32012
7130f41f3fd5 Fix formatting by a third grader with a crayon
Ethan Blanton <elb@pidgin.im>
parents: 32011
diff changeset
174 size_t needed;
7130f41f3fd5 Fix formatting by a third grader with a crayon
Ethan Blanton <elb@pidgin.im>
parents: 32011
diff changeset
175 char *buf, *next, *lim;
7130f41f3fd5 Fix formatting by a third grader with a crayon
Ethan Blanton <elb@pidgin.im>
parents: 32011
diff changeset
176 struct rt_msghdr *rtm;
7130f41f3fd5 Fix formatting by a third grader with a crayon
Ethan Blanton <elb@pidgin.im>
parents: 32011
diff changeset
177 struct sockaddr *sa;
15933
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
178 struct sockaddr_in *sin = NULL;
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
179
32012
7130f41f3fd5 Fix formatting by a third grader with a crayon
Ethan Blanton <elb@pidgin.im>
parents: 32011
diff changeset
180 mib[0] = CTL_NET;
7130f41f3fd5 Fix formatting by a third grader with a crayon
Ethan Blanton <elb@pidgin.im>
parents: 32011
diff changeset
181 mib[1] = PF_ROUTE; /* entire routing table or a subset of it */
7130f41f3fd5 Fix formatting by a third grader with a crayon
Ethan Blanton <elb@pidgin.im>
parents: 32011
diff changeset
182 mib[2] = 0; /* protocol number - always 0 */
41083
590d533cf290 Fix several typos in libpurple
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40653
diff changeset
183 mib[3] = 0; /* address family - 0 for all address families */
32012
7130f41f3fd5 Fix formatting by a third grader with a crayon
Ethan Blanton <elb@pidgin.im>
parents: 32011
diff changeset
184 mib[4] = NET_RT_DUMP;
7130f41f3fd5 Fix formatting by a third grader with a crayon
Ethan Blanton <elb@pidgin.im>
parents: 32011
diff changeset
185 mib[5] = 0;
15970
0ad12ecb1fe3 Whitespace fixes
Evan Schoenberg <evands@pidgin.im>
parents: 15968
diff changeset
186
15933
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
187 /* Determine the buffer side needed to get the full routing table */
32012
7130f41f3fd5 Fix formatting by a third grader with a crayon
Ethan Blanton <elb@pidgin.im>
parents: 32011
diff changeset
188 if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0)
15708
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
189 {
19832
84b69b21672b Patch from QuLogic. Fixes #2903 ('Missing newlines in debug messages.')
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19387
diff changeset
190 purple_debug_warning("nat-pmp", "sysctl: net.route.0.0.dump estimate\n");
15933
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
191 return NULL;
32012
7130f41f3fd5 Fix formatting by a third grader with a crayon
Ethan Blanton <elb@pidgin.im>
parents: 32011
diff changeset
192 }
15970
0ad12ecb1fe3 Whitespace fixes
Evan Schoenberg <evands@pidgin.im>
parents: 15968
diff changeset
193
32012
7130f41f3fd5 Fix formatting by a third grader with a crayon
Ethan Blanton <elb@pidgin.im>
parents: 32011
diff changeset
194 if (!(buf = malloc(needed)))
15708
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
195 {
27149
f8462e36cb98 Fix two warnings when building on OS X
Paul Aurich <darkrain42@pidgin.im>
parents: 25888
diff changeset
196 purple_debug_warning("nat-pmp", "Failed to malloc %" G_GSIZE_FORMAT "\n", needed);
15933
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
197 return NULL;
32012
7130f41f3fd5 Fix formatting by a third grader with a crayon
Ethan Blanton <elb@pidgin.im>
parents: 32011
diff changeset
198 }
15970
0ad12ecb1fe3 Whitespace fixes
Evan Schoenberg <evands@pidgin.im>
parents: 15968
diff changeset
199
15933
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
200 /* Read the routing table into buf */
32012
7130f41f3fd5 Fix formatting by a third grader with a crayon
Ethan Blanton <elb@pidgin.im>
parents: 32011
diff changeset
201 if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0)
15708
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
202 {
32011
52500fc83dc3 Rationalize nat_pmp.c:default_gw() and free leaked buffer.
Ethan Blanton <elb@pidgin.im>
parents: 28981
diff changeset
203 free(buf);
19832
84b69b21672b Patch from QuLogic. Fixes #2903 ('Missing newlines in debug messages.')
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19387
diff changeset
204 purple_debug_warning("nat-pmp", "sysctl: net.route.0.0.dump\n");
15933
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
205 return NULL;
32012
7130f41f3fd5 Fix formatting by a third grader with a crayon
Ethan Blanton <elb@pidgin.im>
parents: 32011
diff changeset
206 }
15970
0ad12ecb1fe3 Whitespace fixes
Evan Schoenberg <evands@pidgin.im>
parents: 15968
diff changeset
207
32012
7130f41f3fd5 Fix formatting by a third grader with a crayon
Ethan Blanton <elb@pidgin.im>
parents: 32011
diff changeset
208 lim = buf + needed;
15970
0ad12ecb1fe3 Whitespace fixes
Evan Schoenberg <evands@pidgin.im>
parents: 15968
diff changeset
209
32012
7130f41f3fd5 Fix formatting by a third grader with a crayon
Ethan Blanton <elb@pidgin.im>
parents: 32011
diff changeset
210 for (next = buf; next < lim; next += rtm->rtm_msglen)
15708
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
211 {
16014
9ee607a29a8c Using rt_msghdr instead of rt_msghdr2 compiles on a greater number of systems -- specifically Mac OS X 10.3.x, in addition to the previous compilation on OS X 10.4.x and above -- and seems to work just as well. If anyone knows how the use of these seemingly very similar structs differs, enlightenment would be appreciated.
Evan Schoenberg <evands@pidgin.im>
parents: 15984
diff changeset
212 rtm = (struct rt_msghdr *)next;
15708
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
213 sa = (struct sockaddr *)(rtm + 1);
25888
d0fdd378a635 Remove trailing whitespace
Mark Doliner <markdoliner@pidgin.im>
parents: 23518
diff changeset
214
d0fdd378a635 Remove trailing whitespace
Mark Doliner <markdoliner@pidgin.im>
parents: 23518
diff changeset
215 if (sa->sa_family == AF_INET)
15708
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
216 {
32011
52500fc83dc3 Rationalize nat_pmp.c:default_gw() and free leaked buffer.
Ethan Blanton <elb@pidgin.im>
parents: 28981
diff changeset
217 struct sockaddr_in *cursin = (struct sockaddr_in*) sa;
15933
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
218
32011
52500fc83dc3 Rationalize nat_pmp.c:default_gw() and free leaked buffer.
Ethan Blanton <elb@pidgin.im>
parents: 28981
diff changeset
219 if ((rtm->rtm_flags & RTF_GATEWAY)
52500fc83dc3 Rationalize nat_pmp.c:default_gw() and free leaked buffer.
Ethan Blanton <elb@pidgin.im>
parents: 28981
diff changeset
220 && cursin->sin_addr.s_addr == INADDR_ANY)
15708
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
221 {
15933
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
222 /* We found the default route. Now get the destination address and netmask. */
32012
7130f41f3fd5 Fix formatting by a third grader with a crayon
Ethan Blanton <elb@pidgin.im>
parents: 32011
diff changeset
223 struct sockaddr *rti_info[RTAX_MAX];
15933
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
224 struct sockaddr addr, mask;
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
225
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
226 get_rtaddrs(rtm->rtm_addrs, sa, rti_info);
19387
8dc4480381f3 bcopy and bzero shouldn't be used. This allows Alver to compile nat-pmp.c on one of his obscure systems (and I fixed some other stuff that I noticed at the same time).
Daniel Atallah <datallah@pidgin.im>
parents: 16965
diff changeset
227 memset(&addr, 0, sizeof(addr));
15970
0ad12ecb1fe3 Whitespace fixes
Evan Schoenberg <evands@pidgin.im>
parents: 15968
diff changeset
228
15933
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
229 if (rtm->rtm_addrs & RTA_DST)
19387
8dc4480381f3 bcopy and bzero shouldn't be used. This allows Alver to compile nat-pmp.c on one of his obscure systems (and I fixed some other stuff that I noticed at the same time).
Daniel Atallah <datallah@pidgin.im>
parents: 16965
diff changeset
230 memcpy(&addr, rti_info[RTAX_DST], sizeof(addr));
15970
0ad12ecb1fe3 Whitespace fixes
Evan Schoenberg <evands@pidgin.im>
parents: 15968
diff changeset
231
19387
8dc4480381f3 bcopy and bzero shouldn't be used. This allows Alver to compile nat-pmp.c on one of his obscure systems (and I fixed some other stuff that I noticed at the same time).
Daniel Atallah <datallah@pidgin.im>
parents: 16965
diff changeset
232 memset(&mask, 0, sizeof(mask));
15970
0ad12ecb1fe3 Whitespace fixes
Evan Schoenberg <evands@pidgin.im>
parents: 15968
diff changeset
233
15933
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
234 if (rtm->rtm_addrs & RTA_NETMASK)
19387
8dc4480381f3 bcopy and bzero shouldn't be used. This allows Alver to compile nat-pmp.c on one of his obscure systems (and I fixed some other stuff that I noticed at the same time).
Daniel Atallah <datallah@pidgin.im>
parents: 16965
diff changeset
235 memcpy(&mask, rti_info[RTAX_NETMASK], sizeof(mask));
15970
0ad12ecb1fe3 Whitespace fixes
Evan Schoenberg <evands@pidgin.im>
parents: 15968
diff changeset
236
15933
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
237 if (rtm->rtm_addrs & RTA_GATEWAY &&
25888
d0fdd378a635 Remove trailing whitespace
Mark Doliner <markdoliner@pidgin.im>
parents: 23518
diff changeset
238 is_default_route(&addr, &mask))
19387
8dc4480381f3 bcopy and bzero shouldn't be used. This allows Alver to compile nat-pmp.c on one of his obscure systems (and I fixed some other stuff that I noticed at the same time).
Daniel Atallah <datallah@pidgin.im>
parents: 16965
diff changeset
239 {
15933
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
240 if (rti_info[RTAX_GATEWAY]) {
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
241 struct sockaddr_in *rti_sin = (struct sockaddr_in *)rti_info[RTAX_GATEWAY];
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
242 sin = g_new0(struct sockaddr_in, 1);
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
243 sin->sin_family = rti_sin->sin_family;
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
244 sin->sin_port = rti_sin->sin_port;
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
245 sin->sin_addr.s_addr = rti_sin->sin_addr.s_addr;
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
246 memcpy(sin, rti_info[RTAX_GATEWAY], sizeof(struct sockaddr_in));
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
247
22668
d57f88274300 Improved some of the debug output from nat-pmp
Evan Schoenberg <evands@pidgin.im>
parents: 21389
diff changeset
248 purple_debug_info("nat-pmp", "Found a default gateway\n");
15933
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
249 break;
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
250 }
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
251 }
15708
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
252 }
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
253 }
32012
7130f41f3fd5 Fix formatting by a third grader with a crayon
Ethan Blanton <elb@pidgin.im>
parents: 32011
diff changeset
254 }
15933
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
255
32011
52500fc83dc3 Rationalize nat_pmp.c:default_gw() and free leaked buffer.
Ethan Blanton <elb@pidgin.im>
parents: 28981
diff changeset
256 free(buf);
52500fc83dc3 Rationalize nat_pmp.c:default_gw() and free leaked buffer.
Ethan Blanton <elb@pidgin.im>
parents: 28981
diff changeset
257 return sin;
15708
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
258 }
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
259
15933
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
260 /*!
25888
d0fdd378a635 Remove trailing whitespace
Mark Doliner <markdoliner@pidgin.im>
parents: 23518
diff changeset
261 * purple_pmp_get_public_ip() will return the publicly facing IP address of the
15708
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
262 * default NAT gateway. The function will return NULL if:
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
263 * - The gateway doesn't support NAT-PMP
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
264 * - The gateway errors in some other spectacular fashion
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
265 */
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
266 char *
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15708
diff changeset
267 purple_pmp_get_public_ip()
15708
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
268 {
16035
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
269 struct sockaddr_in addr, *gateway, *publicsockaddr = NULL;
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
270 struct timeval req_timeout;
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
271 socklen_t len;
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
272
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
273 PurplePmpIpRequest req;
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
274 PurplePmpIpResponse resp;
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
275 int sendfd;
25888
d0fdd378a635 Remove trailing whitespace
Mark Doliner <markdoliner@pidgin.im>
parents: 23518
diff changeset
276
16035
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
277 if (pmp_info.status == PURPLE_PMP_STATUS_UNABLE_TO_DISCOVER)
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
278 return NULL;
25888
d0fdd378a635 Remove trailing whitespace
Mark Doliner <markdoliner@pidgin.im>
parents: 23518
diff changeset
279
16035
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
280 if ((pmp_info.status == PURPLE_PMP_STATUS_DISCOVERED) && (pmp_info.publicip != NULL))
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
281 {
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
282 #ifdef PMP_DEBUG
19832
84b69b21672b Patch from QuLogic. Fixes #2903 ('Missing newlines in debug messages.')
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19387
diff changeset
283 purple_debug_info("nat-pmp", "Returning cached publicip %s\n",pmp_info.publicip);
16035
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
284 #endif
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
285 return pmp_info.publicip;
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
286 }
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
287
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
288 gateway = default_gw();
15970
0ad12ecb1fe3 Whitespace fixes
Evan Schoenberg <evands@pidgin.im>
parents: 15968
diff changeset
289
15968
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
290 if (!gateway)
15708
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
291 {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15708
diff changeset
292 purple_debug_info("nat-pmp", "Cannot request public IP from a NULL gateway!\n");
16035
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
293 /* If we get a NULL gateway, don't try again next time */
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
294 pmp_info.status = PURPLE_PMP_STATUS_UNABLE_TO_DISCOVER;
15708
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
295 return NULL;
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
296 }
15968
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
297
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
298 /* Default port for NAT-PMP is 5351 */
15708
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
299 if (gateway->sin_port != PMP_PORT)
40653
503cfa50c8c3 Use GLib's byte-order macros.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40512
diff changeset
300 gateway->sin_port = g_htons(PMP_PORT);
15708
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
301
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
302 req_timeout.tv_sec = 0;
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
303 req_timeout.tv_usec = PMP_TIMEOUT;
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
304
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
305 sendfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
15970
0ad12ecb1fe3 Whitespace fixes
Evan Schoenberg <evands@pidgin.im>
parents: 15968
diff changeset
306
15968
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
307 /* Clean out both req and resp structures */
19387
8dc4480381f3 bcopy and bzero shouldn't be used. This allows Alver to compile nat-pmp.c on one of his obscure systems (and I fixed some other stuff that I noticed at the same time).
Daniel Atallah <datallah@pidgin.im>
parents: 16965
diff changeset
308 memset(&req, 0, sizeof(PurplePmpIpRequest));
8dc4480381f3 bcopy and bzero shouldn't be used. This allows Alver to compile nat-pmp.c on one of his obscure systems (and I fixed some other stuff that I noticed at the same time).
Daniel Atallah <datallah@pidgin.im>
parents: 16965
diff changeset
309 memset(&resp, 0, sizeof(PurplePmpIpResponse));
15708
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
310 req.version = 0;
19387
8dc4480381f3 bcopy and bzero shouldn't be used. This allows Alver to compile nat-pmp.c on one of his obscure systems (and I fixed some other stuff that I noticed at the same time).
Daniel Atallah <datallah@pidgin.im>
parents: 16965
diff changeset
311 req.opcode = 0;
15970
0ad12ecb1fe3 Whitespace fixes
Evan Schoenberg <evands@pidgin.im>
parents: 15968
diff changeset
312
15968
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
313 /* The NAT-PMP spec says we should attempt to contact the gateway 9 times, doubling the time we wait each time.
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
314 * Even starting with a timeout of 0.1 seconds, that means that we have a total waiting of 204.6 seconds.
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
315 * With the recommended timeout of 0.25 seconds, we're talking 511.5 seconds (8.5 minutes).
25888
d0fdd378a635 Remove trailing whitespace
Mark Doliner <markdoliner@pidgin.im>
parents: 23518
diff changeset
316 *
15968
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
317 * This seems really silly... if this were nonblocking, a couple retries might be in order, but it's not at present.
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
318 */
15708
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
319 #ifdef PMP_DEBUG
15968
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
320 purple_debug_info("nat-pmp", "Attempting to retrieve the public ip address for the NAT device at: %s\n", inet_ntoa(gateway->sin_addr));
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
321 purple_debug_info("nat-pmp", "\tTimeout: %ds %dus\n", req_timeout.tv_sec, req_timeout.tv_usec);
15708
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
322 #endif
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
323
15968
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
324 /* TODO: Non-blocking! */
25888
d0fdd378a635 Remove trailing whitespace
Mark Doliner <markdoliner@pidgin.im>
parents: 23518
diff changeset
325
15968
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
326 if (sendto(sendfd, &req, sizeof(req), 0, (struct sockaddr *)(gateway), sizeof(struct sockaddr)) < 0)
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
327 {
21389
e1dd8142bb87 replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 20147
diff changeset
328 purple_debug_info("nat-pmp", "There was an error sending the NAT-PMP public IP request! (%s)\n", g_strerror(errno));
15933
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
329 g_free(gateway);
16035
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
330 pmp_info.status = PURPLE_PMP_STATUS_UNABLE_TO_DISCOVER;
15708
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
331 return NULL;
15933
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
332 }
15968
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
333
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
334 if (setsockopt(sendfd, SOL_SOCKET, SO_RCVTIMEO, &req_timeout, sizeof(req_timeout)) < 0)
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
335 {
21389
e1dd8142bb87 replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 20147
diff changeset
336 purple_debug_info("nat-pmp", "There was an error setting the socket's options! (%s)\n", g_strerror(errno));
15968
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
337 g_free(gateway);
16035
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
338 pmp_info.status = PURPLE_PMP_STATUS_UNABLE_TO_DISCOVER;
15968
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
339 return NULL;
19387
8dc4480381f3 bcopy and bzero shouldn't be used. This allows Alver to compile nat-pmp.c on one of his obscure systems (and I fixed some other stuff that I noticed at the same time).
Daniel Atallah <datallah@pidgin.im>
parents: 16965
diff changeset
340 }
15968
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
341
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
342 /* TODO: Non-blocking! */
16035
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
343 len = sizeof(struct sockaddr_in);
15968
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
344 if (recvfrom(sendfd, &resp, sizeof(PurplePmpIpResponse), 0, (struct sockaddr *)(&addr), &len) < 0)
19387
8dc4480381f3 bcopy and bzero shouldn't be used. This allows Alver to compile nat-pmp.c on one of his obscure systems (and I fixed some other stuff that I noticed at the same time).
Daniel Atallah <datallah@pidgin.im>
parents: 16965
diff changeset
345 {
15968
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
346 if (errno != EAGAIN)
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
347 {
21389
e1dd8142bb87 replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 20147
diff changeset
348 purple_debug_info("nat-pmp", "There was an error receiving the response from the NAT-PMP device! (%s)\n", g_strerror(errno));
15968
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
349 g_free(gateway);
16035
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
350 pmp_info.status = PURPLE_PMP_STATUS_UNABLE_TO_DISCOVER;
15968
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
351 return NULL;
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
352 }
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
353 }
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
354
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
355 if (addr.sin_addr.s_addr == gateway->sin_addr.s_addr)
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
356 publicsockaddr = &addr;
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
357 else
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
358 {
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
359 purple_debug_info("nat-pmp", "Response was not received from our gateway! Instead from: %s\n", inet_ntoa(addr.sin_addr));
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
360 g_free(gateway);
16035
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
361
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
362 pmp_info.status = PURPLE_PMP_STATUS_UNABLE_TO_DISCOVER;
15968
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
363 return NULL;
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
364 }
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
365
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
366 if (!publicsockaddr) {
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
367 g_free(gateway);
25888
d0fdd378a635 Remove trailing whitespace
Mark Doliner <markdoliner@pidgin.im>
parents: 23518
diff changeset
368
16035
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
369 pmp_info.status = PURPLE_PMP_STATUS_UNABLE_TO_DISCOVER;
15968
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
370 return NULL;
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
371 }
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
372
15708
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
373 #ifdef PMP_DEBUG
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15708
diff changeset
374 purple_debug_info("nat-pmp", "Response received from NAT-PMP device:\n");
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15708
diff changeset
375 purple_debug_info("nat-pmp", "version: %d\n", resp.version);
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15708
diff changeset
376 purple_debug_info("nat-pmp", "opcode: %d\n", resp.opcode);
40653
503cfa50c8c3 Use GLib's byte-order macros.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40512
diff changeset
377 purple_debug_info("nat-pmp", "resultcode: %d\n", g_ntohs(resp.resultcode));
503cfa50c8c3 Use GLib's byte-order macros.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40512
diff changeset
378 purple_debug_info("nat-pmp", "epoch: %d\n", g_ntohl(resp.epoch));
15708
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
379 struct in_addr in;
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
380 in.s_addr = resp.address;
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15708
diff changeset
381 purple_debug_info("nat-pmp", "address: %s\n", inet_ntoa(in));
19387
8dc4480381f3 bcopy and bzero shouldn't be used. This allows Alver to compile nat-pmp.c on one of his obscure systems (and I fixed some other stuff that I noticed at the same time).
Daniel Atallah <datallah@pidgin.im>
parents: 16965
diff changeset
382 #endif
15708
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
383
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
384 publicsockaddr->sin_addr.s_addr = resp.address;
15933
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
385
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
386 g_free(gateway);
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
387
16035
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
388 g_free(pmp_info.publicip);
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
389 pmp_info.publicip = g_strdup(inet_ntoa(publicsockaddr->sin_addr));
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
390 pmp_info.status = PURPLE_PMP_STATUS_DISCOVERED;
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
391
15708
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
392 return inet_ntoa(publicsockaddr->sin_addr);
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
393 }
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
394
15968
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
395 gboolean
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
396 purple_pmp_create_map(PurplePmpType type, unsigned short privateport, unsigned short publicport, int lifetime)
15708
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
397 {
15968
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
398 struct sockaddr_in *gateway;
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
399 gboolean success = TRUE;
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
400 int sendfd;
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
401 struct timeval req_timeout;
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
402 PurplePmpMapRequest req;
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
403 PurplePmpMapResponse *resp;
15970
0ad12ecb1fe3 Whitespace fixes
Evan Schoenberg <evands@pidgin.im>
parents: 15968
diff changeset
404
15968
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
405 gateway = default_gw();
15970
0ad12ecb1fe3 Whitespace fixes
Evan Schoenberg <evands@pidgin.im>
parents: 15968
diff changeset
406
15968
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
407 if (!gateway)
15708
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
408 {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15708
diff changeset
409 purple_debug_info("nat-pmp", "Cannot create mapping on a NULL gateway!\n");
15968
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
410 return FALSE;
15708
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
411 }
15968
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
412
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
413 /* Default port for NAT-PMP is 5351 */
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
414 if (gateway->sin_port != PMP_PORT)
40653
503cfa50c8c3 Use GLib's byte-order macros.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40512
diff changeset
415 gateway->sin_port = g_htons(PMP_PORT);
15970
0ad12ecb1fe3 Whitespace fixes
Evan Schoenberg <evands@pidgin.im>
parents: 15968
diff changeset
416
15968
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
417 resp = g_new0(PurplePmpMapResponse, 1);
15970
0ad12ecb1fe3 Whitespace fixes
Evan Schoenberg <evands@pidgin.im>
parents: 15968
diff changeset
418
15708
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
419 req_timeout.tv_sec = 0;
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
420 req_timeout.tv_usec = PMP_TIMEOUT;
15970
0ad12ecb1fe3 Whitespace fixes
Evan Schoenberg <evands@pidgin.im>
parents: 15968
diff changeset
421
15708
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
422 sendfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
15970
0ad12ecb1fe3 Whitespace fixes
Evan Schoenberg <evands@pidgin.im>
parents: 15968
diff changeset
423
15968
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
424 /* Set up the req */
19387
8dc4480381f3 bcopy and bzero shouldn't be used. This allows Alver to compile nat-pmp.c on one of his obscure systems (and I fixed some other stuff that I noticed at the same time).
Daniel Atallah <datallah@pidgin.im>
parents: 16965
diff changeset
425 memset(&req, 0, sizeof(PurplePmpMapRequest));
15708
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
426 req.version = 0;
19387
8dc4480381f3 bcopy and bzero shouldn't be used. This allows Alver to compile nat-pmp.c on one of his obscure systems (and I fixed some other stuff that I noticed at the same time).
Daniel Atallah <datallah@pidgin.im>
parents: 16965
diff changeset
427 req.opcode = ((type == PURPLE_PMP_TYPE_UDP) ? PMP_MAP_OPCODE_UDP : PMP_MAP_OPCODE_TCP);
40653
503cfa50c8c3 Use GLib's byte-order macros.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40512
diff changeset
428 req.privateport = g_htons(privateport); /* What a difference byte ordering makes...d'oh! */
503cfa50c8c3 Use GLib's byte-order macros.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40512
diff changeset
429 req.publicport = g_htons(publicport);
503cfa50c8c3 Use GLib's byte-order macros.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40512
diff changeset
430 req.lifetime = g_htonl(lifetime);
15970
0ad12ecb1fe3 Whitespace fixes
Evan Schoenberg <evands@pidgin.im>
parents: 15968
diff changeset
431
15968
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
432 /* The NAT-PMP spec says we should attempt to contact the gateway 9 times, doubling the time we wait each time.
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
433 * Even starting with a timeout of 0.1 seconds, that means that we have a total waiting of 204.6 seconds.
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
434 * With the recommended timeout of 0.25 seconds, we're talking 511.5 seconds (8.5 minutes).
25888
d0fdd378a635 Remove trailing whitespace
Mark Doliner <markdoliner@pidgin.im>
parents: 23518
diff changeset
435 *
15968
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
436 * This seems really silly... if this were nonblocking, a couple retries might be in order, but it's not at present.
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
437 * XXX Make this nonblocking.
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
438 * XXX This code looks like the pmp_get_public_ip() code. Can it be consolidated?
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
439 */
15708
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
440 #ifdef PMP_DEBUG
15968
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
441 purple_debug_info("nat-pmp", "Attempting to create a NAT-PMP mapping the private port %d, and the public port %d\n", privateport, publicport);
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
442 purple_debug_info("nat-pmp", "\tTimeout: %ds %dus\n", req_timeout.tv_sec, req_timeout.tv_usec);
15708
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
443 #endif
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
444
15968
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
445 /* TODO: Non-blocking! */
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
446 success = (sendto(sendfd, &req, sizeof(req), 0, (struct sockaddr *)(gateway), sizeof(struct sockaddr)) >= 0);
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
447 if (!success)
21389
e1dd8142bb87 replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 20147
diff changeset
448 purple_debug_info("nat-pmp", "There was an error sending the NAT-PMP mapping request! (%s)\n", g_strerror(errno));
15968
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
449
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
450 if (success)
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
451 {
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
452 success = (setsockopt(sendfd, SOL_SOCKET, SO_RCVTIMEO, &req_timeout, sizeof(req_timeout)) >= 0);
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
453 if (!success)
21389
e1dd8142bb87 replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 20147
diff changeset
454 purple_debug_info("nat-pmp", "There was an error setting the socket's options! (%s)\n", g_strerror(errno));
15968
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
455 }
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
456
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
457 if (success)
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
458 {
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
459 /* The original code treats EAGAIN as a reason to iterate.. but I've removed iteration. This may be a problem */
15961
a3ef09c8ca24 More complete namespacing of nat-pmp
Mark Doliner <markdoliner@pidgin.im>
parents: 15933
diff changeset
460 /* TODO: Non-blocking! */
15968
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
461 success = ((recvfrom(sendfd, resp, sizeof(PurplePmpMapResponse), 0, NULL, NULL) >= 0) ||
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
462 (errno == EAGAIN));
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
463 if (!success)
21389
e1dd8142bb87 replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 20147
diff changeset
464 purple_debug_info("nat-pmp", "There was an error receiving the response from the NAT-PMP device! (%s)\n", g_strerror(errno));
15968
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
465 }
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
466
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
467 if (success)
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
468 {
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
469 success = (resp->opcode == (req.opcode + 128));
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
470 if (!success)
22668
d57f88274300 Improved some of the debug output from nat-pmp
Evan Schoenberg <evands@pidgin.im>
parents: 21389
diff changeset
471 purple_debug_info("nat-pmp", "The opcode for the response from the NAT device (%i) does not match the request opcode (%i + 128 = %i)!\n",
d57f88274300 Improved some of the debug output from nat-pmp
Evan Schoenberg <evands@pidgin.im>
parents: 21389
diff changeset
472 resp->opcode, req.opcode, req.opcode + 128);
15708
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
473 }
15968
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
474
15708
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
475 #ifdef PMP_DEBUG
15968
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
476 if (success)
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
477 {
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
478 purple_debug_info("nat-pmp", "Response received from NAT-PMP device:\n");
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
479 purple_debug_info("nat-pmp", "version: %d\n", resp->version);
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
480 purple_debug_info("nat-pmp", "opcode: %d\n", resp->opcode);
40653
503cfa50c8c3 Use GLib's byte-order macros.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40512
diff changeset
481 purple_debug_info("nat-pmp", "resultcode: %d\n", g_ntohs(resp->resultcode));
503cfa50c8c3 Use GLib's byte-order macros.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40512
diff changeset
482 purple_debug_info("nat-pmp", "epoch: %d\n", g_ntohl(resp->epoch));
503cfa50c8c3 Use GLib's byte-order macros.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40512
diff changeset
483 purple_debug_info("nat-pmp", "privateport: %d\n", g_ntohs(resp->privateport));
503cfa50c8c3 Use GLib's byte-order macros.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40512
diff changeset
484 purple_debug_info("nat-pmp", "publicport: %d\n", g_ntohs(resp->publicport));
503cfa50c8c3 Use GLib's byte-order macros.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40512
diff changeset
485 purple_debug_info("nat-pmp", "lifetime: %d\n", g_ntohl(resp->lifetime));
15968
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
486 }
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
487 #endif
15708
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
488
15968
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
489 g_free(resp);
15933
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
490 g_free(gateway);
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
491
15968
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
492 /* XXX The private port may actually differ from the one we requested, according to the spec.
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
493 * We don't handle that situation at present.
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
494 *
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
495 * TODO: Look at the result and verify it matches what we wanted; either return a failure if it doesn't,
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
496 * or change network.c to know what to do if the desired private port shifts as a result of the nat-pmp operation.
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
497 */
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
498 return success;
15708
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
499 }
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
500
15968
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
501 gboolean
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
502 purple_pmp_destroy_map(PurplePmpType type, unsigned short privateport)
15708
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
503 {
15968
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
504 gboolean success;
15970
0ad12ecb1fe3 Whitespace fixes
Evan Schoenberg <evands@pidgin.im>
parents: 15968
diff changeset
505
15968
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
506 success = purple_pmp_create_map(((type == PURPLE_PMP_TYPE_UDP) ? PMP_MAP_OPCODE_UDP : PMP_MAP_OPCODE_TCP),
15933
913ba1d4b81c nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents: 15884
diff changeset
507 privateport, 0, 0);
15968
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
508 if (!success)
22668
d57f88274300 Improved some of the debug output from nat-pmp
Evan Schoenberg <evands@pidgin.im>
parents: 21389
diff changeset
509 purple_debug_warning("nat-pmp", "Failed to properly destroy mapping for %s port %d!\n",
d57f88274300 Improved some of the debug output from nat-pmp
Evan Schoenberg <evands@pidgin.im>
parents: 21389
diff changeset
510 ((type == PURPLE_PMP_TYPE_UDP) ? "UDP" : "TCP"), privateport);
15968
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
511
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
512 return success;
15708
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
513 }
16035
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
514
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
515 static void
41083
590d533cf290 Fix several typos in libpurple
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40653
diff changeset
516 purple_pmp_network_config_changed_cb(GNetworkMonitor *monitor, gboolean available, gpointer data)
16035
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
517 {
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
518 pmp_info.status = PURPLE_PMP_STATUS_UNDISCOVERED;
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
519 g_free(pmp_info.publicip);
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
520 pmp_info.publicip = NULL;
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
521 }
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
522
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
523 static void*
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
524 purple_pmp_get_handle(void)
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
525 {
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
526 static int handle;
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
527
19387
8dc4480381f3 bcopy and bzero shouldn't be used. This allows Alver to compile nat-pmp.c on one of his obscure systems (and I fixed some other stuff that I noticed at the same time).
Daniel Atallah <datallah@pidgin.im>
parents: 16965
diff changeset
528 return &handle;
16035
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
529 }
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
530
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
531 void
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
532 purple_pmp_init()
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
533 {
37489
cbf9ccc715ab Move everything in libpurple that was using the network-changed signal to use the gio one
Gary Kramlich <grim@reaperworld.com>
parents: 35454
diff changeset
534 g_signal_connect(g_network_monitor_get_default(),
cbf9ccc715ab Move everything in libpurple that was using the network-changed signal to use the gio one
Gary Kramlich <grim@reaperworld.com>
parents: 35454
diff changeset
535 "network-changed",
cbf9ccc715ab Move everything in libpurple that was using the network-changed signal to use the gio one
Gary Kramlich <grim@reaperworld.com>
parents: 35454
diff changeset
536 G_CALLBACK(purple_pmp_network_config_changed_cb),
cbf9ccc715ab Move everything in libpurple that was using the network-changed signal to use the gio one
Gary Kramlich <grim@reaperworld.com>
parents: 35454
diff changeset
537 NULL);
16035
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
538 }
16014
9ee607a29a8c Using rt_msghdr instead of rt_msghdr2 compiles on a greater number of systems -- specifically Mac OS X 10.3.x, in addition to the previous compilation on OS X 10.4.x and above -- and seems to work just as well. If anyone knows how the use of these seemingly very similar structs differs, enlightenment would be appreciated.
Evan Schoenberg <evands@pidgin.im>
parents: 15984
diff changeset
539 #else /* #ifdef NET_RT_DUMP */
15708
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
540 char *
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15708
diff changeset
541 purple_pmp_get_public_ip()
15708
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
542 {
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
543 return NULL;
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
544 }
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
545
15968
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
546 gboolean
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
547 purple_pmp_create_map(PurplePmpType type, unsigned short privateport, unsigned short publicport, int lifetime)
15708
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
548 {
15984
45e6793c221c These should return FALSE, not NULL, when NET_RT_DUMP2 isn't available; they return a gboolean, not a pointer.
Evan Schoenberg <evands@pidgin.im>
parents: 15970
diff changeset
549 return FALSE;
15708
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
550 }
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
551
15968
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
552 gboolean
01dcc5c7cf9e Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
Evan Schoenberg <evands@pidgin.im>
parents: 15961
diff changeset
553 purple_pmp_destroy_map(PurplePmpType type, unsigned short privateport)
15708
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
554 {
15984
45e6793c221c These should return FALSE, not NULL, when NET_RT_DUMP2 isn't available; they return a gboolean, not a pointer.
Evan Schoenberg <evands@pidgin.im>
parents: 15970
diff changeset
555 return FALSE;
15708
979f43512119 Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff changeset
556 }
16035
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
557
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
558 void
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
559 purple_pmp_init()
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
560 {
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
561
eb4eda79a147 The network module now registers the signal 'network-configuration-changed' and emits it when a network change is detected via libnm or the win32 network monitor. The UI could also emit this signal if it knows something network.c doesn't. UPnP and NAT-PMP respond to the signal by clearing their IP address caches; changing networks without quitting/relaunching will now lead to the new IP address being (lazily) determined. This commit also enables nat-pmp and adds nat-pmp.[h|c] to the build process; please let me know if there are any problems building, as I only have OS X test machines.
Evan Schoenberg <evands@pidgin.im>
parents: 16014
diff changeset
562 }
16965
d3df125b3196 I expanded your patch, Richard, to also do appropriate header checking in the configure script and then use that information. I removed some other #includes which don't appear to be needed.
Evan Schoenberg <evands@pidgin.im>
parents: 16964
diff changeset
563 #endif /* #if !(defined(HAVE_SYS_SYCTL_H) && defined(NET_RT_DUMP)) */

mercurial