Mercurial > pidgin.yaz
annotate libpurple/nat-pmp.c @ 24791:7827ba7d5ad8
Add Israt Jahan to the about dialog for the Bengali translation.
Closes #7820
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Thu, 18 Dec 2008 10:24:47 +0000 |
parents | b175f6441bba |
children | 584063555949 |
rev | line source |
---|---|
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
1 /** |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
2 * @file nat-pmp.c NAT-PMP Implementation |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
3 * @ingroup core |
20074
6bf32c9e15a7
remove gpl boilerplate from doxygen docs
Sean Egan <seanegan@gmail.com>
parents:
19653
diff
changeset
|
4 */ |
6bf32c9e15a7
remove gpl boilerplate from doxygen docs
Sean Egan <seanegan@gmail.com>
parents:
19653
diff
changeset
|
5 |
6bf32c9e15a7
remove gpl boilerplate from doxygen docs
Sean Egan <seanegan@gmail.com>
parents:
19653
diff
changeset
|
6 /* purple |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
7 * |
15823 | 8 * Purple is the legal property of its developers, whose names are too numerous |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
9 * to list here. Please refer to the COPYRIGHT file distributed with this |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
10 * source distribution. |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
11 * |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
12 * Most code in nat-pmp.c copyright (C) 2007, R. Tyler Ballance, bleep, LLC. |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
13 * This file is distributed under the 3-clause (modified) BSD license: |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
14 * Redistribution and use in source and binary forms, with or without modification, are permitted |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
15 * provided that the following conditions are met: |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
16 * |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
17 * Redistributions of source code must retain the above copyright notice, this list of conditions and |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
18 * the following disclaimer. |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
19 * Neither the name of the bleep. LLC nor the names of its contributors may be used to endorse or promote |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
20 * products derived from this software without specific prior written permission. |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
21 * |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
23 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
24 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
25 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
28 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
29 * OF SUCH DAMAGE. |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
30 */ |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
31 |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
32 #include "nat-pmp.h" |
16919
d0e74d0be43f
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 <evan.s@dreskin.net>
parents:
16918
diff
changeset
|
33 #include "internal.h" |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
34 #include "debug.h" |
15974
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
35 #include "signals.h" |
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
36 #include "network.h" |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
37 |
23377
b175f6441bba
Some header inclusion fixes to help on NetBSD/FreeBSD.
Richard Laager <rlaager@wiktel.com>
parents:
23203
diff
changeset
|
38 #ifdef HAVE_SYS_PARAM_H |
b175f6441bba
Some header inclusion fixes to help on NetBSD/FreeBSD.
Richard Laager <rlaager@wiktel.com>
parents:
23203
diff
changeset
|
39 #include <sys/param.h> |
b175f6441bba
Some header inclusion fixes to help on NetBSD/FreeBSD.
Richard Laager <rlaager@wiktel.com>
parents:
23203
diff
changeset
|
40 #endif |
b175f6441bba
Some header inclusion fixes to help on NetBSD/FreeBSD.
Richard Laager <rlaager@wiktel.com>
parents:
23203
diff
changeset
|
41 |
16919
d0e74d0be43f
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 <evan.s@dreskin.net>
parents:
16918
diff
changeset
|
42 #ifdef HAVE_SYS_SYSCTL_H |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
43 #include <sys/sysctl.h> |
15975
328ae2c041c3
fix win32 build for nat-pmp stuff. I haven't tested it, but it compiles.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
15974
diff
changeset
|
44 #endif |
328ae2c041c3
fix win32 build for nat-pmp stuff. I haven't tested it, but it compiles.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
15974
diff
changeset
|
45 |
16919
d0e74d0be43f
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 <evan.s@dreskin.net>
parents:
16918
diff
changeset
|
46 #ifdef HAVE_SYS_SOCKET_H |
d0e74d0be43f
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 <evan.s@dreskin.net>
parents:
16918
diff
changeset
|
47 #include <sys/socket.h> |
d0e74d0be43f
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 <evan.s@dreskin.net>
parents:
16918
diff
changeset
|
48 #endif |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
49 |
16919
d0e74d0be43f
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 <evan.s@dreskin.net>
parents:
16918
diff
changeset
|
50 /* We will need sysctl() and NET_RT_DUMP, both of which are not present |
d0e74d0be43f
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 <evan.s@dreskin.net>
parents:
16918
diff
changeset
|
51 * on all platforms, to continue. */ |
d0e74d0be43f
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 <evan.s@dreskin.net>
parents:
16918
diff
changeset
|
52 #if defined(HAVE_SYS_SYSCTL_H) && defined(NET_RT_DUMP) |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
53 |
16919
d0e74d0be43f
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 <evan.s@dreskin.net>
parents:
16918
diff
changeset
|
54 #include <sys/types.h> |
d0e74d0be43f
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 <evan.s@dreskin.net>
parents:
16918
diff
changeset
|
55 #include <net/route.h> |
15856
9b875f0ecb86
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 <evan.s@dreskin.net>
parents:
15823
diff
changeset
|
56 |
15907
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
57 #define PMP_DEBUG 1 |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
58 |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
59 typedef struct { |
16918
533ebd404184
Change the nat-pmp code to use glib's integer types instead of those from
Richard Laager <rlaager@wiktel.com>
parents:
16345
diff
changeset
|
60 guint8 version; |
533ebd404184
Change the nat-pmp code to use glib's integer types instead of those from
Richard Laager <rlaager@wiktel.com>
parents:
16345
diff
changeset
|
61 guint8 opcode; |
15907
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
62 } PurplePmpIpRequest; |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
63 |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
64 typedef struct { |
16918
533ebd404184
Change the nat-pmp code to use glib's integer types instead of those from
Richard Laager <rlaager@wiktel.com>
parents:
16345
diff
changeset
|
65 guint8 version; |
533ebd404184
Change the nat-pmp code to use glib's integer types instead of those from
Richard Laager <rlaager@wiktel.com>
parents:
16345
diff
changeset
|
66 guint8 opcode; /* 128 + n */ |
533ebd404184
Change the nat-pmp code to use glib's integer types instead of those from
Richard Laager <rlaager@wiktel.com>
parents:
16345
diff
changeset
|
67 guint16 resultcode; |
533ebd404184
Change the nat-pmp code to use glib's integer types instead of those from
Richard Laager <rlaager@wiktel.com>
parents:
16345
diff
changeset
|
68 guint32 epoch; |
533ebd404184
Change the nat-pmp code to use glib's integer types instead of those from
Richard Laager <rlaager@wiktel.com>
parents:
16345
diff
changeset
|
69 guint32 address; |
15907
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
70 } PurplePmpIpResponse; |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
71 |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
72 typedef struct { |
16918
533ebd404184
Change the nat-pmp code to use glib's integer types instead of those from
Richard Laager <rlaager@wiktel.com>
parents:
16345
diff
changeset
|
73 guint8 version; |
533ebd404184
Change the nat-pmp code to use glib's integer types instead of those from
Richard Laager <rlaager@wiktel.com>
parents:
16345
diff
changeset
|
74 guint8 opcode; |
15907
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
75 char reserved[2]; |
16918
533ebd404184
Change the nat-pmp code to use glib's integer types instead of those from
Richard Laager <rlaager@wiktel.com>
parents:
16345
diff
changeset
|
76 guint16 privateport; |
533ebd404184
Change the nat-pmp code to use glib's integer types instead of those from
Richard Laager <rlaager@wiktel.com>
parents:
16345
diff
changeset
|
77 guint16 publicport; |
533ebd404184
Change the nat-pmp code to use glib's integer types instead of those from
Richard Laager <rlaager@wiktel.com>
parents:
16345
diff
changeset
|
78 guint32 lifetime; |
15907
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
79 } PurplePmpMapRequest; |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
80 |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
81 struct _PurplePmpMapResponse { |
16918
533ebd404184
Change the nat-pmp code to use glib's integer types instead of those from
Richard Laager <rlaager@wiktel.com>
parents:
16345
diff
changeset
|
82 guint8 version; |
533ebd404184
Change the nat-pmp code to use glib's integer types instead of those from
Richard Laager <rlaager@wiktel.com>
parents:
16345
diff
changeset
|
83 guint8 opcode; |
533ebd404184
Change the nat-pmp code to use glib's integer types instead of those from
Richard Laager <rlaager@wiktel.com>
parents:
16345
diff
changeset
|
84 guint16 resultcode; |
533ebd404184
Change the nat-pmp code to use glib's integer types instead of those from
Richard Laager <rlaager@wiktel.com>
parents:
16345
diff
changeset
|
85 guint32 epoch; |
533ebd404184
Change the nat-pmp code to use glib's integer types instead of those from
Richard Laager <rlaager@wiktel.com>
parents:
16345
diff
changeset
|
86 guint16 privateport; |
533ebd404184
Change the nat-pmp code to use glib's integer types instead of those from
Richard Laager <rlaager@wiktel.com>
parents:
16345
diff
changeset
|
87 guint16 publicport; |
533ebd404184
Change the nat-pmp code to use glib's integer types instead of those from
Richard Laager <rlaager@wiktel.com>
parents:
16345
diff
changeset
|
88 guint32 lifetime; |
15907
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
89 }; |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
90 |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
91 typedef struct _PurplePmpMapResponse PurplePmpMapResponse; |
15856
9b875f0ecb86
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 <evan.s@dreskin.net>
parents:
15823
diff
changeset
|
92 |
15974
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
93 typedef enum { |
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
94 PURPLE_PMP_STATUS_UNDISCOVERED = -1, |
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
95 PURPLE_PMP_STATUS_UNABLE_TO_DISCOVER, |
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
96 PURPLE_PMP_STATUS_DISCOVERING, |
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
97 PURPLE_PMP_STATUS_DISCOVERED |
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
98 } PurpleUPnPStatus; |
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
99 |
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
100 typedef struct { |
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
101 PurpleUPnPStatus status; |
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
102 gchar *publicip; |
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
103 } PurplePmpInfo; |
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
104 |
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
105 static PurplePmpInfo pmp_info = {PURPLE_PMP_STATUS_UNDISCOVERED, NULL}; |
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
106 |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
107 /* |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
108 * Thanks to R. Matthew Emerson for the fixes on this |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
109 */ |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
110 |
15856
9b875f0ecb86
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 <evan.s@dreskin.net>
parents:
15823
diff
changeset
|
111 #define PMP_MAP_OPCODE_UDP 1 |
9b875f0ecb86
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 <evan.s@dreskin.net>
parents:
15823
diff
changeset
|
112 #define PMP_MAP_OPCODE_TCP 2 |
9b875f0ecb86
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 <evan.s@dreskin.net>
parents:
15823
diff
changeset
|
113 |
9b875f0ecb86
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 <evan.s@dreskin.net>
parents:
15823
diff
changeset
|
114 #define PMP_VERSION 0 |
9b875f0ecb86
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 <evan.s@dreskin.net>
parents:
15823
diff
changeset
|
115 #define PMP_PORT 5351 |
15907
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
116 #define PMP_TIMEOUT 250000 /* 250000 useconds */ |
15856
9b875f0ecb86
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 <evan.s@dreskin.net>
parents:
15823
diff
changeset
|
117 |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
118 /* alignment constraint for routing socket */ |
15856
9b875f0ecb86
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 <evan.s@dreskin.net>
parents:
15823
diff
changeset
|
119 #define ROUNDUP(a) ((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long)) |
9b875f0ecb86
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 <evan.s@dreskin.net>
parents:
15823
diff
changeset
|
120 #define ADVANCE(x, n) (x += ROUNDUP((n)->sa_len)) |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
121 |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
122 static void |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
123 get_rtaddrs(int bitmask, struct sockaddr *sa, struct sockaddr *addrs[]) |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
124 { |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
125 int i; |
15909 | 126 |
127 for (i = 0; i < RTAX_MAX; i++) | |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
128 { |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
129 if (bitmask & (1 << i)) |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
130 { |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
131 addrs[i] = sa; |
23203
313b87adb730
A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents:
22516
diff
changeset
|
132 #ifdef HAVE_STRUCT_SOCKADDR_SA_LEN |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
133 sa = (struct sockaddr *)(ROUNDUP(sa->sa_len) + (char *)sa); |
23203
313b87adb730
A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents:
22516
diff
changeset
|
134 #else |
313b87adb730
A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents:
22516
diff
changeset
|
135 if (sa->sa_family == AF_INET) |
313b87adb730
A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents:
22516
diff
changeset
|
136 sa = (struct sockaddr*)(sizeof(struct sockaddr_in) + (char *)sa); |
313b87adb730
A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents:
22516
diff
changeset
|
137 #ifdef AF_INET6 |
313b87adb730
A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents:
22516
diff
changeset
|
138 else if (sa->sa_family == AF_INET6) |
313b87adb730
A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents:
22516
diff
changeset
|
139 sa = (struct sockaddr*)(sizeof(struct sockaddr_in6) + (char *)sa); |
313b87adb730
A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents:
22516
diff
changeset
|
140 #endif |
313b87adb730
A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents:
22516
diff
changeset
|
141 #endif |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
142 } |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
143 else |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
144 { |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
145 addrs[i] = NULL; |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
146 } |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
147 } |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
148 } |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
149 |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
150 static int |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
151 is_default_route(struct sockaddr *sa, struct sockaddr *mask) |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
152 { |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
153 struct sockaddr_in *sin; |
15909 | 154 |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
155 if (sa->sa_family != AF_INET) |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
156 return 0; |
15909 | 157 |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
158 sin = (struct sockaddr_in *)sa; |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
159 if ((sin->sin_addr.s_addr == INADDR_ANY) && |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
160 mask && |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
161 (ntohl(((struct sockaddr_in *)mask)->sin_addr.s_addr) == 0L || |
23203
313b87adb730
A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents:
22516
diff
changeset
|
162 #ifdef HAVE_STRUCT_SOCKADDR_SA_LEN |
313b87adb730
A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents:
22516
diff
changeset
|
163 mask->sa_len == 0 |
313b87adb730
A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents:
22516
diff
changeset
|
164 #else |
313b87adb730
A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents:
22516
diff
changeset
|
165 0 |
313b87adb730
A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents:
22516
diff
changeset
|
166 #endif |
313b87adb730
A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents:
22516
diff
changeset
|
167 )) |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
168 return 1; |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
169 else |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
170 return 0; |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
171 } |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
172 |
15856
9b875f0ecb86
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 <evan.s@dreskin.net>
parents:
15823
diff
changeset
|
173 /*! |
9b875f0ecb86
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 <evan.s@dreskin.net>
parents:
15823
diff
changeset
|
174 * The return sockaddr_in must be g_free()'d when no longer needed |
9b875f0ecb86
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 <evan.s@dreskin.net>
parents:
15823
diff
changeset
|
175 */ |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
176 static struct sockaddr_in * |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
177 default_gw() |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
178 { |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
179 int mib[6]; |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
180 size_t needed; |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
181 char *buf, *next, *lim; |
15950
45cbb80bfd54
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 <evan.s@dreskin.net>
parents:
15923
diff
changeset
|
182 struct rt_msghdr *rtm; |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
183 struct sockaddr *sa; |
15856
9b875f0ecb86
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 <evan.s@dreskin.net>
parents:
15823
diff
changeset
|
184 struct sockaddr_in *sin = NULL; |
9b875f0ecb86
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 <evan.s@dreskin.net>
parents:
15823
diff
changeset
|
185 gboolean found = FALSE; |
9b875f0ecb86
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 <evan.s@dreskin.net>
parents:
15823
diff
changeset
|
186 |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
187 mib[0] = CTL_NET; |
15856
9b875f0ecb86
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 <evan.s@dreskin.net>
parents:
15823
diff
changeset
|
188 mib[1] = PF_ROUTE; /* entire routing table or a subset of it */ |
9b875f0ecb86
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 <evan.s@dreskin.net>
parents:
15823
diff
changeset
|
189 mib[2] = 0; /* protocol number - always 0 */ |
9b875f0ecb86
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 <evan.s@dreskin.net>
parents:
15823
diff
changeset
|
190 mib[3] = 0; /* address family - 0 for all addres families */ |
15950
45cbb80bfd54
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 <evan.s@dreskin.net>
parents:
15923
diff
changeset
|
191 mib[4] = NET_RT_DUMP; |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
192 mib[5] = 0; |
15909 | 193 |
15856
9b875f0ecb86
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 <evan.s@dreskin.net>
parents:
15823
diff
changeset
|
194 /* Determine the buffer side needed to get the full routing table */ |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
195 if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0) |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
196 { |
19653
941965d6fd88
Patch from QuLogic. Fixes #2903 ('Missing newlines in debug messages.')
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19268
diff
changeset
|
197 purple_debug_warning("nat-pmp", "sysctl: net.route.0.0.dump estimate\n"); |
15856
9b875f0ecb86
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 <evan.s@dreskin.net>
parents:
15823
diff
changeset
|
198 return NULL; |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
199 } |
15909 | 200 |
15856
9b875f0ecb86
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 <evan.s@dreskin.net>
parents:
15823
diff
changeset
|
201 if (!(buf = malloc(needed))) |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
202 { |
22516
8972581c2326
Improved some of the debug output from nat-pmp
Evan Schoenberg <evan.s@dreskin.net>
parents:
21121
diff
changeset
|
203 purple_debug_warning("nat-pmp", "Failed to malloc %i\n", needed); |
15856
9b875f0ecb86
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 <evan.s@dreskin.net>
parents:
15823
diff
changeset
|
204 return NULL; |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
205 } |
15909 | 206 |
15856
9b875f0ecb86
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 <evan.s@dreskin.net>
parents:
15823
diff
changeset
|
207 /* Read the routing table into buf */ |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
208 if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0) |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
209 { |
19653
941965d6fd88
Patch from QuLogic. Fixes #2903 ('Missing newlines in debug messages.')
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19268
diff
changeset
|
210 purple_debug_warning("nat-pmp", "sysctl: net.route.0.0.dump\n"); |
15856
9b875f0ecb86
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 <evan.s@dreskin.net>
parents:
15823
diff
changeset
|
211 return NULL; |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
212 } |
15909 | 213 |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
214 lim = buf + needed; |
15909 | 215 |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
216 for (next = buf; next < lim; next += rtm->rtm_msglen) |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
217 { |
15950
45cbb80bfd54
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 <evan.s@dreskin.net>
parents:
15923
diff
changeset
|
218 rtm = (struct rt_msghdr *)next; |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
219 sa = (struct sockaddr *)(rtm + 1); |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
220 |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
221 if (sa->sa_family == AF_INET) |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
222 { |
15856
9b875f0ecb86
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 <evan.s@dreskin.net>
parents:
15823
diff
changeset
|
223 sin = (struct sockaddr_in*) sa; |
9b875f0ecb86
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 <evan.s@dreskin.net>
parents:
15823
diff
changeset
|
224 |
9b875f0ecb86
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 <evan.s@dreskin.net>
parents:
15823
diff
changeset
|
225 if ((rtm->rtm_flags & RTF_GATEWAY) && sin->sin_addr.s_addr == INADDR_ANY) |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
226 { |
15856
9b875f0ecb86
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 <evan.s@dreskin.net>
parents:
15823
diff
changeset
|
227 /* We found the default route. Now get the destination address and netmask. */ |
9b875f0ecb86
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 <evan.s@dreskin.net>
parents:
15823
diff
changeset
|
228 struct sockaddr *rti_info[RTAX_MAX]; |
9b875f0ecb86
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 <evan.s@dreskin.net>
parents:
15823
diff
changeset
|
229 struct sockaddr addr, mask; |
9b875f0ecb86
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 <evan.s@dreskin.net>
parents:
15823
diff
changeset
|
230 |
9b875f0ecb86
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 <evan.s@dreskin.net>
parents:
15823
diff
changeset
|
231 get_rtaddrs(rtm->rtm_addrs, sa, rti_info); |
19268
db6218615be4
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 <daniel.atallah@gmail.com>
parents:
16919
diff
changeset
|
232 memset(&addr, 0, sizeof(addr)); |
15909 | 233 |
15856
9b875f0ecb86
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 <evan.s@dreskin.net>
parents:
15823
diff
changeset
|
234 if (rtm->rtm_addrs & RTA_DST) |
19268
db6218615be4
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 <daniel.atallah@gmail.com>
parents:
16919
diff
changeset
|
235 memcpy(&addr, rti_info[RTAX_DST], sizeof(addr)); |
15909 | 236 |
19268
db6218615be4
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 <daniel.atallah@gmail.com>
parents:
16919
diff
changeset
|
237 memset(&mask, 0, sizeof(mask)); |
15909 | 238 |
15856
9b875f0ecb86
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 <evan.s@dreskin.net>
parents:
15823
diff
changeset
|
239 if (rtm->rtm_addrs & RTA_NETMASK) |
19268
db6218615be4
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 <daniel.atallah@gmail.com>
parents:
16919
diff
changeset
|
240 memcpy(&mask, rti_info[RTAX_NETMASK], sizeof(mask)); |
15909 | 241 |
15856
9b875f0ecb86
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 <evan.s@dreskin.net>
parents:
15823
diff
changeset
|
242 if (rtm->rtm_addrs & RTA_GATEWAY && |
9b875f0ecb86
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 <evan.s@dreskin.net>
parents:
15823
diff
changeset
|
243 is_default_route(&addr, &mask)) |
19268
db6218615be4
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 <daniel.atallah@gmail.com>
parents:
16919
diff
changeset
|
244 { |
15856
9b875f0ecb86
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 <evan.s@dreskin.net>
parents:
15823
diff
changeset
|
245 if (rti_info[RTAX_GATEWAY]) { |
9b875f0ecb86
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 <evan.s@dreskin.net>
parents:
15823
diff
changeset
|
246 struct sockaddr_in *rti_sin = (struct sockaddr_in *)rti_info[RTAX_GATEWAY]; |
9b875f0ecb86
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 <evan.s@dreskin.net>
parents:
15823
diff
changeset
|
247 sin = g_new0(struct sockaddr_in, 1); |
9b875f0ecb86
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 <evan.s@dreskin.net>
parents:
15823
diff
changeset
|
248 sin->sin_family = rti_sin->sin_family; |
9b875f0ecb86
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 <evan.s@dreskin.net>
parents:
15823
diff
changeset
|
249 sin->sin_port = rti_sin->sin_port; |
9b875f0ecb86
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 <evan.s@dreskin.net>
parents:
15823
diff
changeset
|
250 sin->sin_addr.s_addr = rti_sin->sin_addr.s_addr; |
9b875f0ecb86
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 <evan.s@dreskin.net>
parents:
15823
diff
changeset
|
251 memcpy(sin, rti_info[RTAX_GATEWAY], sizeof(struct sockaddr_in)); |
9b875f0ecb86
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 <evan.s@dreskin.net>
parents:
15823
diff
changeset
|
252 |
22516
8972581c2326
Improved some of the debug output from nat-pmp
Evan Schoenberg <evan.s@dreskin.net>
parents:
21121
diff
changeset
|
253 purple_debug_info("nat-pmp", "Found a default gateway\n"); |
15856
9b875f0ecb86
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 <evan.s@dreskin.net>
parents:
15823
diff
changeset
|
254 found = TRUE; |
9b875f0ecb86
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 <evan.s@dreskin.net>
parents:
15823
diff
changeset
|
255 break; |
9b875f0ecb86
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 <evan.s@dreskin.net>
parents:
15823
diff
changeset
|
256 } |
9b875f0ecb86
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 <evan.s@dreskin.net>
parents:
15823
diff
changeset
|
257 } |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
258 } |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
259 } |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
260 } |
15856
9b875f0ecb86
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 <evan.s@dreskin.net>
parents:
15823
diff
changeset
|
261 |
9b875f0ecb86
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 <evan.s@dreskin.net>
parents:
15823
diff
changeset
|
262 return (found ? sin : NULL); |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
263 } |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
264 |
15856
9b875f0ecb86
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 <evan.s@dreskin.net>
parents:
15823
diff
changeset
|
265 /*! |
15823 | 266 * purple_pmp_get_public_ip() will return the publicly facing IP address of the |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
267 * default NAT gateway. The function will return NULL if: |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
268 * - The gateway doesn't support NAT-PMP |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
269 * - The gateway errors in some other spectacular fashion |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
270 */ |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
271 char * |
15823 | 272 purple_pmp_get_public_ip() |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
273 { |
15974
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
274 struct sockaddr_in addr, *gateway, *publicsockaddr = NULL; |
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
275 struct timeval req_timeout; |
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
276 socklen_t len; |
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
277 |
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
278 PurplePmpIpRequest req; |
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
279 PurplePmpIpResponse resp; |
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
280 int sendfd; |
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
281 |
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
282 if (pmp_info.status == PURPLE_PMP_STATUS_UNABLE_TO_DISCOVER) |
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
283 return NULL; |
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
284 |
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
285 if ((pmp_info.status == PURPLE_PMP_STATUS_DISCOVERED) && (pmp_info.publicip != NULL)) |
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
286 { |
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
287 #ifdef PMP_DEBUG |
19653
941965d6fd88
Patch from QuLogic. Fixes #2903 ('Missing newlines in debug messages.')
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19268
diff
changeset
|
288 purple_debug_info("nat-pmp", "Returning cached publicip %s\n",pmp_info.publicip); |
15974
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
289 #endif |
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
290 return pmp_info.publicip; |
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
291 } |
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
292 |
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
293 gateway = default_gw(); |
15909 | 294 |
15907
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
295 if (!gateway) |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
296 { |
15823 | 297 purple_debug_info("nat-pmp", "Cannot request public IP from a NULL gateway!\n"); |
15974
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
298 /* If we get a NULL gateway, don't try again next time */ |
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
299 pmp_info.status = PURPLE_PMP_STATUS_UNABLE_TO_DISCOVER; |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
300 return NULL; |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
301 } |
15907
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
302 |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
303 /* Default port for NAT-PMP is 5351 */ |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
304 if (gateway->sin_port != PMP_PORT) |
15907
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
305 gateway->sin_port = htons(PMP_PORT); |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
306 |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
307 req_timeout.tv_sec = 0; |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
308 req_timeout.tv_usec = PMP_TIMEOUT; |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
309 |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
310 sendfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); |
15909 | 311 |
15907
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
312 /* Clean out both req and resp structures */ |
19268
db6218615be4
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 <daniel.atallah@gmail.com>
parents:
16919
diff
changeset
|
313 memset(&req, 0, sizeof(PurplePmpIpRequest)); |
db6218615be4
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 <daniel.atallah@gmail.com>
parents:
16919
diff
changeset
|
314 memset(&resp, 0, sizeof(PurplePmpIpResponse)); |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
315 req.version = 0; |
19268
db6218615be4
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 <daniel.atallah@gmail.com>
parents:
16919
diff
changeset
|
316 req.opcode = 0; |
15909 | 317 |
15907
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
318 /* The NAT-PMP spec says we should attempt to contact the gateway 9 times, doubling the time we wait each time. |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
319 * Even starting with a timeout of 0.1 seconds, that means that we have a total waiting of 204.6 seconds. |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
320 * With the recommended timeout of 0.25 seconds, we're talking 511.5 seconds (8.5 minutes). |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
321 * |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
322 * This seems really silly... if this were nonblocking, a couple retries might be in order, but it's not at present. |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
323 */ |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
324 #ifdef PMP_DEBUG |
15907
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
325 purple_debug_info("nat-pmp", "Attempting to retrieve the public ip address for the NAT device at: %s\n", inet_ntoa(gateway->sin_addr)); |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
326 purple_debug_info("nat-pmp", "\tTimeout: %ds %dus\n", req_timeout.tv_sec, req_timeout.tv_usec); |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
327 #endif |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
328 |
15907
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
329 /* TODO: Non-blocking! */ |
15974
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
330 |
15907
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
331 if (sendto(sendfd, &req, sizeof(req), 0, (struct sockaddr *)(gateway), sizeof(struct sockaddr)) < 0) |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
332 { |
21121
35b4f1dc4c8d
replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents:
20074
diff
changeset
|
333 purple_debug_info("nat-pmp", "There was an error sending the NAT-PMP public IP request! (%s)\n", g_strerror(errno)); |
15856
9b875f0ecb86
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 <evan.s@dreskin.net>
parents:
15823
diff
changeset
|
334 g_free(gateway); |
15974
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
335 pmp_info.status = PURPLE_PMP_STATUS_UNABLE_TO_DISCOVER; |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
336 return NULL; |
15856
9b875f0ecb86
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 <evan.s@dreskin.net>
parents:
15823
diff
changeset
|
337 } |
15907
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
338 |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
339 if (setsockopt(sendfd, SOL_SOCKET, SO_RCVTIMEO, &req_timeout, sizeof(req_timeout)) < 0) |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
340 { |
21121
35b4f1dc4c8d
replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents:
20074
diff
changeset
|
341 purple_debug_info("nat-pmp", "There was an error setting the socket's options! (%s)\n", g_strerror(errno)); |
15907
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
342 g_free(gateway); |
15974
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
343 pmp_info.status = PURPLE_PMP_STATUS_UNABLE_TO_DISCOVER; |
15907
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
344 return NULL; |
19268
db6218615be4
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 <daniel.atallah@gmail.com>
parents:
16919
diff
changeset
|
345 } |
15907
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
346 |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
347 /* TODO: Non-blocking! */ |
15974
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
348 len = sizeof(struct sockaddr_in); |
15907
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
349 if (recvfrom(sendfd, &resp, sizeof(PurplePmpIpResponse), 0, (struct sockaddr *)(&addr), &len) < 0) |
19268
db6218615be4
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 <daniel.atallah@gmail.com>
parents:
16919
diff
changeset
|
350 { |
15907
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
351 if (errno != EAGAIN) |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
352 { |
21121
35b4f1dc4c8d
replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents:
20074
diff
changeset
|
353 purple_debug_info("nat-pmp", "There was an error receiving the response from the NAT-PMP device! (%s)\n", g_strerror(errno)); |
15907
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
354 g_free(gateway); |
15974
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
355 pmp_info.status = PURPLE_PMP_STATUS_UNABLE_TO_DISCOVER; |
15907
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
356 return NULL; |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
357 } |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
358 } |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
359 |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
360 if (addr.sin_addr.s_addr == gateway->sin_addr.s_addr) |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
361 publicsockaddr = &addr; |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
362 else |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
363 { |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
364 purple_debug_info("nat-pmp", "Response was not received from our gateway! Instead from: %s\n", inet_ntoa(addr.sin_addr)); |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
365 g_free(gateway); |
15974
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
366 |
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
367 pmp_info.status = PURPLE_PMP_STATUS_UNABLE_TO_DISCOVER; |
15907
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
368 return NULL; |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
369 } |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
370 |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
371 if (!publicsockaddr) { |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
372 g_free(gateway); |
15974
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
373 |
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
374 pmp_info.status = PURPLE_PMP_STATUS_UNABLE_TO_DISCOVER; |
15907
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
375 return NULL; |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
376 } |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
377 |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
378 #ifdef PMP_DEBUG |
15823 | 379 purple_debug_info("nat-pmp", "Response received from NAT-PMP device:\n"); |
380 purple_debug_info("nat-pmp", "version: %d\n", resp.version); | |
381 purple_debug_info("nat-pmp", "opcode: %d\n", resp.opcode); | |
382 purple_debug_info("nat-pmp", "resultcode: %d\n", ntohs(resp.resultcode)); | |
383 purple_debug_info("nat-pmp", "epoch: %d\n", ntohl(resp.epoch)); | |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
384 struct in_addr in; |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
385 in.s_addr = resp.address; |
15823 | 386 purple_debug_info("nat-pmp", "address: %s\n", inet_ntoa(in)); |
19268
db6218615be4
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 <daniel.atallah@gmail.com>
parents:
16919
diff
changeset
|
387 #endif |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
388 |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
389 publicsockaddr->sin_addr.s_addr = resp.address; |
15856
9b875f0ecb86
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 <evan.s@dreskin.net>
parents:
15823
diff
changeset
|
390 |
9b875f0ecb86
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 <evan.s@dreskin.net>
parents:
15823
diff
changeset
|
391 g_free(gateway); |
9b875f0ecb86
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 <evan.s@dreskin.net>
parents:
15823
diff
changeset
|
392 |
15974
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
393 g_free(pmp_info.publicip); |
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
394 pmp_info.publicip = g_strdup(inet_ntoa(publicsockaddr->sin_addr)); |
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
395 pmp_info.status = PURPLE_PMP_STATUS_DISCOVERED; |
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
396 |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
397 return inet_ntoa(publicsockaddr->sin_addr); |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
398 } |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
399 |
15907
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
400 gboolean |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
401 purple_pmp_create_map(PurplePmpType type, unsigned short privateport, unsigned short publicport, int lifetime) |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
402 { |
15907
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
403 struct sockaddr_in *gateway; |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
404 gboolean success = TRUE; |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
405 int sendfd; |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
406 struct timeval req_timeout; |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
407 PurplePmpMapRequest req; |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
408 PurplePmpMapResponse *resp; |
15909 | 409 |
15907
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
410 gateway = default_gw(); |
15909 | 411 |
15907
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
412 if (!gateway) |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
413 { |
15823 | 414 purple_debug_info("nat-pmp", "Cannot create mapping on a NULL gateway!\n"); |
15907
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
415 return FALSE; |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
416 } |
15907
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
417 |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
418 /* Default port for NAT-PMP is 5351 */ |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
419 if (gateway->sin_port != PMP_PORT) |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
420 gateway->sin_port = htons(PMP_PORT); |
15909 | 421 |
15907
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
422 resp = g_new0(PurplePmpMapResponse, 1); |
15909 | 423 |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
424 req_timeout.tv_sec = 0; |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
425 req_timeout.tv_usec = PMP_TIMEOUT; |
15909 | 426 |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
427 sendfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); |
15909 | 428 |
15907
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
429 /* Set up the req */ |
19268
db6218615be4
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 <daniel.atallah@gmail.com>
parents:
16919
diff
changeset
|
430 memset(&req, 0, sizeof(PurplePmpMapRequest)); |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
431 req.version = 0; |
19268
db6218615be4
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 <daniel.atallah@gmail.com>
parents:
16919
diff
changeset
|
432 req.opcode = ((type == PURPLE_PMP_TYPE_UDP) ? PMP_MAP_OPCODE_UDP : PMP_MAP_OPCODE_TCP); |
16345
6b4e778ee4b4
Death to // comments.
Richard Laager <rlaager@wiktel.com>
parents:
15975
diff
changeset
|
433 req.privateport = htons(privateport); /* What a difference byte ordering makes...d'oh! */ |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
434 req.publicport = htons(publicport); |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
435 req.lifetime = htonl(lifetime); |
15909 | 436 |
15907
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
437 /* The NAT-PMP spec says we should attempt to contact the gateway 9 times, doubling the time we wait each time. |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
438 * Even starting with a timeout of 0.1 seconds, that means that we have a total waiting of 204.6 seconds. |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
439 * With the recommended timeout of 0.25 seconds, we're talking 511.5 seconds (8.5 minutes). |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
440 * |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
441 * This seems really silly... if this were nonblocking, a couple retries might be in order, but it's not at present. |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
442 * XXX Make this nonblocking. |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
443 * XXX This code looks like the pmp_get_public_ip() code. Can it be consolidated? |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
444 */ |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
445 #ifdef PMP_DEBUG |
15907
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
446 purple_debug_info("nat-pmp", "Attempting to create a NAT-PMP mapping the private port %d, and the public port %d\n", privateport, publicport); |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
447 purple_debug_info("nat-pmp", "\tTimeout: %ds %dus\n", req_timeout.tv_sec, req_timeout.tv_usec); |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
448 #endif |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
449 |
15907
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
450 /* TODO: Non-blocking! */ |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
451 success = (sendto(sendfd, &req, sizeof(req), 0, (struct sockaddr *)(gateway), sizeof(struct sockaddr)) >= 0); |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
452 if (!success) |
21121
35b4f1dc4c8d
replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents:
20074
diff
changeset
|
453 purple_debug_info("nat-pmp", "There was an error sending the NAT-PMP mapping request! (%s)\n", g_strerror(errno)); |
15907
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
454 |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
455 if (success) |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
456 { |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
457 success = (setsockopt(sendfd, SOL_SOCKET, SO_RCVTIMEO, &req_timeout, sizeof(req_timeout)) >= 0); |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
458 if (!success) |
21121
35b4f1dc4c8d
replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents:
20074
diff
changeset
|
459 purple_debug_info("nat-pmp", "There was an error setting the socket's options! (%s)\n", g_strerror(errno)); |
15907
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
460 } |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
461 |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
462 if (success) |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
463 { |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
464 /* The original code treats EAGAIN as a reason to iterate.. but I've removed iteration. This may be a problem */ |
15900
9cfe41743c65
More complete namespacing of nat-pmp
Mark Doliner <mark@kingant.net>
parents:
15856
diff
changeset
|
465 /* TODO: Non-blocking! */ |
15907
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
466 success = ((recvfrom(sendfd, resp, sizeof(PurplePmpMapResponse), 0, NULL, NULL) >= 0) || |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
467 (errno == EAGAIN)); |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
468 if (!success) |
21121
35b4f1dc4c8d
replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents:
20074
diff
changeset
|
469 purple_debug_info("nat-pmp", "There was an error receiving the response from the NAT-PMP device! (%s)\n", g_strerror(errno)); |
15907
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
470 } |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
471 |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
472 if (success) |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
473 { |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
474 success = (resp->opcode == (req.opcode + 128)); |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
475 if (!success) |
22516
8972581c2326
Improved some of the debug output from nat-pmp
Evan Schoenberg <evan.s@dreskin.net>
parents:
21121
diff
changeset
|
476 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", |
8972581c2326
Improved some of the debug output from nat-pmp
Evan Schoenberg <evan.s@dreskin.net>
parents:
21121
diff
changeset
|
477 resp->opcode, req.opcode, req.opcode + 128); |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
478 } |
15907
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
479 |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
480 #ifdef PMP_DEBUG |
15907
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
481 if (success) |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
482 { |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
483 purple_debug_info("nat-pmp", "Response received from NAT-PMP device:\n"); |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
484 purple_debug_info("nat-pmp", "version: %d\n", resp->version); |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
485 purple_debug_info("nat-pmp", "opcode: %d\n", resp->opcode); |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
486 purple_debug_info("nat-pmp", "resultcode: %d\n", ntohs(resp->resultcode)); |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
487 purple_debug_info("nat-pmp", "epoch: %d\n", ntohl(resp->epoch)); |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
488 purple_debug_info("nat-pmp", "privateport: %d\n", ntohs(resp->privateport)); |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
489 purple_debug_info("nat-pmp", "publicport: %d\n", ntohs(resp->publicport)); |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
490 purple_debug_info("nat-pmp", "lifetime: %d\n", ntohl(resp->lifetime)); |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
491 } |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
492 #endif |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
493 |
15907
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
494 g_free(resp); |
15856
9b875f0ecb86
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 <evan.s@dreskin.net>
parents:
15823
diff
changeset
|
495 g_free(gateway); |
9b875f0ecb86
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 <evan.s@dreskin.net>
parents:
15823
diff
changeset
|
496 |
15907
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
497 /* XXX The private port may actually differ from the one we requested, according to the spec. |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
498 * We don't handle that situation at present. |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
499 * |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
500 * TODO: Look at the result and verify it matches what we wanted; either return a failure if it doesn't, |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
501 * or change network.c to know what to do if the desired private port shifts as a result of the nat-pmp operation. |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
502 */ |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
503 return success; |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
504 } |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
505 |
15907
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
506 gboolean |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
507 purple_pmp_destroy_map(PurplePmpType type, unsigned short privateport) |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
508 { |
15907
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
509 gboolean success; |
15909 | 510 |
15907
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
511 success = purple_pmp_create_map(((type == PURPLE_PMP_TYPE_UDP) ? PMP_MAP_OPCODE_UDP : PMP_MAP_OPCODE_TCP), |
15856
9b875f0ecb86
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 <evan.s@dreskin.net>
parents:
15823
diff
changeset
|
512 privateport, 0, 0); |
15907
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
513 if (!success) |
22516
8972581c2326
Improved some of the debug output from nat-pmp
Evan Schoenberg <evan.s@dreskin.net>
parents:
21121
diff
changeset
|
514 purple_debug_warning("nat-pmp", "Failed to properly destroy mapping for %s port %d!\n", |
8972581c2326
Improved some of the debug output from nat-pmp
Evan Schoenberg <evan.s@dreskin.net>
parents:
21121
diff
changeset
|
515 ((type == PURPLE_PMP_TYPE_UDP) ? "UDP" : "TCP"), privateport); |
15907
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
516 |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
517 return success; |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
518 } |
15974
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
519 |
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
520 static void |
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
521 purple_pmp_network_config_changed_cb(void *data) |
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
522 { |
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
523 pmp_info.status = PURPLE_PMP_STATUS_UNDISCOVERED; |
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
524 g_free(pmp_info.publicip); |
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
525 pmp_info.publicip = NULL; |
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
526 } |
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
527 |
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
528 static void* |
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
529 purple_pmp_get_handle(void) |
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
530 { |
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
531 static int handle; |
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
532 |
19268
db6218615be4
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 <daniel.atallah@gmail.com>
parents:
16919
diff
changeset
|
533 return &handle; |
15974
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
534 } |
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
535 |
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
536 void |
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
537 purple_pmp_init() |
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
538 { |
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
539 purple_signal_connect(purple_network_get_handle(), "network-configuration-changed", |
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
540 purple_pmp_get_handle(), PURPLE_CALLBACK(purple_pmp_network_config_changed_cb), |
19268
db6218615be4
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 <daniel.atallah@gmail.com>
parents:
16919
diff
changeset
|
541 GINT_TO_POINTER(0)); |
15974
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
542 } |
15950
45cbb80bfd54
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 <evan.s@dreskin.net>
parents:
15923
diff
changeset
|
543 #else /* #ifdef NET_RT_DUMP */ |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
544 char * |
15823 | 545 purple_pmp_get_public_ip() |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
546 { |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
547 return NULL; |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
548 } |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
549 |
15907
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
550 gboolean |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
551 purple_pmp_create_map(PurplePmpType type, unsigned short privateport, unsigned short publicport, int lifetime) |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
552 { |
15923
8bea220c0997
These should return FALSE, not NULL, when NET_RT_DUMP2 isn't available; they return a gboolean, not a pointer.
Evan Schoenberg <evan.s@dreskin.net>
parents:
15909
diff
changeset
|
553 return FALSE; |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
554 } |
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
555 |
15907
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
556 gboolean |
2cf21661f828
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 <evan.s@dreskin.net>
parents:
15900
diff
changeset
|
557 purple_pmp_destroy_map(PurplePmpType type, unsigned short privateport) |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
558 { |
15923
8bea220c0997
These should return FALSE, not NULL, when NET_RT_DUMP2 isn't available; they return a gboolean, not a pointer.
Evan Schoenberg <evan.s@dreskin.net>
parents:
15909
diff
changeset
|
559 return FALSE; |
15647
552be3958d6a
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff
changeset
|
560 } |
15974
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
561 |
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
562 void |
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
563 purple_pmp_init() |
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
564 { |
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
565 |
1a12ce76c4f4
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 <evan.s@dreskin.net>
parents:
15950
diff
changeset
|
566 } |
16919
d0e74d0be43f
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 <evan.s@dreskin.net>
parents:
16918
diff
changeset
|
567 #endif /* #if !(defined(HAVE_SYS_SYCTL_H) && defined(NET_RT_DUMP)) */ |