aboutsummaryrefslogtreecommitdiff
path: root/src/nat/gnunet-nat-server.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-07-01 21:30:28 +0000
committerChristian Grothoff <christian@grothoff.org>2011-07-01 21:30:28 +0000
commite3f24011c0e95a67d673b43348202b7751574474 (patch)
tree89fff5172468c23f762c3db9c531b3e792da56dc /src/nat/gnunet-nat-server.c
parent490cf7e092613f7c511b46332710187336eb3a6a (diff)
downloadgnunet-e3f24011c0e95a67d673b43348202b7751574474.tar.gz
gnunet-e3f24011c0e95a67d673b43348202b7751574474.zip
testcase for nat test code
Diffstat (limited to 'src/nat/gnunet-nat-server.c')
-rw-r--r--src/nat/gnunet-nat-server.c33
1 files changed, 27 insertions, 6 deletions
diff --git a/src/nat/gnunet-nat-server.c b/src/nat/gnunet-nat-server.c
index f2508a94a..f8951d4d2 100644
--- a/src/nat/gnunet-nat-server.c
+++ b/src/nat/gnunet-nat-server.c
@@ -39,6 +39,7 @@ static struct GNUNET_SERVER_Handle *server;
39 */ 39 */
40static const struct GNUNET_CONFIGURATION_Handle *cfg; 40static const struct GNUNET_CONFIGURATION_Handle *cfg;
41 41
42
42/** 43/**
43 * Try contacting the peer using autonomous 44 * Try contacting the peer using autonomous
44 * NAT traveral method. 45 * NAT traveral method.
@@ -55,12 +56,17 @@ try_anat (uint32_t dst_ipv4,
55 struct GNUNET_NAT_Handle *h; 56 struct GNUNET_NAT_Handle *h;
56 struct sockaddr_in sa; 57 struct sockaddr_in sa;
57 58
59 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
60 "Asking for connection reversal with %x and code %u\n",
61 (unsigned int) dst_ipv4,
62 (unsigned int) dport);
58 h = GNUNET_NAT_register (cfg, 63 h = GNUNET_NAT_register (cfg,
59 is_tcp, 64 is_tcp,
60 dport, 65 dport,
61 0, NULL, NULL, 66 0, NULL, NULL,
62 NULL, NULL, NULL); 67 NULL, NULL, NULL);
63 memset (&sa, 0, sizeof (sa)); 68 memset (&sa, 0, sizeof (sa));
69 sa.sin_family = AF_INET;
64#if HAVE_SOCKADDR_IN_SIN_LEN 70#if HAVE_SOCKADDR_IN_SIN_LEN
65 sa.sin_len = sizeof (sa); 71 sa.sin_len = sizeof (sa);
66#endif 72#endif
@@ -105,7 +111,7 @@ tcp_send (void *cls,
105 ctx->s)) ) 111 ctx->s)) )
106 { 112 {
107 if (-1 == GNUNET_NETWORK_socket_send (ctx->s, &ctx->data, sizeof (ctx->data))) 113 if (-1 == GNUNET_NETWORK_socket_send (ctx->s, &ctx->data, sizeof (ctx->data)))
108 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "send"); 114 GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG, "send");
109 GNUNET_NETWORK_socket_shutdown (ctx->s, SHUT_RDWR); 115 GNUNET_NETWORK_socket_shutdown (ctx->s, SHUT_RDWR);
110 } 116 }
111 GNUNET_NETWORK_socket_close (ctx->s); 117 GNUNET_NETWORK_socket_close (ctx->s);
@@ -130,18 +136,22 @@ try_send_tcp (uint32_t dst_ipv4,
130 struct sockaddr_in sa; 136 struct sockaddr_in sa;
131 struct TcpContext *ctx; 137 struct TcpContext *ctx;
132 138
133 s = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0); 139 s = GNUNET_NETWORK_socket_create (AF_INET, SOCK_STREAM, 0);
134 if (NULL == s) 140 if (NULL == s)
135 { 141 {
136 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "socket"); 142 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "socket");
137 return; 143 return;
138 } 144 }
139 memset (&sa, 0, sizeof (sa)); 145 memset (&sa, 0, sizeof (sa));
146 sa.sin_family = AF_INET;
140#if HAVE_SOCKADDR_IN_SIN_LEN 147#if HAVE_SOCKADDR_IN_SIN_LEN
141 sa.sin_len = sizeof (sa); 148 sa.sin_len = sizeof (sa);
142#endif 149#endif
143 sa.sin_addr.s_addr = dst_ipv4; 150 sa.sin_addr.s_addr = dst_ipv4;
144 sa.sin_port = htons (dport); 151 sa.sin_port = htons (dport);
152 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
153 "Sending TCP message to `%s'\n",
154 GNUNET_a2s ((struct sockaddr*) &sa, sizeof (sa)));
145 if ( (GNUNET_OK != 155 if ( (GNUNET_OK !=
146 GNUNET_NETWORK_socket_connect (s, 156 GNUNET_NETWORK_socket_connect (s,
147 (const struct sockaddr*) &sa, sizeof (sa))) && 157 (const struct sockaddr*) &sa, sizeof (sa))) &&
@@ -176,19 +186,25 @@ try_send_udp (uint32_t dst_ipv4,
176 struct GNUNET_NETWORK_Handle *s; 186 struct GNUNET_NETWORK_Handle *s;
177 struct sockaddr_in sa; 187 struct sockaddr_in sa;
178 188
179 s = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_DGRAM, 0); 189 s = GNUNET_NETWORK_socket_create (AF_INET, SOCK_DGRAM, 0);
180 if (NULL == s) 190 if (NULL == s)
181 { 191 {
182 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "socket"); 192 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "socket");
183 return; 193 return;
184 } 194 }
185 memset (&sa, 0, sizeof (sa)); 195 memset (&sa, 0, sizeof (sa));
196 sa.sin_family = AF_INET;
186#if HAVE_SOCKADDR_IN_SIN_LEN 197#if HAVE_SOCKADDR_IN_SIN_LEN
187 sa.sin_len = sizeof (sa); 198 sa.sin_len = sizeof (sa);
188#endif 199#endif
189 sa.sin_addr.s_addr = dst_ipv4; 200 sa.sin_addr.s_addr = dst_ipv4;
190 sa.sin_port = htons (dport); 201 sa.sin_port = htons (dport);
191 if (-1 == GNUNET_NETWORK_socket_sendto (s, &data, sizeof(data), (const struct sockaddr*) &sa, sizeof (sa))) 202 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
203 "Sending UDP packet to `%s'\n",
204 GNUNET_a2s ((struct sockaddr*) &sa, sizeof (sa)));
205 if (-1 == GNUNET_NETWORK_socket_sendto (s,
206 &data, sizeof(data),
207 (const struct sockaddr*) &sa, sizeof (sa)))
192 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "sendto"); 208 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "sendto");
193 GNUNET_NETWORK_socket_close (s); 209 GNUNET_NETWORK_socket_close (s);
194} 210}
@@ -210,6 +226,8 @@ test (void *cls,
210 const struct GNUNET_NAT_TestMessage *tm; 226 const struct GNUNET_NAT_TestMessage *tm;
211 uint16_t dport; 227 uint16_t dport;
212 228
229 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
230 "Received test request\n");
213 tm = (const struct GNUNET_NAT_TestMessage*) msg; 231 tm = (const struct GNUNET_NAT_TestMessage*) msg;
214 dport = ntohs (tm->dport); 232 dport = ntohs (tm->dport);
215 if (0 == dport) 233 if (0 == dport)
@@ -279,15 +297,18 @@ run (void *cls,
279 if ( (args[0] == NULL) || 297 if ( (args[0] == NULL) ||
280 (1 != SSCANF (args[0], "%u", &port)) || 298 (1 != SSCANF (args[0], "%u", &port)) ||
281 (0 == port) || 299 (0 == port) ||
282 (65536 >= port) ) 300 (65536 <= port) )
283 { 301 {
284 fprintf (stderr, 302 fprintf (stderr,
285 _("Please pass valid port number as the first argument!\n")); 303 _("Please pass valid port number as the first argument! (got `%s')\n"),
304 args[0]);
286 return; 305 return;
287 } 306 }
288 memset (&in4, 0, sizeof (in4)); 307 memset (&in4, 0, sizeof (in4));
289 memset (&in6, 0, sizeof (in6)); 308 memset (&in6, 0, sizeof (in6));
309 in4.sin_family = AF_INET;
290 in4.sin_port = htons ((uint16_t) port); 310 in4.sin_port = htons ((uint16_t) port);
311 in6.sin6_family = AF_INET6;
291 in6.sin6_port = htons ((uint16_t) port); 312 in6.sin6_port = htons ((uint16_t) port);
292#if HAVE_SOCKADDR_IN_SIN_LEN 313#if HAVE_SOCKADDR_IN_SIN_LEN
293 in4.sin_len = sizeof (in); 314 in4.sin_len = sizeof (in);