diff options
Diffstat (limited to 'src/transport/gnunet-nat-server.c')
-rw-r--r-- | src/transport/gnunet-nat-server.c | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/src/transport/gnunet-nat-server.c b/src/transport/gnunet-nat-server.c index df6b69c65..6bead4c31 100644 --- a/src/transport/gnunet-nat-server.c +++ b/src/transport/gnunet-nat-server.c | |||
@@ -62,7 +62,7 @@ | |||
62 | */ | 62 | */ |
63 | #define DUMMY_IP "1.2.3.4" | 63 | #define DUMMY_IP "1.2.3.4" |
64 | 64 | ||
65 | #define VERBOSE GNUNET_NO | 65 | #define VERBOSE 1 |
66 | 66 | ||
67 | /** | 67 | /** |
68 | * How often do we send our ICMP messages to receive replies? | 68 | * How often do we send our ICMP messages to receive replies? |
@@ -193,6 +193,8 @@ process_icmp_response () | |||
193 | struct ip_packet ip_pkt; | 193 | struct ip_packet ip_pkt; |
194 | struct icmp_packet icmp_pkt; | 194 | struct icmp_packet icmp_pkt; |
195 | size_t off; | 195 | size_t off; |
196 | int have_port; | ||
197 | uint32_t port; | ||
196 | 198 | ||
197 | have = read (icmpsock, buf, sizeof (buf)); | 199 | have = read (icmpsock, buf, sizeof (buf)); |
198 | if (have == -1) | 200 | if (have == -1) |
@@ -202,7 +204,12 @@ process_icmp_response () | |||
202 | strerror (errno)); | 204 | strerror (errno)); |
203 | return; | 205 | return; |
204 | } | 206 | } |
205 | if (have != sizeof (struct ip_packet) *2 + sizeof (struct icmp_packet) * 2) | 207 | have_port = 0; |
208 | if (have == sizeof (struct ip_packet) *2 + sizeof (struct icmp_packet) * 2 + sizeof(uint32_t)) | ||
209 | { | ||
210 | have_port = 1; | ||
211 | } | ||
212 | else if (have != sizeof (struct ip_packet) *2 + sizeof (struct icmp_packet) * 2) | ||
206 | { | 213 | { |
207 | #if VERBOSE | 214 | #if VERBOSE |
208 | fprintf (stderr, | 215 | fprintf (stderr, |
@@ -226,12 +233,26 @@ process_icmp_response () | |||
226 | memcpy(&sip, | 233 | memcpy(&sip, |
227 | &ip_pkt.src_ip, | 234 | &ip_pkt.src_ip, |
228 | sizeof (sip)); | 235 | sizeof (sip)); |
229 | fprintf (stdout, | 236 | if (have_port) |
230 | "%s\n", | 237 | { |
231 | inet_ntop (AF_INET, | 238 | memcpy(&port, &buf[sizeof (struct ip_packet) *2 + sizeof (struct icmp_packet) * 2], sizeof(uint32_t)); |
232 | &sip, | 239 | port = ntohs(port); |
233 | buf, | 240 | fprintf (stdout, |
234 | sizeof (buf))); | 241 | "%s:%d\n", |
242 | inet_ntop (AF_INET, | ||
243 | &sip, | ||
244 | buf, | ||
245 | sizeof (buf)), port); | ||
246 | } | ||
247 | else | ||
248 | { | ||
249 | fprintf (stdout, | ||
250 | "%s\n", | ||
251 | inet_ntop (AF_INET, | ||
252 | &sip, | ||
253 | buf, | ||
254 | sizeof (buf))); | ||
255 | } | ||
235 | fflush (stdout); | 256 | fflush (stdout); |
236 | } | 257 | } |
237 | 258 | ||