mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2024-08-24 23:25:58 +00:00
IPv4: splitted IPv4 header fields version/len and tos, made macros depend on BYTE_ORDER to prevent unnecessary calls to htons()
This commit is contained in:
parent
a745528b40
commit
41c785d77a
@ -705,9 +705,10 @@ err_t ip_output_if_opt(struct pbuf *p, ip_addr_t *src, ip_addr_t *dest,
|
|||||||
chk_sum += ip4_addr_get_u32(&iphdr->dest) >> 16;
|
chk_sum += ip4_addr_get_u32(&iphdr->dest) >> 16;
|
||||||
#endif /* CHECKSUM_GEN_IP_INLINE */
|
#endif /* CHECKSUM_GEN_IP_INLINE */
|
||||||
|
|
||||||
IPH_VHLTOS_SET(iphdr, 4, ip_hlen / 4, tos);
|
IPH_VHL_SET(iphdr, 4, ip_hlen / 4);
|
||||||
|
IPH_TOS_SET(iphdr, tos);
|
||||||
#if CHECKSUM_GEN_IP_INLINE
|
#if CHECKSUM_GEN_IP_INLINE
|
||||||
chk_sum += iphdr->_v_hl_tos;
|
chk_sum += LWIP_MAKE_U16(tos, iphdr->_v_hl);
|
||||||
#endif /* CHECKSUM_GEN_IP_INLINE */
|
#endif /* CHECKSUM_GEN_IP_INLINE */
|
||||||
IPH_LEN_SET(iphdr, htons(p->tot_len));
|
IPH_LEN_SET(iphdr, htons(p->tot_len));
|
||||||
#if CHECKSUM_GEN_IP_INLINE
|
#if CHECKSUM_GEN_IP_INLINE
|
||||||
|
@ -62,8 +62,10 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
PACK_STRUCT_BEGIN
|
PACK_STRUCT_BEGIN
|
||||||
struct ip_hdr {
|
struct ip_hdr {
|
||||||
/* version / header length / type of service */
|
/* version / header length */
|
||||||
PACK_STRUCT_FIELD(u16_t _v_hl_tos);
|
PACK_STRUCT_FIELD(u8_t _v_hl);
|
||||||
|
/* type of service */
|
||||||
|
PACK_STRUCT_FIELD(u8_t _tos);
|
||||||
/* total length */
|
/* total length */
|
||||||
PACK_STRUCT_FIELD(u16_t _len);
|
PACK_STRUCT_FIELD(u16_t _len);
|
||||||
/* identification */
|
/* identification */
|
||||||
@ -89,9 +91,14 @@ PACK_STRUCT_END
|
|||||||
# include "arch/epstruct.h"
|
# include "arch/epstruct.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define IPH_V(hdr) (ntohs((hdr)->_v_hl_tos) >> 12)
|
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||||
#define IPH_HL(hdr) ((ntohs((hdr)->_v_hl_tos) >> 8) & 0x0f)
|
#define IPH_V(hdr) ((hdr)->_v_hl >> 4)
|
||||||
#define IPH_TOS(hdr) (ntohs((hdr)->_v_hl_tos) & 0xff)
|
#define IPH_HL(hdr) ((hdr)->_v_hl & 0x0f)
|
||||||
|
#else /* BYTE_ORDER == LITTLE_ENDIAN */
|
||||||
|
#define IPH_V(hdr) ((hdr)->_v_hl & 0x0f)
|
||||||
|
#define IPH_HL(hdr) ((hdr)->_v_hl >> 4)
|
||||||
|
#endif /* BYTE_ORDER == LITTLE_ENDIAN */
|
||||||
|
#define IPH_TOS(hdr) ((hdr)->_tos)
|
||||||
#define IPH_LEN(hdr) ((hdr)->_len)
|
#define IPH_LEN(hdr) ((hdr)->_len)
|
||||||
#define IPH_ID(hdr) ((hdr)->_id)
|
#define IPH_ID(hdr) ((hdr)->_id)
|
||||||
#define IPH_OFFSET(hdr) ((hdr)->_offset)
|
#define IPH_OFFSET(hdr) ((hdr)->_offset)
|
||||||
@ -99,7 +106,12 @@ PACK_STRUCT_END
|
|||||||
#define IPH_PROTO(hdr) ((hdr)->_proto)
|
#define IPH_PROTO(hdr) ((hdr)->_proto)
|
||||||
#define IPH_CHKSUM(hdr) ((hdr)->_chksum)
|
#define IPH_CHKSUM(hdr) ((hdr)->_chksum)
|
||||||
|
|
||||||
#define IPH_VHLTOS_SET(hdr, v, hl, tos) (hdr)->_v_hl_tos = (htons(((v) << 12) | ((hl) << 8) | (tos)))
|
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||||
|
#define IPH_VHL_SET(hdr, v, hl) (hdr)->_v_hl = (((v) << 4) | (hl))
|
||||||
|
#else /* BYTE_ORDER == LITTLE_ENDIAN */
|
||||||
|
#define IPH_VHL_SET(hdr, v, hl) (hdr)->_v_hl = ((v) | ((hl) << 4))
|
||||||
|
#endif /* BYTE_ORDER == LITTLE_ENDIAN */
|
||||||
|
#define IPH_TOS_SET(hdr, tos) (hdr)->_tos = (tos)
|
||||||
#define IPH_LEN_SET(hdr, len) (hdr)->_len = (len)
|
#define IPH_LEN_SET(hdr, len) (hdr)->_len = (len)
|
||||||
#define IPH_ID_SET(hdr, id) (hdr)->_id = (id)
|
#define IPH_ID_SET(hdr, id) (hdr)->_id = (id)
|
||||||
#define IPH_OFFSET_SET(hdr, off) (hdr)->_offset = (off)
|
#define IPH_OFFSET_SET(hdr, off) (hdr)->_offset = (off)
|
||||||
|
Loading…
Reference in New Issue
Block a user