STM32F769IDiscovery  1.00
uDANTE Audio Networking with STM32F7 DISCO board
ip4.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  * 3. The name of the author may not be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
19  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
21  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
24  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
25  * OF SUCH DAMAGE.
26  *
27  * This file is part of the lwIP TCP/IP stack.
28  *
29  * Author: Adam Dunkels <adam@sics.se>
30  *
31  */
32 #ifndef LWIP_HDR_IP4_H
33 #define LWIP_HDR_IP4_H
34 
35 #include "lwip/opt.h"
36 
37 #if LWIP_IPV4
38 
39 #include "lwip/def.h"
40 #include "lwip/pbuf.h"
41 #include "lwip/ip_addr.h"
42 #include "lwip/ip6_addr.h"
43 #include "lwip/err.h"
44 #include "lwip/netif.h"
45 
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 
50 #ifdef LWIP_HOOK_IP4_ROUTE_SRC
51 #define LWIP_IPV4_SRC_ROUTING 1
52 #else
53 #define LWIP_IPV4_SRC_ROUTING 0
54 #endif
55 
57 #define IP_OPTIONS_SEND (LWIP_IPV4 && LWIP_IGMP)
58 
59 #define IP_HLEN 20
60 
61 
62 #ifdef PACK_STRUCT_USE_INCLUDES
63 # include "arch/bpstruct.h"
64 #endif
66 struct ip_hdr {
67  /* version / header length */
68  PACK_STRUCT_FLD_8(u8_t _v_hl);
69  /* type of service */
70  PACK_STRUCT_FLD_8(u8_t _tos);
71  /* total length */
73  /* identification */
75  /* fragment offset field */
76  PACK_STRUCT_FIELD(u16_t _offset);
77 #define IP_RF 0x8000U /* reserved fragment flag */
78 #define IP_DF 0x4000U /* don't fragment flag */
79 #define IP_MF 0x2000U /* more fragments flag */
80 #define IP_OFFMASK 0x1fffU /* mask for fragmenting bits */
81  /* time to live */
82  PACK_STRUCT_FLD_8(u8_t _ttl);
83  /* protocol*/
84  PACK_STRUCT_FLD_8(u8_t _proto);
85  /* checksum */
86  PACK_STRUCT_FIELD(u16_t _chksum);
87  /* source and destination IP addresses */
88  PACK_STRUCT_FLD_S(ip4_addr_p_t src);
89  PACK_STRUCT_FLD_S(ip4_addr_p_t dest);
92 #ifdef PACK_STRUCT_USE_INCLUDES
93 # include "arch/epstruct.h"
94 #endif
95 
96 #define IPH_V(hdr) ((hdr)->_v_hl >> 4)
97 #define IPH_HL(hdr) ((hdr)->_v_hl & 0x0f)
98 #define IPH_TOS(hdr) ((hdr)->_tos)
99 #define IPH_LEN(hdr) ((hdr)->_len)
100 #define IPH_ID(hdr) ((hdr)->_id)
101 #define IPH_OFFSET(hdr) ((hdr)->_offset)
102 #define IPH_TTL(hdr) ((hdr)->_ttl)
103 #define IPH_PROTO(hdr) ((hdr)->_proto)
104 #define IPH_CHKSUM(hdr) ((hdr)->_chksum)
105 
106 #define IPH_VHL_SET(hdr, v, hl) (hdr)->_v_hl = (u8_t)((((v) << 4) | (hl)))
107 #define IPH_TOS_SET(hdr, tos) (hdr)->_tos = (tos)
108 #define IPH_LEN_SET(hdr, len) (hdr)->_len = (len)
109 #define IPH_ID_SET(hdr, id) (hdr)->_id = (id)
110 #define IPH_OFFSET_SET(hdr, off) (hdr)->_offset = (off)
111 #define IPH_TTL_SET(hdr, ttl) (hdr)->_ttl = (u8_t)(ttl)
112 #define IPH_PROTO_SET(hdr, proto) (hdr)->_proto = (u8_t)(proto)
113 #define IPH_CHKSUM_SET(hdr, chksum) (hdr)->_chksum = (chksum)
114 
115 #define ip_init() /* Compatibility define, no init needed. */
116 struct netif *ip4_route(const ip4_addr_t *dest);
117 #if LWIP_IPV4_SRC_ROUTING
118 struct netif *ip4_route_src(const ip4_addr_t *dest, const ip4_addr_t *src);
119 #else /* LWIP_IPV4_SRC_ROUTING */
120 #define ip4_route_src(dest, src) ip4_route(dest)
121 #endif /* LWIP_IPV4_SRC_ROUTING */
122 err_t ip4_input(struct pbuf *p, struct netif *inp);
123 err_t ip4_output(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest,
124  u8_t ttl, u8_t tos, u8_t proto);
125 err_t ip4_output_if(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest,
126  u8_t ttl, u8_t tos, u8_t proto, struct netif *netif);
127 err_t ip4_output_if_src(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest,
128  u8_t ttl, u8_t tos, u8_t proto, struct netif *netif);
129 #if LWIP_NETIF_HWADDRHINT
130 err_t ip4_output_hinted(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest,
131  u8_t ttl, u8_t tos, u8_t proto, u8_t *addr_hint);
132 #endif /* LWIP_NETIF_HWADDRHINT */
133 #if IP_OPTIONS_SEND
134 err_t ip4_output_if_opt(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest,
135  u8_t ttl, u8_t tos, u8_t proto, struct netif *netif, void *ip_options,
136  u16_t optlen);
137 err_t ip4_output_if_opt_src(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest,
138  u8_t ttl, u8_t tos, u8_t proto, struct netif *netif, void *ip_options,
139  u16_t optlen);
140 #endif /* IP_OPTIONS_SEND */
141 
142 #if LWIP_MULTICAST_TX_OPTIONS
143 void ip4_set_default_multicast_netif(struct netif* default_multicast_netif);
144 #endif /* LWIP_MULTICAST_TX_OPTIONS */
145 
146 #define ip4_netif_get_local_ip(netif) (((netif) != NULL) ? netif_ip_addr4(netif) : NULL)
147 
148 #if IP_DEBUG
149 void ip4_debug_print(struct pbuf *p);
150 #else
151 #define ip4_debug_print(p)
152 #endif /* IP_DEBUG */
153 
154 #ifdef __cplusplus
155 }
156 #endif
157 
158 #endif /* LWIP_IPV4 */
159 
160 
161 #endif /* LWIP_HDR_IP_H */
162 
#define PACK_STRUCT_STRUCT
Definition: arch.h:68
#define PACK_STRUCT_FLD_8(x)
Definition: arch.h:78
#define PACK_STRUCT_FIELD(x)
Definition: arch.h:72
Definition: pbuf.h:108
s8_t err_t
Definition: err.h:47
Definition: netif.h:182
#define PACK_STRUCT_FLD_S(x)
Definition: arch.h:84
#define PACK_STRUCT_BEGIN
Definition: arch.h:60
unsigned char u8_t
Definition: cc.h:38
#define PACK_STRUCT_END
Definition: arch.h:64
unsigned short u16_t
Definition: cc.h:40