aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-03-11 22:46:21 +0000
committerChristian Grothoff <christian@grothoff.org>2012-03-11 22:46:21 +0000
commit5a60ea398453342651cae558c37bbe2d0ef2ab36 (patch)
tree5878b5109963e012a088cf15de8bdeacd9eeae87 /src
parent0746baa7c3e4924ac6a687d0d1fff3b33138eca0 (diff)
downloadgnunet-5a60ea398453342651cae558c37bbe2d0ef2ab36.tar.gz
gnunet-5a60ea398453342651cae558c37bbe2d0ef2ab36.zip
-LRN: Add UDP StA function
Diffstat (limited to 'src')
-rw-r--r--src/transport/plugin_transport_udp.c51
1 files changed, 49 insertions, 2 deletions
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c
index ed6fc847a..662ecffa1 100644
--- a/src/transport/plugin_transport_udp.c
+++ b/src/transport/plugin_transport_udp.c
@@ -364,6 +364,53 @@ udp_address_to_string (void *cls, const void *addr, size_t addrlen)
364 364
365 365
366/** 366/**
367 * Function called to convert a string address to
368 * a binary address.
369 *
370 * @param cls closure ('struct Plugin*')
371 * @param addr string address
372 * @param addrlen length of the address
373 * @param buf location to store the buffer
374 * @param added location to store the number of bytes in the buffer.
375 * If the function returns GNUNET_SYSERR, its contents are undefined.
376 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
377 */
378int
379udp_string_to_address (void *cls, const char *addr, uint16_t addrlen,
380 void **buf, size_t *added)
381{
382 struct sockaddr_storage socket_address;
383 int ret = GNUNET_STRINGS_to_address_ip (addr, addrlen,
384 &socket_address);
385
386 if (ret != GNUNET_OK)
387 return GNUNET_SYSERR;
388
389 if (socket_address.ss_family == AF_INET)
390 {
391 struct IPv4UdpAddress *u4;
392 struct sockaddr_in *in4 = (struct sockaddr_in *) &socket_address;
393 u4 = GNUNET_malloc (sizeof (struct IPv4UdpAddress));
394 u4->ipv4_addr = in4->sin_addr.s_addr;
395 u4->u4_port = in4->sin_port;
396 *buf = u4;
397 *added = sizeof (struct IPv4UdpAddress);
398 }
399 else if (socket_address.ss_family == AF_INET6)
400 {
401 struct IPv6UdpAddress *u6;
402 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) &socket_address;
403 u6 = GNUNET_malloc (sizeof (struct IPv6UdpAddress));
404 u6->ipv6_addr = in6->sin6_addr;
405 u6->u6_port = in6->sin6_port;
406 *buf = u6;
407 *added = sizeof (struct IPv6UdpAddress);
408 }
409 return GNUNET_SYSERR;
410}
411
412
413/**
367 * Append our port and forward the result. 414 * Append our port and forward the result.
368 * 415 *
369 * @param cls a 'struct PrettyPrinterContext' 416 * @param cls a 'struct PrettyPrinterContext'
@@ -2061,7 +2108,7 @@ libgnunet_plugin_transport_udp_init (void *cls)
2061 api->cls = NULL; 2108 api->cls = NULL;
2062 api->address_pretty_printer = &udp_plugin_address_pretty_printer; 2109 api->address_pretty_printer = &udp_plugin_address_pretty_printer;
2063 api->address_to_string = &udp_address_to_string; 2110 api->address_to_string = &udp_address_to_string;
2064 api->string_to_address = NULL; // FIXME! 2111 api->string_to_address = &udp_string_to_address;
2065 return api; 2112 return api;
2066 } 2113 }
2067 2114
@@ -2170,7 +2217,7 @@ libgnunet_plugin_transport_udp_init (void *cls)
2170 api->disconnect = &udp_disconnect; 2217 api->disconnect = &udp_disconnect;
2171 api->address_pretty_printer = &udp_plugin_address_pretty_printer; 2218 api->address_pretty_printer = &udp_plugin_address_pretty_printer;
2172 api->address_to_string = &udp_address_to_string; 2219 api->address_to_string = &udp_address_to_string;
2173 api->string_to_address = NULL; // FIXME! 2220 api->string_to_address = &udp_string_to_address;
2174 api->check_address = &udp_plugin_check_address; 2221 api->check_address = &udp_plugin_check_address;
2175 api->get_session = &udp_plugin_get_session; 2222 api->get_session = &udp_plugin_get_session;
2176 api->send = &udp_plugin_send; 2223 api->send = &udp_plugin_send;