#ifndef _IPV6_HELPERS_H #define _IPV6_HELPERS_H #ifdef __cpluscplus extern "C" { #endif #include #include /* * IPv6 Header Format * * 0 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * |Version| Traffic Class | Flow Label | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Payload Length | Next Header | Hop Limit | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | | * + + * | | * + Source Address + * | | * + + * | | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | | * + + * | | * + Destination Address + * | | * + + * | | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ static inline uint8_t ipv6_hdr_get_version(const struct ip6_hdr *hdr) { return (ntohl(hdr->ip6_flow) & 0xf0000000) >> 28; } static inline uint8_t ipv6_hdr_get_traffic_class(const struct ip6_hdr *hdr) { return (ntohl(hdr->ip6_flow) & 0x0ff00000) >> 20; } static inline uint32_t ipv6_hdr_get_flow_label(const struct ip6_hdr *hdr) { return ntohl(hdr->ip6_flow) & 0x000fffff; } static inline uint16_t ipv6_hdr_get_payload_len(const struct ip6_hdr *hdr) { return ntohs(hdr->ip6_plen); } static inline uint8_t ipv6_hdr_get_next_header(const struct ip6_hdr *hdr) { return hdr->ip6_nxt; } static inline uint8_t ipv6_hdr_get_hop_limit(const struct ip6_hdr *hdr) { return hdr->ip6_hlim; } static inline struct in6_addr ipv6_hdr_get_net_order_saddr(const struct ip6_hdr *hdr) { return hdr->ip6_src; } static inline struct in6_addr ipv6_hdr_get_net_order_daddr(const struct ip6_hdr *hdr) { return hdr->ip6_dst; } // TODO IPv6 extension headers #ifdef __cpluscplus } #endif #endif