#ifndef _IPV4_HELPERS_H #define _IPV4_HELPERS_H #ifdef __cpluscplus extern "C" { #endif #include #include static inline uint16_t ipv4_hdr_get_ipid(const struct ip *hdr) { return ntohs(hdr->ip_id); } static inline uint8_t ipv4_hdr_get_flags(const struct ip *hdr) { return (ntohs(hdr->ip_off) & IP_OFFMASK) >> 13; } static inline uint16_t ipv4_hdr_get_frag_offset(const struct ip *hdr) { return ntohs(hdr->ip_off) & IP_OFFMASK; } static inline uint8_t ipv4_hdr_get_ttl(const struct ip *hdr) { return hdr->ip_ttl; } static inline uint8_t ipv4_hdr_get_protocol(const struct ip *hdr) { return hdr->ip_p; } static inline uint16_t ipv4_hdr_get_checksum(const struct ip *hdr) { return ntohs(hdr->ip_sum); } static inline uint32_t ipv4_hdr_get_src(const struct ip *hdr) { return ntohl(hdr->ip_src.s_addr); } static inline uint32_t ipv4_hdr_get_dst(const struct ip *hdr) { return ntohl(hdr->ip_dst.s_addr); } static inline bool ipv4_hdr_has_flag_rf(const struct ip *hdr) { return (ntohs(hdr->ip_off) & IP_RF) != 0; } static inline bool ipv4_hdr_has_flag_df(const struct ip *hdr) { return (ntohs(hdr->ip_off) & IP_DF) != 0; } static inline bool ipv4_hdr_has_flag_mf(const struct ip *hdr) { return (ntohs(hdr->ip_off) & IP_MF) != 0; } #ifdef __cpluscplus } #endif #endif