aboutsummaryrefslogtreecommitdiff
path: root/src/transport/plugin_transport_udp.c
diff options
context:
space:
mode:
authorNathan S. Evans <evans@in.tum.de>2010-06-25 16:41:59 +0000
committerNathan S. Evans <evans@in.tum.de>2010-06-25 16:41:59 +0000
commit018719e628f3b8951d92d8dfb1a1771474fe8dc7 (patch)
treec79af1ae7cf6c9861ad3b2c72a1f0da33476b1a9 /src/transport/plugin_transport_udp.c
parent94f01bdd2fda575769f01f8072689fa6936af8f4 (diff)
downloadgnunet-018719e628f3b8951d92d8dfb1a1771474fe8dc7.tar.gz
gnunet-018719e628f3b8951d92d8dfb1a1771474fe8dc7.zip
fixing christians overwritten changes
Diffstat (limited to 'src/transport/plugin_transport_udp.c')
-rw-r--r--src/transport/plugin_transport_udp.c288
1 files changed, 236 insertions, 52 deletions
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c
index 71f1dd190..ee06d02de 100644
--- a/src/transport/plugin_transport_udp.c
+++ b/src/transport/plugin_transport_udp.c
@@ -90,6 +90,38 @@ struct UDPMessage
90 90
91}; 91};
92 92
93/**
94 * Network format for IPv4 addresses.
95 */
96struct IPv4UdpAddress
97{
98 /**
99 * IPv4 address, in network byte order.
100 */
101 uint32_t ipv4_addr;
102
103 /**
104 * Port number, in network byte order.
105 */
106 uint16_t u_port;
107};
108
109
110/**
111 * Network format for IPv6 addresses.
112 */
113struct IPv6UdpAddress
114{
115 /**
116 * IPv6 address.
117 */
118 unsigned char ipv6_addr[16];
119
120 /**
121 * Port number, in network byte order.
122 */
123 uint16_t u6_port;
124};
93 125
94/* Forward definition */ 126/* Forward definition */
95struct Plugin; 127struct Plugin;
@@ -512,12 +544,18 @@ udp_real_send (void *cls,
512 struct UDPMessage *message; 544 struct UDPMessage *message;
513 int ssize; 545 int ssize;
514 ssize_t sent; 546 ssize_t sent;
547 struct sockaddr_in a4;
548 struct sockaddr_in6 a6;
549 const struct IPv4UdpAddress *t4;
550 const struct IPv6UdpAddress *t6;
551 const void *sb;
552 size_t sbs;
515 553
516 if ((addr == NULL) || (addrlen == 0)) 554 if ((addr == NULL) || (addrlen == 0))
517 { 555 {
518#if DEBUG_UDP_NAT 556#if DEBUG_UDP_NAT
519 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _ 557 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _
520 ("udp_plugin_send called without address, returning!\n")); 558 ("udp_real_send called without address, returning!\n"));
521#endif 559#endif
522 if (cont != NULL) 560 if (cont != NULL)
523 cont (cont_cls, target, GNUNET_SYSERR); 561 cont (cont_cls, target, GNUNET_SYSERR);
@@ -534,11 +572,45 @@ udp_real_send (void *cls,
534 sizeof (struct GNUNET_PeerIdentity)); 572 sizeof (struct GNUNET_PeerIdentity));
535 memcpy (&message[1], msgbuf, msgbuf_size); 573 memcpy (&message[1], msgbuf, msgbuf_size);
536 574
575 if (addrlen == sizeof (struct IPv6UdpAddress))
576 {
577 t6 = addr;
578 memset (&a6, 0, sizeof (a6));
579#if HAVE_SOCKADDR_IN_SIN_LEN
580 a6.sin6_len = sizeof (a6);
581#endif
582 a6.sin6_family = AF_INET6;
583 a6.sin6_port = t6->u6_port;
584 memcpy (&a6.sin6_addr,
585 &t6->ipv6_addr,
586 sizeof (struct in6_addr));
587 sb = &a6;
588 sbs = sizeof (a6);
589 }
590 else if (addrlen == sizeof (struct IPv4UdpAddress))
591 {
592 t4 = addr;
593 memset (&a4, 0, sizeof (a4));
594#if HAVE_SOCKADDR_IN_SIN_LEN
595 a4.sin_len = sizeof (a4);
596#endif
597 a4.sin_family = AF_INET;
598 a4.sin_port = t4->u_port;
599 a4.sin_addr.s_addr = t4->ipv4_addr;
600 sb = &a4;
601 sbs = sizeof (a4);
602 }
603 else
604 {
605 GNUNET_break_op (0);
606 return -1;
607 }
608
537 /* Actually send the message */ 609 /* Actually send the message */
538 sent = 610 sent =
539 GNUNET_NETWORK_socket_sendto (send_handle, message, ssize, 611 GNUNET_NETWORK_socket_sendto (send_handle, message, ssize,
540 addr, 612 sb,
541 addrlen); 613 sbs);
542 614
543 if (cont != NULL) 615 if (cont != NULL)
544 { 616 {
@@ -646,14 +718,25 @@ udp_plugin_send (void *cls,
646 ssize_t sent; 718 ssize_t sent;
647 struct MessageQueue *temp_message; 719 struct MessageQueue *temp_message;
648 struct PeerSession *peer_session; 720 struct PeerSession *peer_session;
649 struct sockaddr_in *sockaddr = (struct sockaddr_in *)addr;
650 int other_peer_natd; 721 int other_peer_natd;
722 const struct IPv4UdpAddress *t4;
651 723
652 GNUNET_assert (NULL == session); 724 GNUNET_assert (NULL == session);
653 other_peer_natd = GNUNET_NO; 725 other_peer_natd = GNUNET_NO;
654 if ((sockaddr->sin_family == AF_INET) && (ntohs(sockaddr->sin_port) == 0)) 726
727 if (addrlen == sizeof(struct IPv4UdpAddress))
655 { 728 {
656 other_peer_natd = GNUNET_YES; 729 t4 = addr;
730 if (ntohs(t4->u_port) == 0)
731 other_peer_natd = GNUNET_YES;
732 }
733 else if (addrlen == sizeof(struct IPv6UdpAddress))
734 {
735
736 }
737 else
738 {
739 GNUNET_break_op(0);
657 } 740 }
658 741
659 sent = 0; 742 sent = 0;
@@ -742,72 +825,87 @@ process_interfaces (void *cls,
742{ 825{
743 struct Plugin *plugin = cls; 826 struct Plugin *plugin = cls;
744 int af; 827 int af;
745 struct sockaddr_in *v4; 828 struct IPv4UdpAddress t4;
746 struct sockaddr_in6 *v6; 829 struct IPv6UdpAddress t6;
747 struct sockaddr *addr_nat; 830 void *arg;
831 uint16_t args;
832
833 void *addr_nat;
748 834
749 addr_nat = NULL; 835 addr_nat = NULL;
750 af = addr->sa_family; 836 af = addr->sa_family;
751 if (af == AF_INET) 837 if (af == AF_INET)
752 { 838 {
753 v4 = (struct sockaddr_in *) addr; 839 t4.ipv4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr;
754 if ((plugin->behind_nat == GNUNET_YES) && (plugin->only_nat_addresses == GNUNET_YES)) 840 if ((plugin->behind_nat == GNUNET_YES) && (plugin->only_nat_addresses == GNUNET_YES))
755 { 841 {
756 v4->sin_port = htons (DEFAULT_NAT_PORT); /* Indicates to receiver we are behind NAT */ 842 t4.u_port = htons (DEFAULT_NAT_PORT);
757 } 843 }
758 else if (plugin->behind_nat == GNUNET_YES) /* We are behind NAT, but will advertise NAT and normal addresses */ 844 else if (plugin->behind_nat == GNUNET_YES) /* We are behind NAT, but will advertise NAT and normal addresses */
759 { 845 {
760 addr_nat = GNUNET_malloc(addrlen); 846 addr_nat = GNUNET_malloc(sizeof(t4));
761 memcpy(addr_nat, addr, addrlen); 847 memcpy(addr_nat, &t4, sizeof(t4));
762 v4 = (struct sockaddr_in *) addr_nat; 848 t4.u_port = plugin->port;
763 v4->sin_port = htons(plugin->port); 849 ((struct IPv4UdpAddress *)addr_nat)->u_port = htons(DEFAULT_NAT_PORT);
764 } 850 }
765 else 851 else
766 { 852 {
767 v4->sin_port = htons (plugin->port); 853 t4.u_port = htons(plugin->port);
768 } 854 }
855 arg = &t4;
856 args = sizeof (t4);
769 } 857 }
770 else 858 else if (af == AF_INET6)
771 { 859 {
772 GNUNET_assert (af == AF_INET6); 860
773 v6 = (struct sockaddr_in6 *) addr; 861 if (IN6_IS_ADDR_LINKLOCAL (&((struct sockaddr_in6 *) addr)->sin6_addr))
862 {
863 /* skip link local addresses */
864 return GNUNET_OK;
865 }
866 memcpy (&t6.ipv6_addr,
867 &((struct sockaddr_in6 *) addr)->sin6_addr,
868 sizeof (struct in6_addr));
774 if ((plugin->behind_nat == GNUNET_YES) && (plugin->only_nat_addresses == GNUNET_YES)) 869 if ((plugin->behind_nat == GNUNET_YES) && (plugin->only_nat_addresses == GNUNET_YES))
775 { 870 {
776 v6->sin6_port = htons (0); 871 t6.u6_port = htons (0);
777 } 872 }
778 else if (plugin->behind_nat == GNUNET_YES) /* We are behind NAT, but will advertise NAT and normal addresses */ 873 else if (plugin->behind_nat == GNUNET_YES)
779 { 874 {
780 addr_nat = GNUNET_malloc(addrlen); 875 addr_nat = GNUNET_malloc(sizeof(t6));
781 memcpy(addr_nat, addr, addrlen); 876 memcpy(addr_nat, &t6, sizeof(t6));
782 v6 = (struct sockaddr_in6 *) addr_nat; 877 t6.u6_port = plugin->port;
783 v6->sin6_port = htons(plugin->port); 878 ((struct IPv6UdpAddress *)addr_nat)->u6_port = htons(DEFAULT_NAT_PORT);
784 } 879 }
785 else 880 else
786 { 881 {
787 v6->sin6_port = htons (plugin->port); 882 t6.u6_port = htons (plugin->port);
788 } 883 }
884
885 arg = &t6;
886 args = sizeof (t6);
789 } 887 }
790 888
791 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO | 889 GNUNET_log (GNUNET_ERROR_TYPE_INFO |
792 GNUNET_ERROR_TYPE_BULK, 890 GNUNET_ERROR_TYPE_BULK,
793 "udp", _("Found address `%s' (%s)\n"), 891 _("Found address `%s' (%s)\n"),
794 GNUNET_a2s (addr, addrlen), name); 892 GNUNET_a2s (addr, addrlen), name);
795 893
796 if (addr_nat != NULL) 894 if (addr_nat != NULL)
797 { 895 {
798 plugin->env->notify_address (plugin->env->cls, 896 plugin->env->notify_address (plugin->env->cls,
799 "udp", 897 "udp",
800 addr_nat, addrlen, GNUNET_TIME_UNIT_FOREVER_REL); 898 addr_nat, args, GNUNET_TIME_UNIT_FOREVER_REL);
801 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO | 899 GNUNET_log (GNUNET_ERROR_TYPE_INFO |
802 GNUNET_ERROR_TYPE_BULK, 900 GNUNET_ERROR_TYPE_BULK,
803 "udp", _("Found NAT address `%s' (%s)\n"), 901 _("Found NAT address `%s' (%s)\n"),
804 GNUNET_a2s (addr_nat, addrlen), name); 902 GNUNET_a2s (addr_nat, args), name);
805 GNUNET_free(addr_nat); 903 GNUNET_free(addr_nat);
806 } 904 }
807 905
808 plugin->env->notify_address (plugin->env->cls, 906 plugin->env->notify_address (plugin->env->cls,
809 "udp", 907 "udp",
810 addr, addrlen, GNUNET_TIME_UNIT_FOREVER_REL); 908 arg, args, GNUNET_TIME_UNIT_FOREVER_REL);
811 909
812 return GNUNET_OK; 910 return GNUNET_OK;
813} 911}
@@ -1042,7 +1140,10 @@ udp_plugin_server_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc
1042 * @param sockinfo which socket did we receive the message on 1140 * @param sockinfo which socket did we receive the message on
1043 */ 1141 */
1044static void 1142static void
1045udp_demultiplexer(struct Plugin *plugin, struct GNUNET_PeerIdentity *sender, const struct GNUNET_MessageHeader *currhdr, struct sockaddr_storage *sender_addr, socklen_t fromlen, struct UDP_Sock_Info *sockinfo) 1143udp_demultiplexer(struct Plugin *plugin, struct GNUNET_PeerIdentity *sender,
1144 const struct GNUNET_MessageHeader *currhdr,
1145 const void *sender_addr,
1146 size_t fromlen, struct UDP_Sock_Info *sockinfo)
1046{ 1147{
1047 struct UDP_NAT_ProbeMessageReply *outgoing_probe_reply; 1148 struct UDP_NAT_ProbeMessageReply *outgoing_probe_reply;
1048 struct UDP_NAT_ProbeMessageConfirmation *outgoing_probe_confirmation; 1149 struct UDP_NAT_ProbeMessageConfirmation *outgoing_probe_confirmation;
@@ -1079,7 +1180,7 @@ udp_demultiplexer(struct Plugin *plugin, struct GNUNET_PeerIdentity *sender, con
1079 (char *)outgoing_probe_reply, 1180 (char *)outgoing_probe_reply,
1080 ntohs(outgoing_probe_reply->header.size), 0, 1181 ntohs(outgoing_probe_reply->header.size), 0,
1081 GNUNET_TIME_relative_get_unit(), 1182 GNUNET_TIME_relative_get_unit(),
1082 sender_addr, fromlen, 1183 sender_addr, fromlen,
1083 NULL, NULL); 1184 NULL, NULL);
1084 1185
1085#if DEBUG_UDP_NAT 1186#if DEBUG_UDP_NAT
@@ -1094,7 +1195,7 @@ udp_demultiplexer(struct Plugin *plugin, struct GNUNET_PeerIdentity *sender, con
1094 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "udp", 1195 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "udp",
1095 _("Received PROBE REPLY from port %d on incoming port %d\n"), ntohs(((struct sockaddr_in *)sender_addr)->sin_port), sockinfo->port); 1196 _("Received PROBE REPLY from port %d on incoming port %d\n"), ntohs(((struct sockaddr_in *)sender_addr)->sin_port), sockinfo->port);
1096#endif 1197#endif
1097 if (sender_addr->ss_family == AF_INET) 1198 if (sizeof(sender_addr) == sizeof(struct IPv4UdpAddress))
1098 { 1199 {
1099 memset(&addr_buf, 0, sizeof(addr_buf)); 1200 memset(&addr_buf, 0, sizeof(addr_buf));
1100 if (NULL == inet_ntop (AF_INET, 1201 if (NULL == inet_ntop (AF_INET,
@@ -1212,7 +1313,7 @@ udp_demultiplexer(struct Plugin *plugin, struct GNUNET_PeerIdentity *sender, con
1212 break; 1313 break;
1213 default: 1314 default:
1214 plugin->env->receive (plugin->env->cls, sender, currhdr, UDP_DIRECT_DISTANCE, 1315 plugin->env->receive (plugin->env->cls, sender, currhdr, UDP_DIRECT_DISTANCE,
1215 NULL, (char *)sender_addr, fromlen); 1316 NULL, sender_addr, fromlen);
1216 } 1317 }
1217 1318
1218} 1319}
@@ -1236,13 +1337,19 @@ udp_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1236 struct GNUNET_PeerIdentity *sender; 1337 struct GNUNET_PeerIdentity *sender;
1237 unsigned int buflen; 1338 unsigned int buflen;
1238 socklen_t fromlen; 1339 socklen_t fromlen;
1239 struct sockaddr_storage addr; 1340 struct sockaddr addr;
1240 ssize_t ret; 1341 ssize_t ret;
1241 int offset; 1342 int offset;
1242 int count; 1343 int count;
1243 int tsize; 1344 int tsize;
1244 char *msgbuf; 1345 char *msgbuf;
1245 const struct GNUNET_MessageHeader *currhdr; 1346 const struct GNUNET_MessageHeader *currhdr;
1347 struct IPv4UdpAddress t4;
1348 struct IPv6UdpAddress t6;
1349 const struct sockaddr_in *s4;
1350 const struct sockaddr_in6 *s6;
1351 const void *ca;
1352 size_t calen;
1246 1353
1247 plugin->select_task = GNUNET_SCHEDULER_NO_TASK; 1354 plugin->select_task = GNUNET_SCHEDULER_NO_TASK;
1248 1355
@@ -1259,10 +1366,35 @@ udp_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1259 1366
1260 buf = GNUNET_malloc (buflen); 1367 buf = GNUNET_malloc (buflen);
1261 fromlen = sizeof (addr); 1368 fromlen = sizeof (addr);
1262 memset (&addr, 0, fromlen); 1369 memset (&addr, 0, sizeof(addr));
1263 ret = 1370 ret =
1264 GNUNET_NETWORK_socket_recvfrom (udp_sock.desc, buf, buflen, 1371 GNUNET_NETWORK_socket_recvfrom (udp_sock.desc, buf, buflen,
1265 (struct sockaddr *) &addr, &fromlen); 1372 &addr, &fromlen);
1373
1374 if (fromlen == sizeof (struct sockaddr_in))
1375 {
1376 s4 = (const struct sockaddr_in*) &addr;
1377 t4.u_port = s4->sin_port;
1378 t4.ipv4_addr = s4->sin_addr.s_addr;
1379 ca = &t4;
1380 calen = sizeof (t4);
1381 }
1382 else if (fromlen == sizeof (struct sockaddr_in6))
1383 {
1384 s6 = (const struct sockaddr_in6*) &addr;
1385 t6.u6_port = s6->sin6_port;
1386 memcpy (&t6.ipv6_addr,
1387 &s6->sin6_addr,
1388 sizeof (struct in6_addr));
1389 ca = &t6;
1390 calen = sizeof (t6);
1391 }
1392 else
1393 {
1394 GNUNET_break (0);
1395 ca = NULL;
1396 calen = 0;
1397 }
1266 1398
1267#if DEBUG_UDP_NAT 1399#if DEBUG_UDP_NAT
1268 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _ 1400 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _
@@ -1304,7 +1436,7 @@ udp_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1304 ("processing msg %d: type %d, size %d at offset %d\n"), 1436 ("processing msg %d: type %d, size %d at offset %d\n"),
1305 count, ntohs(currhdr->type), ntohs(currhdr->size), offset); 1437 count, ntohs(currhdr->type), ntohs(currhdr->size), offset);
1306#endif 1438#endif
1307 udp_demultiplexer(plugin, sender, currhdr, &addr, fromlen, &udp_sock); 1439 udp_demultiplexer(plugin, sender, currhdr, ca, calen, &udp_sock);
1308#if DEBUG_UDP_NAT 1440#if DEBUG_UDP_NAT
1309 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _ 1441 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _
1310 ("processing done msg %d: type %d, size %d at offset %d\n"), 1442 ("processing done msg %d: type %d, size %d at offset %d\n"),
@@ -1659,6 +1791,59 @@ check_gnunet_nat_binary(char *binary)
1659} 1791}
1660 1792
1661/** 1793/**
1794 * Function called for a quick conversion of the binary address to
1795 * a numeric address. Note that the caller must not free the
1796 * address and that the next call to this function is allowed
1797 * to override the address again.
1798 *
1799 * @param cls closure
1800 * @param addr binary address
1801 * @param addrlen length of the address
1802 * @return string representing the same address
1803 */
1804static const char*
1805udp_address_to_string (void *cls,
1806 const void *addr,
1807 size_t addrlen)
1808{
1809 static char rbuf[INET6_ADDRSTRLEN + 10];
1810 char buf[INET6_ADDRSTRLEN];
1811 const void *sb;
1812 struct in_addr a4;
1813 struct in6_addr a6;
1814 const struct IPv4UdpAddress *t4;
1815 const struct IPv6UdpAddress *t6;
1816 int af;
1817 uint16_t port;
1818
1819 if (addrlen == sizeof (struct IPv6UdpAddress))
1820 {
1821 t6 = addr;
1822 af = AF_INET6;
1823 port = ntohs (t6->u6_port);
1824 memcpy (&a6, &t6->ipv6_addr, sizeof (a6));
1825 sb = &a6;
1826 }
1827 else if (addrlen == sizeof (struct IPv4UdpAddress))
1828 {
1829 t4 = addr;
1830 af = AF_INET;
1831 port = ntohs (t4->u_port);
1832 memcpy (&a4, &t4->ipv4_addr, sizeof (a4));
1833 sb = &a4;
1834 }
1835 else
1836 return NULL;
1837 inet_ntop (af, sb, buf, INET6_ADDRSTRLEN);
1838 GNUNET_snprintf (rbuf,
1839 sizeof (rbuf),
1840 "%s:%u",
1841 buf,
1842 port);
1843 return rbuf;
1844}
1845
1846/**
1662 * The exported method. Makes the core api available via a global and 1847 * The exported method. Makes the core api available via a global and
1663 * returns the udp transport API. 1848 * returns the udp transport API.
1664 */ 1849 */
@@ -1677,7 +1862,7 @@ libgnunet_plugin_transport_udp_init (void *cls)
1677 int only_nat_addresses; 1862 int only_nat_addresses;
1678 char *internal_address; 1863 char *internal_address;
1679 char *external_address; 1864 char *external_address;
1680 struct sockaddr_in in_addr; 1865 struct IPv4UdpAddress v4_address;
1681 1866
1682 service = GNUNET_SERVICE_start ("transport-udp", env->sched, env->cfg); 1867 service = GNUNET_SERVICE_start ("transport-udp", env->sched, env->cfg);
1683 if (service == NULL) 1868 if (service == NULL)
@@ -1743,7 +1928,7 @@ libgnunet_plugin_transport_udp_init (void *cls)
1743 return NULL; 1928 return NULL;
1744 } 1929 }
1745 1930
1746 if ((external_address != NULL) && (inet_pton(AF_INET, external_address, &in_addr.sin_addr) != 1)) 1931 if ((external_address != NULL) && (inet_pton(AF_INET, external_address, &v4_address.ipv4_addr) != 1))
1747 { 1932 {
1748 GNUNET_log_from(GNUNET_ERROR_TYPE_WARNING, "udp", "Malformed EXTERNAL_ADDRESS %s given in configuration!\n", external_address); 1933 GNUNET_log_from(GNUNET_ERROR_TYPE_WARNING, "udp", "Malformed EXTERNAL_ADDRESS %s given in configuration!\n", external_address);
1749 } 1934 }
@@ -1765,7 +1950,7 @@ libgnunet_plugin_transport_udp_init (void *cls)
1765 return NULL; 1950 return NULL;
1766 } 1951 }
1767 1952
1768 if ((internal_address != NULL) && (inet_pton(AF_INET, internal_address, &in_addr.sin_addr) != 1)) 1953 if ((internal_address != NULL) && (inet_pton(AF_INET, internal_address, &v4_address.ipv4_addr) != 1))
1769 { 1954 {
1770 GNUNET_log_from(GNUNET_ERROR_TYPE_WARNING, "udp", "Malformed INTERNAL_ADDRESS %s given in configuration!\n", internal_address); 1955 GNUNET_log_from(GNUNET_ERROR_TYPE_WARNING, "udp", "Malformed INTERNAL_ADDRESS %s given in configuration!\n", internal_address);
1771 } 1956 }
@@ -1812,6 +1997,7 @@ libgnunet_plugin_transport_udp_init (void *cls)
1812 api->send = &udp_plugin_send; 1997 api->send = &udp_plugin_send;
1813 api->disconnect = &udp_disconnect; 1998 api->disconnect = &udp_disconnect;
1814 api->address_pretty_printer = &udp_plugin_address_pretty_printer; 1999 api->address_pretty_printer = &udp_plugin_address_pretty_printer;
2000 api->address_to_string = &udp_address_to_string;
1815 api->check_address = &udp_check_address; 2001 api->check_address = &udp_check_address;
1816 2002
1817 plugin->service = service; 2003 plugin->service = service;
@@ -1828,21 +2014,19 @@ libgnunet_plugin_transport_udp_init (void *cls)
1828 &process_hostname_ips, 2014 &process_hostname_ips,
1829 plugin); 2015 plugin);
1830 2016
1831 if ((plugin->behind_nat == GNUNET_YES) && (inet_pton(AF_INET, plugin->external_address, &in_addr.sin_addr) == 1)) 2017 if ((plugin->behind_nat == GNUNET_YES) && (inet_pton(AF_INET, plugin->external_address, &v4_address.ipv4_addr) == 1))
1832 { 2018 {
1833 in_addr.sin_port = htons(0); 2019 v4_address.u_port = htons(0);
1834 in_addr.sin_family = AF_INET;
1835 plugin->env->notify_address (plugin->env->cls, 2020 plugin->env->notify_address (plugin->env->cls,
1836 "udp", 2021 "udp",
1837 &in_addr, sizeof(in_addr), GNUNET_TIME_UNIT_FOREVER_REL); 2022 &v4_address, sizeof(v4_address), GNUNET_TIME_UNIT_FOREVER_REL);
1838 } 2023 }
1839 else if ((plugin->external_address != NULL) && (inet_pton(AF_INET, plugin->external_address, &in_addr.sin_addr) == 1)) 2024 else if ((plugin->external_address != NULL) && (inet_pton(AF_INET, plugin->external_address, &v4_address.ipv4_addr) == 1))
1840 { 2025 {
1841 in_addr.sin_port = htons(plugin->port); 2026 v4_address.u_port = htons(plugin->port);
1842 in_addr.sin_family = AF_INET;
1843 plugin->env->notify_address (plugin->env->cls, 2027 plugin->env->notify_address (plugin->env->cls,
1844 "udp", 2028 "udp",
1845 &in_addr, sizeof(in_addr), GNUNET_TIME_UNIT_FOREVER_REL); 2029 &v4_address, sizeof(v4_address), GNUNET_TIME_UNIT_FOREVER_REL);
1846 } 2030 }
1847 2031
1848 sockets_created = udp_transport_server_start (plugin); 2032 sockets_created = udp_transport_server_start (plugin);