Prusa MINI Firmware overview
Main Page
Modules
Classes
Files
File List
File Members
ip4.h
Go to the documentation of this file.
1
/**
2
* @file
3
* IPv4 protocol definitions
4
*/
5
6
/*
7
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
8
* All rights reserved.
9
*
10
* Redistribution and use in source and binary forms, with or without modification,
11
* are permitted provided that the following conditions are met:
12
*
13
* 1. Redistributions of source code must retain the above copyright notice,
14
* this list of conditions and the following disclaimer.
15
* 2. Redistributions in binary form must reproduce the above copyright notice,
16
* this list of conditions and the following disclaimer in the documentation
17
* and/or other materials provided with the distribution.
18
* 3. The name of the author may not be used to endorse or promote products
19
* derived from this software without specific prior written permission.
20
*
21
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
22
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
24
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
29
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
30
* OF SUCH DAMAGE.
31
*
32
* This file is part of the lwIP TCP/IP stack.
33
*
34
* Author: Adam Dunkels <adam@sics.se>
35
*
36
*/
37
#ifndef LWIP_HDR_PROT_IP4_H
38
#define LWIP_HDR_PROT_IP4_H
39
40
#include "
lwip/arch.h
"
41
#include "
lwip/ip4_addr.h
"
42
43
#ifdef __cplusplus
44
extern
"C"
{
45
#endif
46
47
/** This is the packed version of ip4_addr_t,
48
used in network headers that are itself packed */
49
#ifdef PACK_STRUCT_USE_INCLUDES
50
# include "
arch/bpstruct.h
"
51
#endif
52
PACK_STRUCT_BEGIN
53
struct
ip4_addr_packed
{
54
PACK_STRUCT_FIELD
(
u32_t
addr);
55
}
PACK_STRUCT_STRUCT
;
56
PACK_STRUCT_END
57
#ifdef PACK_STRUCT_USE_INCLUDES
58
# include "
arch/epstruct.h
"
59
#endif
60
61
typedef
struct
ip4_addr_packed
ip4_addr_p_t
;
62
63
/* Size of the IPv4 header. Same as 'sizeof(struct ip_hdr)'. */
64
#define IP_HLEN 20
65
66
#ifdef PACK_STRUCT_USE_INCLUDES
67
# include "
arch/bpstruct.h
"
68
#endif
69
PACK_STRUCT_BEGIN
70
/* The IPv4 header */
71
struct
ip_hdr
{
72
/* version / header length */
73
PACK_STRUCT_FLD_8
(
u8_t
_v_hl);
74
/* type of service */
75
PACK_STRUCT_FLD_8
(
u8_t
_tos);
76
/* total length */
77
PACK_STRUCT_FIELD
(
u16_t
_len);
78
/* identification */
79
PACK_STRUCT_FIELD
(
u16_t
_id);
80
/* fragment offset field */
81
PACK_STRUCT_FIELD
(
u16_t
_offset);
82
#define IP_RF 0x8000U
/* reserved fragment flag */
83
#define IP_DF 0x4000U
/* don't fragment flag */
84
#define IP_MF 0x2000U
/* more fragments flag */
85
#define IP_OFFMASK 0x1fffU
/* mask for fragmenting bits */
86
/* time to live */
87
PACK_STRUCT_FLD_8
(
u8_t
_ttl);
88
/* protocol*/
89
PACK_STRUCT_FLD_8
(
u8_t
_proto);
90
/* checksum */
91
PACK_STRUCT_FIELD
(
u16_t
_chksum);
92
/* source and destination IP addresses */
93
PACK_STRUCT_FLD_S
(
ip4_addr_p_t
src);
94
PACK_STRUCT_FLD_S
(
ip4_addr_p_t
dest);
95
}
PACK_STRUCT_STRUCT
;
96
PACK_STRUCT_END
97
#ifdef PACK_STRUCT_USE_INCLUDES
98
# include "
arch/epstruct.h
"
99
#endif
100
101
/* Macros to get struct ip_hdr fields: */
102
#define IPH_V(hdr) ((hdr)->_v_hl >> 4)
103
#define IPH_HL(hdr) ((hdr)->_v_hl & 0x0f)
104
#define IPH_TOS(hdr) ((hdr)->_tos)
105
#define IPH_LEN(hdr) ((hdr)->_len)
106
#define IPH_ID(hdr) ((hdr)->_id)
107
#define IPH_OFFSET(hdr) ((hdr)->_offset)
108
#define IPH_TTL(hdr) ((hdr)->_ttl)
109
#define IPH_PROTO(hdr) ((hdr)->_proto)
110
#define IPH_CHKSUM(hdr) ((hdr)->_chksum)
111
112
/* Macros to set struct ip_hdr fields: */
113
#define IPH_VHL_SET(hdr, v, hl) (hdr)->_v_hl = (u8_t)((((v) << 4) | (hl)))
114
#define IPH_TOS_SET(hdr, tos) (hdr)->_tos = (tos)
115
#define IPH_LEN_SET(hdr, len) (hdr)->_len = (len)
116
#define IPH_ID_SET(hdr, id) (hdr)->_id = (id)
117
#define IPH_OFFSET_SET(hdr, off) (hdr)->_offset = (off)
118
#define IPH_TTL_SET(hdr, ttl) (hdr)->_ttl = (u8_t)(ttl)
119
#define IPH_PROTO_SET(hdr, proto) (hdr)->_proto = (u8_t)(proto)
120
#define IPH_CHKSUM_SET(hdr, chksum) (hdr)->_chksum = (chksum)
121
122
123
#ifdef __cplusplus
124
}
125
#endif
126
127
#endif
/* LWIP_HDR_PROT_IP4_H */
PACK_STRUCT_BEGIN
#define PACK_STRUCT_BEGIN
Definition:
arch.h:242
bpstruct.h
u16_t
uint16_t u16_t
Definition:
arch.h:121
u32_t
uint32_t u32_t
Definition:
arch.h:123
ip_hdr::PACK_STRUCT_FLD_S
PACK_STRUCT_FLD_S(ip4_addr_p_t src)
PACK_STRUCT_STRUCT
PACK_STRUCT_BEGIN struct ip4_addr_packed PACK_STRUCT_STRUCT
ip4_addr_packed
Definition:
ip4.h:53
arch.h
ip_hdr
Definition:
ip4.h:71
u8_t
uint8_t u8_t
Definition:
arch.h:119
ip_hdr::PACK_STRUCT_FIELD
PACK_STRUCT_FIELD(u16_t _len)
ip_hdr::PACK_STRUCT_FLD_8
PACK_STRUCT_FLD_8(u8_t _v_hl)
ip4_addr.h
PACK_STRUCT_END
#define PACK_STRUCT_END
Definition:
arch.h:251
ip4_addr_packed::PACK_STRUCT_FIELD
PACK_STRUCT_FIELD(u32_t addr)
epstruct.h
ip4_addr_p_t
typedefPACK_STRUCT_END struct ip4_addr_packed ip4_addr_p_t
Definition:
ip4.h:61
Prusa-Firmware-Buddy-Private1
lib
Middlewares
Third_Party
LwIP
src
include
lwip
prot
ip4.h
Generated by
1.8.16