aboutsummaryrefslogtreecommitdiff
path: root/src/transport/plugin_transport_udp.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2011-07-13 16:23:41 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2011-07-13 16:23:41 +0000
commit1d9420ad0782bd03f19800ba34f50437707375a0 (patch)
tree909b8d2463e94169390cb3a2051a9fba827efcb4 /src/transport/plugin_transport_udp.c
parentcccf27bb8eed3e178e146f9aa7582d82f3673e2c (diff)
downloadgnunet-1d9420ad0782bd03f19800ba34f50437707375a0.tar.gz
gnunet-1d9420ad0782bd03f19800ba34f50437707375a0.zip
printer: print ip if dns timeout occurs
Diffstat (limited to 'src/transport/plugin_transport_udp.c')
-rw-r--r--src/transport/plugin_transport_udp.c140
1 files changed, 84 insertions, 56 deletions
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c
index e5e741df3..b3a64b286 100644
--- a/src/transport/plugin_transport_udp.c
+++ b/src/transport/plugin_transport_udp.c
@@ -129,11 +129,33 @@ struct Plugin;
129 129
130struct PrettyPrinterContext 130struct PrettyPrinterContext
131{ 131{
132 /**
133 * Function to call with the result.
134 */
132 GNUNET_TRANSPORT_AddressStringCallback asc; 135 GNUNET_TRANSPORT_AddressStringCallback asc;
136
137 /**
138 * Clsoure for 'asc'.
139 */
133 void *asc_cls; 140 void *asc_cls;
141
142 /**
143 * The address
144 */
145 void * addr;
146
147 /**
148 * address length
149 */
150 size_t addr_len;
151
152 /**
153 * Port to add after the IP address.
154 */
134 uint16_t port; 155 uint16_t port;
135}; 156};
136 157
158
137struct MessageQueue 159struct MessageQueue
138{ 160{
139 /** 161 /**
@@ -1256,6 +1278,61 @@ udp_plugin_check_address (void *cls,
1256 1278
1257 1279
1258/** 1280/**
1281 * Function called for a quick conversion of the binary address to
1282 * a numeric address. Note that the caller must not free the
1283 * address and that the next call to this function is allowed
1284 * to override the address again.
1285 *
1286 * @param cls closure
1287 * @param addr binary address
1288 * @param addrlen length of the address
1289 * @return string representing the same address
1290 */
1291static const char*
1292udp_address_to_string (void *cls,
1293 const void *addr,
1294 size_t addrlen)
1295{
1296 static char rbuf[INET6_ADDRSTRLEN + 10];
1297 char buf[INET6_ADDRSTRLEN];
1298 const void *sb;
1299 struct in_addr a4;
1300 struct in6_addr a6;
1301 const struct IPv4UdpAddress *t4;
1302 const struct IPv6UdpAddress *t6;
1303 int af;
1304 uint16_t port;
1305
1306 if (addrlen == sizeof (struct IPv6UdpAddress))
1307 {
1308 t6 = addr;
1309 af = AF_INET6;
1310 port = ntohs (t6->u6_port);
1311 memcpy (&a6, &t6->ipv6_addr, sizeof (a6));
1312 sb = &a6;
1313 }
1314 else if (addrlen == sizeof (struct IPv4UdpAddress))
1315 {
1316 t4 = addr;
1317 af = AF_INET;
1318 port = ntohs (t4->u4_port);
1319 memcpy (&a4, &t4->ipv4_addr, sizeof (a4));
1320 sb = &a4;
1321 }
1322 else
1323 return NULL;
1324 inet_ntop (af, sb, buf, INET6_ADDRSTRLEN);
1325 GNUNET_snprintf (rbuf,
1326 sizeof (rbuf),
1327 "%s:%u",
1328 buf,
1329 port);
1330 return rbuf;
1331}
1332
1333
1334
1335/**
1259 * Append our port and forward the result. 1336 * Append our port and forward the result.
1260 */ 1337 */
1261static void 1338static void
@@ -1266,7 +1343,9 @@ append_port (void *cls, const char *hostname)
1266 1343
1267 if (hostname == NULL) 1344 if (hostname == NULL)
1268 { 1345 {
1269 ppc->asc (ppc->asc_cls, NULL); 1346 ret = strdup(udp_address_to_string(NULL, ppc->addr, ppc->addr_len));
1347 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error in name resolution: `%s'\n",ret);
1348 ppc->asc (ppc->asc_cls, ret);
1270 GNUNET_free (ppc); 1349 GNUNET_free (ppc);
1271 return; 1350 return;
1272 } 1351 }
@@ -1340,10 +1419,13 @@ udp_plugin_address_pretty_printer (void *cls,
1340 asc (asc_cls, NULL); 1419 asc (asc_cls, NULL);
1341 return; 1420 return;
1342 } 1421 }
1343 ppc = GNUNET_malloc (sizeof (struct PrettyPrinterContext)); 1422 ppc = GNUNET_malloc (sizeof (struct PrettyPrinterContext) + addrlen);
1344 ppc->asc = asc; 1423 ppc->asc = asc;
1345 ppc->asc_cls = asc_cls; 1424 ppc->asc_cls = asc_cls;
1346 ppc->port = port; 1425 ppc->port = port;
1426 ppc->addr = &ppc[1];
1427 ppc->addr_len = addrlen;
1428 memcpy(ppc->addr, addr, addrlen);
1347 GNUNET_RESOLVER_hostname_get (sb, 1429 GNUNET_RESOLVER_hostname_get (sb,
1348 sbs, 1430 sbs,
1349 !numeric, timeout, &append_port, ppc); 1431 !numeric, timeout, &append_port, ppc);
@@ -1351,60 +1433,6 @@ udp_plugin_address_pretty_printer (void *cls,
1351 1433
1352 1434
1353/** 1435/**
1354 * Function called for a quick conversion of the binary address to
1355 * a numeric address. Note that the caller must not free the
1356 * address and that the next call to this function is allowed
1357 * to override the address again.
1358 *
1359 * @param cls closure
1360 * @param addr binary address
1361 * @param addrlen length of the address
1362 * @return string representing the same address
1363 */
1364static const char*
1365udp_address_to_string (void *cls,
1366 const void *addr,
1367 size_t addrlen)
1368{
1369 static char rbuf[INET6_ADDRSTRLEN + 10];
1370 char buf[INET6_ADDRSTRLEN];
1371 const void *sb;
1372 struct in_addr a4;
1373 struct in6_addr a6;
1374 const struct IPv4UdpAddress *t4;
1375 const struct IPv6UdpAddress *t6;
1376 int af;
1377 uint16_t port;
1378
1379 if (addrlen == sizeof (struct IPv6UdpAddress))
1380 {
1381 t6 = addr;
1382 af = AF_INET6;
1383 port = ntohs (t6->u6_port);
1384 memcpy (&a6, &t6->ipv6_addr, sizeof (a6));
1385 sb = &a6;
1386 }
1387 else if (addrlen == sizeof (struct IPv4UdpAddress))
1388 {
1389 t4 = addr;
1390 af = AF_INET;
1391 port = ntohs (t4->u4_port);
1392 memcpy (&a4, &t4->ipv4_addr, sizeof (a4));
1393 sb = &a4;
1394 }
1395 else
1396 return NULL;
1397 inet_ntop (af, sb, buf, INET6_ADDRSTRLEN);
1398 GNUNET_snprintf (rbuf,
1399 sizeof (rbuf),
1400 "%s:%u",
1401 buf,
1402 port);
1403 return rbuf;
1404}
1405
1406
1407/**
1408 * Our external IP address/port mapping has changed. 1436 * Our external IP address/port mapping has changed.
1409 * 1437 *
1410 * @param cls closure, the 'struct LocalAddrList' 1438 * @param cls closure, the 'struct LocalAddrList'