aboutsummaryrefslogtreecommitdiff
path: root/src/transport/plugin_transport_tcp.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/plugin_transport_tcp.c')
-rw-r--r--src/transport/plugin_transport_tcp.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c
index 330b24f61..453a0095f 100644
--- a/src/transport/plugin_transport_tcp.c
+++ b/src/transport/plugin_transport_tcp.c
@@ -2734,6 +2734,66 @@ tcp_plugin_get_network (void *cls,
2734 2734
2735 2735
2736/** 2736/**
2737 * Function obtain the network type for an address.
2738 *
2739 * @param cls closure (`struct Plugin *`)
2740 * @param address the address
2741 * @return the network type
2742 */
2743static enum GNUNET_ATS_Network_Type
2744tcp_plugin_get_network_for_address (void *cls,
2745 const struct GNUNET_HELLO_Address *address)
2746{
2747 struct Plugin *plugin = cls;
2748 size_t addrlen;
2749 struct sockaddr_in a4;
2750 struct sockaddr_in6 a6;
2751 const struct IPv4TcpAddress *t4;
2752 const struct IPv6TcpAddress *t6;
2753 const void *sb;
2754 size_t sbs;
2755
2756 addrlen = address->address_length;
2757 if (addrlen == sizeof(struct IPv6TcpAddress))
2758 {
2759 GNUNET_assert (NULL != address->address); /* make static analysis happy */
2760 t6 = address->address;
2761 memset (&a6, 0, sizeof(a6));
2762#if HAVE_SOCKADDR_IN_SIN_LEN
2763 a6.sin6_len = sizeof (a6);
2764#endif
2765 a6.sin6_family = AF_INET6;
2766 a6.sin6_port = t6->t6_port;
2767 memcpy (&a6.sin6_addr, &t6->ipv6_addr, sizeof(struct in6_addr));
2768 sb = &a6;
2769 sbs = sizeof(a6);
2770 }
2771 else if (addrlen == sizeof(struct IPv4TcpAddress))
2772 {
2773 GNUNET_assert (NULL != address->address); /* make static analysis happy */
2774 t4 = address->address;
2775 memset (&a4, 0, sizeof(a4));
2776#if HAVE_SOCKADDR_IN_SIN_LEN
2777 a4.sin_len = sizeof (a4);
2778#endif
2779 a4.sin_family = AF_INET;
2780 a4.sin_port = t4->t4_port;
2781 a4.sin_addr.s_addr = t4->ipv4_addr;
2782 sb = &a4;
2783 sbs = sizeof(a4);
2784 }
2785 else
2786 {
2787 GNUNET_break (0);
2788 return GNUNET_ATS_NET_UNSPECIFIED;
2789 }
2790 return plugin->env->get_address_type (plugin->env->cls,
2791 sb,
2792 sbs);
2793}
2794
2795
2796/**
2737 * Return information about the given session to the 2797 * Return information about the given session to the
2738 * monitor callback. 2798 * monitor callback.
2739 * 2799 *
@@ -2991,6 +3051,7 @@ libgnunet_plugin_transport_tcp_init (void *cls)
2991 api->address_to_string = &tcp_plugin_address_to_string; 3051 api->address_to_string = &tcp_plugin_address_to_string;
2992 api->string_to_address = &tcp_plugin_string_to_address; 3052 api->string_to_address = &tcp_plugin_string_to_address;
2993 api->get_network = &tcp_plugin_get_network; 3053 api->get_network = &tcp_plugin_get_network;
3054 api->get_network_for_address = &tcp_plugin_get_network_for_address;
2994 api->update_session_timeout = &tcp_plugin_update_session_timeout; 3055 api->update_session_timeout = &tcp_plugin_update_session_timeout;
2995 api->update_inbound_delay = &tcp_plugin_update_inbound_delay; 3056 api->update_inbound_delay = &tcp_plugin_update_inbound_delay;
2996 api->setup_monitor = &tcp_plugin_setup_monitor; 3057 api->setup_monitor = &tcp_plugin_setup_monitor;