X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fipv4.h;h=cd4c372bfd2a61bd811388a434821404cd6d73d3;hb=c32235ac0ef4ce8af77d59c6186436c49c3d7386;hp=940c239c985737669802aca300d80c34f78369af;hpb=ce8775000ab38229a78ecf3dc26bab008ca0f332;p=tinc diff --git a/src/ipv4.h b/src/ipv4.h index 940c239c..cd4c372b 100644 --- a/src/ipv4.h +++ b/src/ipv4.h @@ -1,7 +1,10 @@ +#ifndef TINC_IPV4_H +#define TINC_IPV4_H + /* ipv4.h -- missing IPv4 related definitions Copyright (C) 2005 Ivo Timmermans - 2006 Guus Sliepen + 2006-2012 Guus Sliepen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -18,8 +21,7 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#ifndef __TINC_IPV4_H__ -#define __TINC_IPV4_H__ +#include "system.h" #ifndef AF_INET #define AF_INET 2 @@ -41,6 +43,14 @@ #define ICMP_NET_UNKNOWN 6 #endif +#ifndef ICMP_TIME_EXCEEDED +#define ICMP_TIME_EXCEEDED 11 +#endif + +#ifndef ICMP_EXC_TTL +#define ICMP_EXC_TTL 0 +#endif + #ifndef ICMP_NET_UNREACH #define ICMP_NET_UNREACH 0 #endif @@ -54,34 +64,40 @@ #endif #ifndef HAVE_STRUCT_IP -struct ip { #if __BYTE_ORDER == __LITTLE_ENDIAN - unsigned int ip_hl:4; - unsigned int ip_v:4; +#define IP_NIBBLE1 ip_hl +#define IP_NIBBLE2 ip_v #else - unsigned int ip_v:4; - unsigned int ip_hl:4; +#define IP_NIBBLE1 ip_v +#define IP_NIBBLE2 ip_hl #endif +PACKED(struct ip { + uint8_t IP_NIBBLE1: 4; + uint8_t IP_NIBBLE2: 4; uint8_t ip_tos; uint16_t ip_len; - uint16_t ip_id; + uint16_t ip_id; uint16_t ip_off; -#define IP_RF 0x8000 -#define IP_DF 0x4000 -#define IP_MF 0x2000 uint8_t ip_ttl; uint8_t ip_p; uint16_t ip_sum; struct in_addr ip_src, ip_dst; -} __attribute__ ((__packed__)); +}); +#undef IP_NIBBLE1 +#undef IP_NIBBLE2 +#define IP_RF 0x8000 +#define IP_DF 0x4000 +#define IP_MF 0x2000 #endif +STATIC_ASSERT(sizeof(struct ip) == 20, "ip has incorrect size"); + #ifndef IP_OFFMASK #define IP_OFFMASK 0x1fff #endif #ifndef HAVE_STRUCT_ICMP -struct icmp { +PACKED(struct icmp { uint8_t icmp_type; uint8_t icmp_code; uint16_t icmp_cksum; @@ -106,16 +122,6 @@ struct icmp { uint16_t irt_lifetime; } ih_rtradv; } icmp_hun; -#define icmp_pptr icmp_hun.ih_pptr -#define icmp_gwaddr icmp_hun.ih_gwaddr -#define icmp_id icmp_hun.ih_idseq.icd_id -#define icmp_seq icmp_hun.ih_idseq.icd_seq -#define icmp_void icmp_hun.ih_void -#define icmp_pmvoid icmp_hun.ih_pmtu.ipm_void -#define icmp_nextmtu icmp_hun.ih_pmtu.ipm_nextmtu -#define icmp_num_addrs icmp_hun.ih_rtradv.irt_num_addrs -#define icmp_wpa icmp_hun.ih_rtradv.irt_wpa -#define icmp_lifetime icmp_hun.ih_rtradv.irt_lifetime union { struct { uint32_t its_otime; @@ -128,6 +134,17 @@ struct icmp { uint32_t id_mask; uint8_t id_data[1]; } icmp_dun; +}); +#define icmp_pptr icmp_hun.ih_pptr +#define icmp_gwaddr icmp_hun.ih_gwaddr +#define icmp_id icmp_hun.ih_idseq.icd_id +#define icmp_seq icmp_hun.ih_idseq.icd_seq +#define icmp_void icmp_hun.ih_void +#define icmp_pmvoid icmp_hun.ih_pmtu.ipm_void +#define icmp_nextmtu icmp_hun.ih_pmtu.ipm_nextmtu +#define icmp_num_addrs icmp_hun.ih_rtradv.irt_num_addrs +#define icmp_wpa icmp_hun.ih_rtradv.irt_wpa +#define icmp_lifetime icmp_hun.ih_rtradv.irt_lifetime #define icmp_otime icmp_dun.id_ts.its_otime #define icmp_rtime icmp_dun.id_ts.its_rtime #define icmp_ttime icmp_dun.id_ts.its_ttime @@ -135,7 +152,8 @@ struct icmp { #define icmp_radv icmp_dun.id_radv #define icmp_mask icmp_dun.id_mask #define icmp_data icmp_dun.id_data -} __attribute__ ((__packed__)); #endif -#endif /* __TINC_IPV4_H__ */ +STATIC_ASSERT(sizeof(struct icmp) == 28, "icmp has incorrect size"); + +#endif