Sun, 25 Mar 2007 00:41:31 +0000
More complete namespacing of nat-pmp
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
1 | /** |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
2 | * @file nat-pmp.c NAT-PMP Implementation |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
3 | * @ingroup core |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
4 | * |
| 15884 | 5 | * purple |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
6 | * |
| 15884 | 7 | * Purple is the legal property of its developers, whose names are too numerous |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
8 | * to list here. Please refer to the COPYRIGHT file distributed with this |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
9 | * source distribution. |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
10 | * |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
11 | * Most code in nat-pmp.c copyright (C) 2007, R. Tyler Ballance, bleep, LLC. |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
12 | * This file is distributed under the 3-clause (modified) BSD license: |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
13 | * Redistribution and use in source and binary forms, with or without modification, are permitted |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
14 | * provided that the following conditions are met: |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
15 | * |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
16 | * Redistributions of source code must retain the above copyright notice, this list of conditions and |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
17 | * the following disclaimer. |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
18 | * Neither the name of the bleep. LLC nor the names of its contributors may be used to endorse or promote |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
19 | * products derived from this software without specific prior written permission. |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
20 | * |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
22 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
23 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
25 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
28 | * OF SUCH DAMAGE. |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
29 | */ |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
30 | |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
31 | #include "nat-pmp.h" |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
32 | #include "debug.h" |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
33 | |
|
15961
a3ef09c8ca24
More complete namespacing of nat-pmp
Mark Doliner <markdoliner@pidgin.im>
parents:
15933
diff
changeset
|
34 | #include <arpa/inet.h> |
|
a3ef09c8ca24
More complete namespacing of nat-pmp
Mark Doliner <markdoliner@pidgin.im>
parents:
15933
diff
changeset
|
35 | #include <net/route.h> |
|
a3ef09c8ca24
More complete namespacing of nat-pmp
Mark Doliner <markdoliner@pidgin.im>
parents:
15933
diff
changeset
|
36 | #include <netinet/in.h> |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
37 | #include <sys/socket.h> |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
38 | #include <sys/sysctl.h> |
|
15961
a3ef09c8ca24
More complete namespacing of nat-pmp
Mark Doliner <markdoliner@pidgin.im>
parents:
15933
diff
changeset
|
39 | #include <sys/types.h> |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
40 | |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
41 | #include <netdb.h> |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
42 | #include <stdio.h> |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
43 | #include <stdlib.h> |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
44 | #include <string.h> |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
45 | #include <err.h> |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
46 | |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
47 | #include <errno.h> |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
48 | #include <sys/types.h> |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
49 | #include <net/if.h> |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
50 | |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
51 | #ifdef NET_RT_DUMP2 |
|
15933
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
52 | |
|
15961
a3ef09c8ca24
More complete namespacing of nat-pmp
Mark Doliner <markdoliner@pidgin.im>
parents:
15933
diff
changeset
|
53 | #define PMP_DEBUG 1 |
|
15933
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
54 | |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
55 | /* |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
56 | * Thanks to R. Matthew Emerson for the fixes on this |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
57 | */ |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
58 | |
|
15933
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
59 | #define PMP_MAP_OPCODE_UDP 1 |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
60 | #define PMP_MAP_OPCODE_TCP 2 |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
61 | |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
62 | #define PMP_VERSION 0 |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
63 | #define PMP_PORT 5351 |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
64 | #define PMP_TIMEOUT 250000 // 250000 useconds |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
65 | |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
66 | /* alignment constraint for routing socket */ |
|
15933
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
67 | #define ROUNDUP(a) ((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long)) |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
68 | #define ADVANCE(x, n) (x += ROUNDUP((n)->sa_len)) |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
69 | |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
70 | static void |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
71 | get_rtaddrs(int bitmask, struct sockaddr *sa, struct sockaddr *addrs[]) |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
72 | { |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
73 | int i; |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
74 | |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
75 | for (i = 0; i < RTAX_MAX; i++) |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
76 | { |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
77 | if (bitmask & (1 << i)) |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
78 | { |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
79 | addrs[i] = sa; |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
80 | sa = (struct sockaddr *)(ROUNDUP(sa->sa_len) + (char *)sa); |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
81 | } |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
82 | else |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
83 | { |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
84 | addrs[i] = NULL; |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
85 | } |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
86 | } |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
87 | } |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
88 | |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
89 | static int |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
90 | is_default_route(struct sockaddr *sa, struct sockaddr *mask) |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
91 | { |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
92 | struct sockaddr_in *sin; |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
93 | |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
94 | if (sa->sa_family != AF_INET) |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
95 | return 0; |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
96 | |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
97 | sin = (struct sockaddr_in *)sa; |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
98 | if ((sin->sin_addr.s_addr == INADDR_ANY) && |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
99 | mask && |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
100 | (ntohl(((struct sockaddr_in *)mask)->sin_addr.s_addr) == 0L || |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
101 | mask->sa_len == 0)) |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
102 | return 1; |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
103 | else |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
104 | return 0; |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
105 | } |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
106 | |
|
15933
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
107 | /*! |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
108 | * The return sockaddr_in must be g_free()'d when no longer needed |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
109 | */ |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
110 | static struct sockaddr_in * |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
111 | default_gw() |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
112 | { |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
113 | int mib[6]; |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
114 | size_t needed; |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
115 | char *buf, *next, *lim; |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
116 | struct rt_msghdr2 *rtm; |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
117 | struct sockaddr *sa; |
|
15933
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
118 | struct sockaddr_in *sin = NULL; |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
119 | gboolean found = FALSE; |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
120 | |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
121 | mib[0] = CTL_NET; |
|
15933
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
122 | mib[1] = PF_ROUTE; /* entire routing table or a subset of it */ |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
123 | mib[2] = 0; /* protocol number - always 0 */ |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
124 | mib[3] = 0; /* address family - 0 for all addres families */ |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
125 | mib[4] = NET_RT_DUMP2; |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
126 | mib[5] = 0; |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
127 | |
|
15933
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
128 | /* Determine the buffer side needed to get the full routing table */ |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
129 | if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0) |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
130 | { |
|
15933
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
131 | purple_debug_warning("nat-pmp", "sysctl: net.route.0.0.dump estimate"); |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
132 | return NULL; |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
133 | } |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
134 | |
|
15933
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
135 | if (!(buf = malloc(needed))) |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
136 | { |
|
15933
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
137 | purple_debug_warning("nat-pmp", "malloc"); |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
138 | return NULL; |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
139 | } |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
140 | |
|
15933
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
141 | /* Read the routing table into buf */ |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
142 | if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0) |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
143 | { |
|
15933
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
144 | purple_debug_warning("nat-pmp", "sysctl: net.route.0.0.dump"); |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
145 | return NULL; |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
146 | } |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
147 | |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
148 | lim = buf + needed; |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
149 | |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
150 | for (next = buf; next < lim; next += rtm->rtm_msglen) |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
151 | { |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
152 | rtm = (struct rt_msghdr2 *)next; |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
153 | sa = (struct sockaddr *)(rtm + 1); |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
154 | |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
155 | if (sa->sa_family == AF_INET) |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
156 | { |
|
15933
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
157 | sin = (struct sockaddr_in*) sa; |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
158 | |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
159 | if ((rtm->rtm_flags & RTF_GATEWAY) && sin->sin_addr.s_addr == INADDR_ANY) |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
160 | { |
|
15933
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
161 | /* We found the default route. Now get the destination address and netmask. */ |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
162 | struct sockaddr *rti_info[RTAX_MAX]; |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
163 | struct sockaddr addr, mask; |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
164 | |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
165 | get_rtaddrs(rtm->rtm_addrs, sa, rti_info); |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
166 | bzero(&addr, sizeof(addr)); |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
167 | |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
168 | if (rtm->rtm_addrs & RTA_DST) |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
169 | bcopy(rti_info[RTAX_DST], &addr, rti_info[RTAX_DST]->sa_len); |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
170 | |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
171 | bzero(&mask, sizeof(mask)); |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
172 | |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
173 | if (rtm->rtm_addrs & RTA_NETMASK) |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
174 | bcopy(rti_info[RTAX_NETMASK], &mask, rti_info[RTAX_NETMASK]->sa_len); |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
175 | |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
176 | if (rtm->rtm_addrs & RTA_GATEWAY && |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
177 | is_default_route(&addr, &mask)) |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
178 | { |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
179 | if (rti_info[RTAX_GATEWAY]) { |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
180 | struct sockaddr_in *rti_sin = (struct sockaddr_in *)rti_info[RTAX_GATEWAY]; |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
181 | sin = g_new0(struct sockaddr_in, 1); |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
182 | sin->sin_family = rti_sin->sin_family; |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
183 | sin->sin_port = rti_sin->sin_port; |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
184 | sin->sin_addr.s_addr = rti_sin->sin_addr.s_addr; |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
185 | memcpy(sin, rti_info[RTAX_GATEWAY], sizeof(struct sockaddr_in)); |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
186 | |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
187 | purple_debug_info("nat-pmp", "found a default gateway"); |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
188 | found = TRUE; |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
189 | break; |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
190 | } |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
191 | } |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
192 | } |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
193 | } |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
194 | } |
|
15933
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
195 | |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
196 | return (found ? sin : NULL); |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
197 | } |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
198 | |
|
15933
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
199 | /*! |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
200 | * double_timeout(struct timeval *) will handle doubling a timeout for backoffs required by NAT-PMP |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
201 | */ |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
202 | static void |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
203 | double_timeout(struct timeval *to) |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
204 | { |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
205 | int second = 1000000; // number of useconds |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
206 | |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
207 | to->tv_sec = (to->tv_sec * 2); |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
208 | to->tv_usec = (to->tv_usec * 2); |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
209 | |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
210 | // Overflow useconds if necessary |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
211 | if (to->tv_usec >= second) |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
212 | { |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
213 | int overflow = (to->tv_usec / second); |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
214 | to->tv_usec = (to->tv_usec - (overflow * second)); |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
215 | to->tv_sec = (to->tv_sec + overflow); |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
216 | } |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
217 | } |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
218 | |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
219 | /*! |
| 15884 | 220 | * purple_pmp_get_public_ip() will return the publicly facing IP address of the |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
221 | * default NAT gateway. The function will return NULL if: |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
222 | * - The gateway doesn't support NAT-PMP |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
223 | * - The gateway errors in some other spectacular fashion |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
224 | */ |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
225 | char * |
| 15884 | 226 | purple_pmp_get_public_ip() |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
227 | { |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
228 | struct sockaddr_in *gateway = default_gw(); |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
229 | |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
230 | if (gateway == NULL) |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
231 | { |
| 15884 | 232 | purple_debug_info("nat-pmp", "Cannot request public IP from a NULL gateway!\n"); |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
233 | return NULL; |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
234 | } |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
235 | if (gateway->sin_port != PMP_PORT) |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
236 | { |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
237 | gateway->sin_port = htons(PMP_PORT); // Default port for NAT-PMP is 5351 |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
238 | } |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
239 | |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
240 | int sendfd; |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
241 | int req_attempts = 1; |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
242 | struct timeval req_timeout; |
|
15961
a3ef09c8ca24
More complete namespacing of nat-pmp
Mark Doliner <markdoliner@pidgin.im>
parents:
15933
diff
changeset
|
243 | PurplePmpIpRequest req; |
|
a3ef09c8ca24
More complete namespacing of nat-pmp
Mark Doliner <markdoliner@pidgin.im>
parents:
15933
diff
changeset
|
244 | PurplePmpIpResponse resp; |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
245 | struct sockaddr_in *publicsockaddr = NULL; |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
246 | |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
247 | req_timeout.tv_sec = 0; |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
248 | req_timeout.tv_usec = PMP_TIMEOUT; |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
249 | |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
250 | sendfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
251 | |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
252 | // Clean out both req and resp structures |
|
15961
a3ef09c8ca24
More complete namespacing of nat-pmp
Mark Doliner <markdoliner@pidgin.im>
parents:
15933
diff
changeset
|
253 | bzero(&req, sizeof(PurplePmpIpRequest)); |
|
a3ef09c8ca24
More complete namespacing of nat-pmp
Mark Doliner <markdoliner@pidgin.im>
parents:
15933
diff
changeset
|
254 | bzero(&resp, sizeof(PurplePmpIpResponse)); |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
255 | req.version = 0; |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
256 | req.opcode = 0; |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
257 | |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
258 | // Attempt to contact NAT-PMP device 9 times as per: draft-cheshire-nat-pmp-02.txt |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
259 | while (req_attempts < 10) |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
260 | { |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
261 | #ifdef PMP_DEBUG |
| 15884 | 262 | purple_debug_info("nat-pmp", "Attempting to retrieve the public ip address for the NAT device at: %s\n", inet_ntoa(gateway->sin_addr)); |
| 263 | purple_debug_info("nat-pmp", "\tTimeout: %ds %dus, Request #: %d\n", req_timeout.tv_sec, req_timeout.tv_usec, req_attempts); | |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
264 | #endif |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
265 | struct sockaddr_in addr; |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
266 | socklen_t len = sizeof(struct sockaddr_in); |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
267 | |
|
15961
a3ef09c8ca24
More complete namespacing of nat-pmp
Mark Doliner <markdoliner@pidgin.im>
parents:
15933
diff
changeset
|
268 | /* TODO: Non-blocking! */ |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
269 | if (sendto(sendfd, &req, sizeof(req), 0, (struct sockaddr *)(gateway), sizeof(struct sockaddr)) < 0) |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
270 | { |
| 15884 | 271 | purple_debug_info("nat-pmp", "There was an error sending the NAT-PMP public IP request! (%s)\n", strerror(errno)); |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
272 | return NULL; |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
273 | } |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
274 | |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
275 | if (setsockopt(sendfd, SOL_SOCKET, SO_RCVTIMEO, &req_timeout, sizeof(req_timeout)) < 0) |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
276 | { |
| 15884 | 277 | purple_debug_info("nat-pmp", "There was an error setting the socket's options! (%s)\n", strerror(errno)); |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
278 | return NULL; |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
279 | } |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
280 | |
|
15961
a3ef09c8ca24
More complete namespacing of nat-pmp
Mark Doliner <markdoliner@pidgin.im>
parents:
15933
diff
changeset
|
281 | /* TODO: Non-blocking! */ |
|
a3ef09c8ca24
More complete namespacing of nat-pmp
Mark Doliner <markdoliner@pidgin.im>
parents:
15933
diff
changeset
|
282 | if (recvfrom(sendfd, &resp, sizeof(PurplePmpIpResponse), 0, (struct sockaddr *)(&addr), &len) < 0) |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
283 | { |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
284 | if ( (errno != EAGAIN) || (req_attempts == 9) ) |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
285 | { |
| 15884 | 286 | purple_debug_info("nat-pmp", "There was an error receiving the response from the NAT-PMP device! (%s)\n", strerror(errno)); |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
287 | return NULL; |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
288 | } |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
289 | else |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
290 | { |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
291 | goto iterate; |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
292 | } |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
293 | } |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
294 | |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
295 | if (addr.sin_addr.s_addr != gateway->sin_addr.s_addr) |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
296 | { |
| 15884 | 297 | purple_debug_info("nat-pmp", "Response was not received from our gateway! Instead from: %s\n", inet_ntoa(addr.sin_addr)); |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
298 | goto iterate; |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
299 | } |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
300 | else |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
301 | { |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
302 | publicsockaddr = &addr; |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
303 | break; |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
304 | } |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
305 | |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
306 | iterate: |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
307 | ++req_attempts; |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
308 | double_timeout(&req_timeout); |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
309 | } |
|
15933
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
310 | |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
311 | if (publicsockaddr == NULL) { |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
312 | g_free(gateway); |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
313 | return NULL; |
|
15933
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
314 | } |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
315 | |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
316 | #ifdef PMP_DEBUG |
| 15884 | 317 | purple_debug_info("nat-pmp", "Response received from NAT-PMP device:\n"); |
| 318 | purple_debug_info("nat-pmp", "version: %d\n", resp.version); | |
| 319 | purple_debug_info("nat-pmp", "opcode: %d\n", resp.opcode); | |
| 320 | purple_debug_info("nat-pmp", "resultcode: %d\n", ntohs(resp.resultcode)); | |
| 321 | purple_debug_info("nat-pmp", "epoch: %d\n", ntohl(resp.epoch)); | |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
322 | struct in_addr in; |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
323 | in.s_addr = resp.address; |
| 15884 | 324 | purple_debug_info("nat-pmp", "address: %s\n", inet_ntoa(in)); |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
325 | #endif |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
326 | |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
327 | publicsockaddr->sin_addr.s_addr = resp.address; |
|
15933
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
328 | |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
329 | g_free(gateway); |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
330 | |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
331 | return inet_ntoa(publicsockaddr->sin_addr); |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
332 | } |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
333 | |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
334 | /*! |
|
15961
a3ef09c8ca24
More complete namespacing of nat-pmp
Mark Doliner <markdoliner@pidgin.im>
parents:
15933
diff
changeset
|
335 | * will return NULL on error, or a pointer to the PurplePmpMapResponse type |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
336 | */ |
|
15961
a3ef09c8ca24
More complete namespacing of nat-pmp
Mark Doliner <markdoliner@pidgin.im>
parents:
15933
diff
changeset
|
337 | PurplePmpMapResponse * |
|
15933
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
338 | purple_pmp_create_map(PurplePmpType type, uint16_t privateport, uint16_t publicport, uint32_t lifetime) |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
339 | { |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
340 | struct sockaddr_in *gateway = default_gw(); |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
341 | |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
342 | if (gateway == NULL) |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
343 | { |
| 15884 | 344 | purple_debug_info("nat-pmp", "Cannot create mapping on a NULL gateway!\n"); |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
345 | return NULL; |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
346 | } |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
347 | if (gateway->sin_port != PMP_PORT) |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
348 | { |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
349 | gateway->sin_port = htons(PMP_PORT); // Default port for NAT-PMP is 5351 |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
350 | } |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
351 | |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
352 | int sendfd; |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
353 | int req_attempts = 1; |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
354 | struct timeval req_timeout; |
|
15961
a3ef09c8ca24
More complete namespacing of nat-pmp
Mark Doliner <markdoliner@pidgin.im>
parents:
15933
diff
changeset
|
355 | PurplePmpMapRequest req; |
|
a3ef09c8ca24
More complete namespacing of nat-pmp
Mark Doliner <markdoliner@pidgin.im>
parents:
15933
diff
changeset
|
356 | PurplePmpMapResponse *resp = (PurplePmpMapResponse *)(malloc(sizeof(PurplePmpMapResponse))); |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
357 | |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
358 | req_timeout.tv_sec = 0; |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
359 | req_timeout.tv_usec = PMP_TIMEOUT; |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
360 | |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
361 | sendfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
362 | |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
363 | // Clean out both req and resp structures |
|
15961
a3ef09c8ca24
More complete namespacing of nat-pmp
Mark Doliner <markdoliner@pidgin.im>
parents:
15933
diff
changeset
|
364 | bzero(&req, sizeof(PurplePmpMapRequest)); |
|
a3ef09c8ca24
More complete namespacing of nat-pmp
Mark Doliner <markdoliner@pidgin.im>
parents:
15933
diff
changeset
|
365 | bzero(resp, sizeof(PurplePmpMapResponse)); |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
366 | req.version = 0; |
|
15933
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
367 | req.opcode = ((type == PURPLE_PMP_TYPE_UDP) ? PMP_MAP_OPCODE_UDP : PMP_MAP_OPCODE_TCP); |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
368 | req.privateport = htons(privateport); // What a difference byte ordering makes...d'oh! |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
369 | req.publicport = htons(publicport); |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
370 | req.lifetime = htonl(lifetime); |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
371 | |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
372 | // Attempt to contact NAT-PMP device 9 times as per: draft-cheshire-nat-pmp-02.txt |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
373 | while (req_attempts < 10) |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
374 | { |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
375 | #ifdef PMP_DEBUG |
| 15884 | 376 | purple_debug_info("nat-pmp", "Attempting to create a NAT-PMP mapping the private port %d, and the public port %d\n", privateport, publicport); |
| 377 | purple_debug_info("nat-pmp", "\tTimeout: %ds %dus, Request #: %d\n", req_timeout.tv_sec, req_timeout.tv_usec, req_attempts); | |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
378 | #endif |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
379 | |
|
15961
a3ef09c8ca24
More complete namespacing of nat-pmp
Mark Doliner <markdoliner@pidgin.im>
parents:
15933
diff
changeset
|
380 | /* TODO: Non-blocking! */ |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
381 | if (sendto(sendfd, &req, sizeof(req), 0, (struct sockaddr *)(gateway), sizeof(struct sockaddr)) < 0) |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
382 | { |
| 15884 | 383 | purple_debug_info("nat-pmp", "There was an error sending the NAT-PMP mapping request! (%s)\n", strerror(errno)); |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
384 | return NULL; |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
385 | } |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
386 | |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
387 | if (setsockopt(sendfd, SOL_SOCKET, SO_RCVTIMEO, &req_timeout, sizeof(req_timeout)) < 0) |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
388 | { |
| 15884 | 389 | purple_debug_info("nat-pmp", "There was an error setting the socket's options! (%s)\n", strerror(errno)); |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
390 | return NULL; |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
391 | } |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
392 | |
|
15961
a3ef09c8ca24
More complete namespacing of nat-pmp
Mark Doliner <markdoliner@pidgin.im>
parents:
15933
diff
changeset
|
393 | /* TODO: Non-blocking! */ |
|
a3ef09c8ca24
More complete namespacing of nat-pmp
Mark Doliner <markdoliner@pidgin.im>
parents:
15933
diff
changeset
|
394 | if (recvfrom(sendfd, resp, sizeof(PurplePmpMapResponse), 0, NULL, NULL) < 0) |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
395 | { |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
396 | if ( (errno != EAGAIN) || (req_attempts == 9) ) |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
397 | { |
| 15884 | 398 | purple_debug_info("nat-pmp", "There was an error receiving the response from the NAT-PMP device! (%s)\n", strerror(errno)); |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
399 | return NULL; |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
400 | } |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
401 | else |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
402 | { |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
403 | goto iterate; |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
404 | } |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
405 | } |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
406 | |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
407 | if (resp->opcode != (req.opcode + 128)) |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
408 | { |
| 15884 | 409 | purple_debug_info("nat-pmp", "The opcode for the response from the NAT device does not match the request opcode!\n"); |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
410 | goto iterate; |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
411 | } |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
412 | |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
413 | break; |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
414 | |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
415 | iterate: |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
416 | ++req_attempts; |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
417 | double_timeout(&req_timeout); |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
418 | } |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
419 | |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
420 | #ifdef PMP_DEBUG |
| 15884 | 421 | purple_debug_info("nat-pmp", "Response received from NAT-PMP device:\n"); |
| 422 | purple_debug_info("nat-pmp", "version: %d\n", resp->version); | |
| 423 | purple_debug_info("nat-pmp", "opcode: %d\n", resp->opcode); | |
| 424 | purple_debug_info("nat-pmp", "resultcode: %d\n", ntohs(resp->resultcode)); | |
| 425 | purple_debug_info("nat-pmp", "epoch: %d\n", ntohl(resp->epoch)); | |
| 426 | purple_debug_info("nat-pmp", "privateport: %d\n", ntohs(resp->privateport)); | |
| 427 | purple_debug_info("nat-pmp", "publicport: %d\n", ntohs(resp->publicport)); | |
| 428 | purple_debug_info("nat-pmp", "lifetime: %d\n", ntohl(resp->lifetime)); | |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
429 | #endif |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
430 | |
|
15933
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
431 | g_free(gateway); |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
432 | |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
433 | return resp; |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
434 | } |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
435 | |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
436 | /*! |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
437 | * pmp_destroy_map(uint8_t,uint16_t) |
|
15961
a3ef09c8ca24
More complete namespacing of nat-pmp
Mark Doliner <markdoliner@pidgin.im>
parents:
15933
diff
changeset
|
438 | * will return NULL on error, or a pointer to the PurplePmpMapResponse type |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
439 | */ |
|
15961
a3ef09c8ca24
More complete namespacing of nat-pmp
Mark Doliner <markdoliner@pidgin.im>
parents:
15933
diff
changeset
|
440 | PurplePmpMapResponse * |
|
15933
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
441 | purple_pmp_destroy_map(PurplePmpType type, uint16_t privateport) |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
442 | { |
|
15961
a3ef09c8ca24
More complete namespacing of nat-pmp
Mark Doliner <markdoliner@pidgin.im>
parents:
15933
diff
changeset
|
443 | PurplePmpMapResponse *response; |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
444 | |
|
15933
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
445 | response = purple_pmp_create_map(((type == PURPLE_PMP_TYPE_UDP) ? PMP_MAP_OPCODE_UDP : PMP_MAP_OPCODE_TCP), |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
446 | privateport, 0, 0); |
|
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
447 | if (!response) |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
448 | { |
| 15884 | 449 | purple_debug_info("nat-pmp", "Failed to properly destroy mapping for %d!\n", privateport); |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
450 | return NULL; |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
451 | } |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
452 | else |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
453 | { |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
454 | return response; |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
455 | } |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
456 | } |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
457 | #else /* #ifdef NET_RT_DUMP2 */ |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
458 | char * |
| 15884 | 459 | purple_pmp_get_public_ip() |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
460 | { |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
461 | return NULL; |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
462 | } |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
463 | |
|
15961
a3ef09c8ca24
More complete namespacing of nat-pmp
Mark Doliner <markdoliner@pidgin.im>
parents:
15933
diff
changeset
|
464 | PurplePmpMapResponse * |
|
15933
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
465 | purple_pmp_create_map(PurplePmpType type, uint16_t privateport, uint16_t publicport, uint32_t lifetime) |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
466 | { |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
467 | return NULL; |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
468 | } |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
469 | |
|
15961
a3ef09c8ca24
More complete namespacing of nat-pmp
Mark Doliner <markdoliner@pidgin.im>
parents:
15933
diff
changeset
|
470 | PurplePmpMapResponse * |
|
15933
913ba1d4b81c
nat-pmp is now functional with a compatible router. I'm not enabling this code yet because it hasn't been tested with a router which doesn't support nat-pmp.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
471 | purple_pmp_destroy_map(PurplePmpType type, uint16_t privateport) |
|
15708
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
472 | { |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
473 | return NULL; |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
474 | } |
|
979f43512119
Added nat-pmp implementation and #ifdef'd out changes to network.c which would utilize it.
Evan Schoenberg <evands@pidgin.im>
parents:
diff
changeset
|
475 | #endif /* #ifndef NET_RT_DUMP2 */ |