diff options
author | Nathan S. Evans <evans@in.tum.de> | 2010-06-08 13:27:11 +0000 |
---|---|---|
committer | Nathan S. Evans <evans@in.tum.de> | 2010-06-08 13:27:11 +0000 |
commit | 87f73e3aee4a5f582ffb71e925f1f1d4f30e26d2 (patch) | |
tree | b491849e5f80047f69043d5012e4654d2431c819 /src/transport/gnunet-nat-server.c | |
parent | 318da8efb4ad0f80439aa83cff43849c020b61a6 (diff) | |
download | gnunet-87f73e3aee4a5f582ffb71e925f1f1d4f30e26d2.tar.gz gnunet-87f73e3aee4a5f582ffb71e925f1f1d4f30e26d2.zip |
add UDP inside ICMP for NAT punch
Diffstat (limited to 'src/transport/gnunet-nat-server.c')
-rw-r--r-- | src/transport/gnunet-nat-server.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/transport/gnunet-nat-server.c b/src/transport/gnunet-nat-server.c index dcea365f8..8f39ab374 100644 --- a/src/transport/gnunet-nat-server.c +++ b/src/transport/gnunet-nat-server.c | |||
@@ -91,6 +91,14 @@ struct icmp_packet | |||
91 | uint32_t reserved; | 91 | uint32_t reserved; |
92 | }; | 92 | }; |
93 | 93 | ||
94 | struct udp_packet | ||
95 | { | ||
96 | uint16_t src_port; | ||
97 | |||
98 | uint16_t dst_port; | ||
99 | |||
100 | uint32_t length; | ||
101 | }; | ||
94 | 102 | ||
95 | static int icmpsock; | 103 | static int icmpsock; |
96 | 104 | ||
@@ -192,8 +200,10 @@ process_icmp_response () | |||
192 | struct in_addr sip; | 200 | struct in_addr sip; |
193 | struct ip_packet ip_pkt; | 201 | struct ip_packet ip_pkt; |
194 | struct icmp_packet icmp_pkt; | 202 | struct icmp_packet icmp_pkt; |
203 | struct udp_packet udp_pkt; | ||
195 | size_t off; | 204 | size_t off; |
196 | int have_port; | 205 | int have_port; |
206 | int have_udp; | ||
197 | uint32_t port; | 207 | uint32_t port; |
198 | 208 | ||
199 | have = read (icmpsock, buf, sizeof (buf)); | 209 | have = read (icmpsock, buf, sizeof (buf)); |
@@ -205,6 +215,7 @@ process_icmp_response () | |||
205 | return; | 215 | return; |
206 | } | 216 | } |
207 | have_port = 0; | 217 | have_port = 0; |
218 | |||
208 | if (have == sizeof (struct ip_packet) *2 + sizeof (struct icmp_packet) * 2 + sizeof(uint32_t)) | 219 | if (have == sizeof (struct ip_packet) *2 + sizeof (struct icmp_packet) * 2 + sizeof(uint32_t)) |
209 | { | 220 | { |
210 | have_port = 1; | 221 | have_port = 1; |
@@ -233,6 +244,15 @@ process_icmp_response () | |||
233 | memcpy(&sip, | 244 | memcpy(&sip, |
234 | &ip_pkt.src_ip, | 245 | &ip_pkt.src_ip, |
235 | sizeof (sip)); | 246 | sizeof (sip)); |
247 | |||
248 | memcpy (&ip_pkt, &buf[off], sizeof (ip_pkt)); | ||
249 | off += sizeof (ip_pkt); | ||
250 | |||
251 | if (ip_pkt.proto == IPPROTO_UDP) | ||
252 | { | ||
253 | have_udp = 1; | ||
254 | } | ||
255 | |||
236 | if (have_port) | 256 | if (have_port) |
237 | { | 257 | { |
238 | memcpy(&port, &buf[sizeof (struct ip_packet) *2 + sizeof (struct icmp_packet) * 2], sizeof(uint32_t)); | 258 | memcpy(&port, &buf[sizeof (struct ip_packet) *2 + sizeof (struct icmp_packet) * 2], sizeof(uint32_t)); |
@@ -244,6 +264,16 @@ process_icmp_response () | |||
244 | buf, | 264 | buf, |
245 | sizeof (buf)), port); | 265 | sizeof (buf)), port); |
246 | } | 266 | } |
267 | else if (have_udp) | ||
268 | { | ||
269 | memcpy(&udp_pkt, &buf[off], sizeof(udp_pkt)); | ||
270 | fprintf (stdout, | ||
271 | "%s:%d\n", | ||
272 | inet_ntop (AF_INET, | ||
273 | &sip, | ||
274 | buf, | ||
275 | sizeof (buf)), ntohl(udp_pkt.length)); | ||
276 | } | ||
247 | else | 277 | else |
248 | { | 278 | { |
249 | fprintf (stdout, | 279 | fprintf (stdout, |