aboutsummaryrefslogtreecommitdiff
path: root/src/tun
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-01-17 19:30:12 +0000
committerChristian Grothoff <christian@grothoff.org>2012-01-17 19:30:12 +0000
commite0d8c3f1c05ab0cb218d7182c723298f7e981b58 (patch)
treeb33c36503906c1ea96f11896db1d95603468e9a4 /src/tun
parent72c3f26dc08bd15e7142b002116950fe79baa5a1 (diff)
downloadgnunet-e0d8c3f1c05ab0cb218d7182c723298f7e981b58.tar.gz
gnunet-e0d8c3f1c05ab0cb218d7182c723298f7e981b58.zip
-move IPv6 header initialization to tun library
Diffstat (limited to 'src/tun')
-rw-r--r--src/tun/tun.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/tun/tun.c b/src/tun/tun.c
index 97b7a730e..005c7013d 100644
--- a/src/tun/tun.c
+++ b/src/tun/tun.c
@@ -48,6 +48,7 @@ GNUNET_TUN_initialize_ipv4_header (struct GNUNET_TUN_IPv4Header *ip,
48 const struct in_addr *src, 48 const struct in_addr *src,
49 const struct in_addr *dst) 49 const struct in_addr *dst)
50{ 50{
51 GNUNET_assert (payload_length <= UINT16_MAX - sizeof (struct GNUNET_TUN_IPv4Header));
51 ip->header_length = sizeof (struct GNUNET_TUN_IPv4Header) / 4; 52 ip->header_length = sizeof (struct GNUNET_TUN_IPv4Header) / 4;
52 ip->version = 4; 53 ip->version = 4;
53 ip->diff_serv = 0; 54 ip->diff_serv = 0;
@@ -65,5 +66,34 @@ GNUNET_TUN_initialize_ipv4_header (struct GNUNET_TUN_IPv4Header *ip,
65} 66}
66 67
67 68
69/**
70 * Initialize an IPv6 header.
71 *
72 * @param ip header to initialize
73 * @param protocol protocol to use (i.e. IPPROTO_UDP), technically "next_header" for IPv6
74 * @param payload_length number of bytes of payload that follow (excluding IPv4 header)
75 * @param src source IP address to use
76 * @param dst destination IP address to use
77 */
78void
79GNUNET_TUN_initialize_ipv6_header (struct GNUNET_TUN_IPv6Header *ip,
80 uint8_t protocol,
81 uint16_t payload_length,
82 const struct in6_addr *src,
83 const struct in6_addr *dst)
84{
85 GNUNET_assert (payload_length <= UINT16_MAX - sizeof (struct GNUNET_TUN_IPv6Header));
86 ip->traffic_class_h = 0;
87 ip->version = 6;
88 ip->traffic_class_l = 0;
89 ip->flow_label = 0;
90 ip->next_header = protocol;
91 ip->payload_length = htons ((uint16_t) (payload_length + sizeof (struct GNUNET_TUN_IPv6Header)));
92 ip->hop_limit = FRESH_TTL;
93 ip->destination_address = *dst;
94 ip->source_address = *src;
95}
96
97
68 98
69/* end of tun.c */ 99/* end of tun.c */