Embedded TCP/IP stack: fnet_ip6.h Source File

FNET

fnet_ip6.h
1 /**************************************************************************
2 *
3 * Copyright 2011-2016 by Andrey Butok. FNET Community.
4 * Copyright 2008-2010 by Andrey Butok. Freescale Semiconductor, Inc.
5 *
6 ***************************************************************************
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License"); you may
9 * not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 *
20 ***************************************************************************
21 *
22 * IPv6 protocol API.
23 *
24 ***************************************************************************/
25 
26 #ifndef _FNET_IP6_H_
27 
28 #define _FNET_IP6_H_
29 
33 /**************************************************************************/
36 FNET_COMP_PACKED_BEGIN
37 /* 128-bit IP6 address */
38 typedef union
39 {
40  fnet_uint8_t addr[16];
41  fnet_uint16_t addr16[8];
42  fnet_uint32_t addr32[4];
44 FNET_COMP_PACKED_END
45 
46 /**************************************************************************/
53 #define FNET_IP6_ADDR_STR_SIZE sizeof("abcd:abcd:abcd:abcd:abcd:abcd:abcd:abcd")
54 
57 /******************************************************************
58 * Constants
59 *******************************************************************/
60 #define FNET_IP6_HEAD_SIZE 40u /* IPv6 Header size. */
61 
62 #define FNET_IP6_DEFAULT_MTU 1280u /* Minimum IPv6 datagram size which
63  * must be supported by all IPv6 hosts */
64 
65 /****************************************************************
66  *
67  * Helpful macros.
68  *
69  *****************************************************************/
70 #define FNET_IP6_ADDR_INIT(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16) \
71  {{ (a1), (a2), (a3), (a4), (a5), (a6), (a7), (a8), (a9), (a10), (a11), (a12), (a13), (a14), (a15), (a16) }}
72 
73 /*
74  * Definition of some useful macros to handle IP6 addresses
75  */
76 #define FNET_IP6_ADDR_ANY_INIT FNET_IP6_ADDR_INIT(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
77 #define FNET_IP6_ADDR_LOOPBACK_INIT FNET_IP6_ADDR_INIT(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01)
78 #define FNET_IP6_ADDR_NODELOCAL_ALLNODES_INIT FNET_IP6_ADDR_INIT(0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01)
79 #define FNET_IP6_ADDR_INTFACELOCAL_ALLNODES_INIT FNET_IP6_ADDR_INIT(0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01)
80 #define FNET_IP6_ADDR_LINKLOCAL_ALLNODES_INIT FNET_IP6_ADDR_INIT(0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01)
81 #define FNET_IP6_ADDR_LINKLOCAL_ALLROUTERS_INIT FNET_IP6_ADDR_INIT(0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02)
82 #define FNET_IP6_ADDR_LINKLOCAL_ALLV2ROUTERS_INIT FNET_IP6_ADDR_INIT(0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16)
83 #define FNET_IP6_ADDR_LINKLOCAL_PREFIX_INIT FNET_IP6_ADDR_INIT(0xFE, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
84 
85 extern const fnet_ip6_addr_t fnet_ip6_addr_any;
86 extern const fnet_ip6_addr_t fnet_ip6_addr_loopback;
87 extern const fnet_ip6_addr_t fnet_ip6_addr_nodelocal_allnodes;
88 extern const fnet_ip6_addr_t fnet_ip6_addr_linklocal_allnodes;
89 extern const fnet_ip6_addr_t fnet_ip6_addr_linklocal_allrouters;
90 extern const fnet_ip6_addr_t fnet_ip6_addr_linklocal_allv2routers;
91 extern const fnet_ip6_addr_t fnet_ip6_addr_linklocal_prefix;
92 
93 /* Equality. */
94 #define FNET_IP6_ADDR_EQUAL(a, b) \
95  ((fnet_memcmp(&(a)->addr[0], &(b)->addr[0], sizeof(fnet_ip6_addr_t)) == 0)?FNET_TRUE:FNET_FALSE)
96 
97 /* Copying address. */
98 #define FNET_IP6_ADDR_COPY(from_addr, to_addr) \
99  (fnet_memcpy(&(to_addr)->addr[0], &(from_addr)->addr[0], sizeof(fnet_ip6_addr_t)))
100 
101 /* Unspecified.*/
102 #define FNET_IP6_ADDR_IS_UNSPECIFIED(a) \
103  (((((a)->addr32[0]) == 0U) && \
104  (((a)->addr32[1]) == 0U) && \
105  (((a)->addr32[2]) == 0U) && \
106  (((a)->addr32[3]) == 0U))?FNET_TRUE:FNET_FALSE)
107 
108 /* Loopback.*/
109 #define FNET_IP6_ADDR_IS_LOOPBACK(a) \
110  ((((a)->addr32[0]) == 0U) && \
111  (((a)->addr32[1]) == 0U) && \
112  (((a)->addr32[2]) == 0U) && \
113  (((a)->addr32[3]) == FNET_NTOHL(1U)))
114 
115 /* Multicast. */
116 #define FNET_IP6_ADDR_IS_MULTICAST(a) ((((a)->addr[0]) == 0xffU)?FNET_TRUE:FNET_FALSE)
117 
118 /* Unicast Scope.*/
119 #define FNET_IP6_ADDR_IS_LINKLOCAL(a) \
120  ((((a)->addr[0]) == 0xfeU) && ((((a)->addr[1]) & 0xc0U) == 0x80U))
121 #define FNET_IP6_ADDR_IS_SITELOCAL(a) \
122  ((((a)->addr[0]) == 0xfeU) && ((((a)->addr[1]) & 0xc0U) == 0xc0U))
123 
124 #endif /* _FNET_IP6_H_ */
128-bit IPv6 address type.
Definition: fnet_ip6.h:38

© 2005-2018 by Andrey Butok. http://fnet.sourceforge.net