Embedded TCP/IP stack  4.7.0
fnet_ip4.h
1 /**************************************************************************
2 *
3 * Copyright 2008-2018 by Andrey Butok. FNET Community.
4 *
5 ***************************************************************************
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may
8 * not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 ***************************************************************************
20 *
21 * IPv4 protocol API.
22 *
23 ***************************************************************************/
24 
25 #ifndef _FNET_IP4_H_
26 
27 #define _FNET_IP4_H_
28 
32 /**************************************************************************/
35 typedef fnet_uint32_t fnet_ip4_addr_t;
36 
37 /**************************************************************************/
47 #define FNET_IP4_ADDR_INIT(a, b, c, d) ((fnet_ip4_addr_t)(FNET_NTOHL((((fnet_uint32_t)(a)&0xFFUL)<< 24U) + (((fnet_uint32_t)(b)&0xFFUL)<< 16U) + (((fnet_uint32_t)(c)&0xFFUL)<< 8U ) + ((fnet_uint32_t)(d)&0xFFUL))))
48 
49 /**************************************************************************/
57 #define FNET_IP4_ADDR_STR_SIZE sizeof("255.255.255.255")
58 
59 /* 169.254/16 prefix that is valid for Link-Local communication. RFC3927*/
60 #define FNET_IP4_ADDR_LINK_LOCAL_PREFIX FNET_IP4_ADDR_INIT(169,254,0,0)
61 
62 /* IPv4 Link-Local broadcast. RFC3927*/
63 #define FNET_IP4_ADDR_LINK_LOCAL_BROADCAST FNET_IP4_ADDR_INIT(169,254,255,255)
64 
65 /************************************************************************
66 * Definitions for IP type of service.
67 *************************************************************************/
68 #define FNET_IP4_TOS_NORMAL (0x0U)
69 #define FNET_IP4_TOS_LOWDELAY (0x10U)
70 #define FNET_IP4_TOS_THROUGHPUT (0x08U)
71 #define FNET_IP4_TOS_RELIABILITY (0x04U)
72 
73 /************************************************************************
74 * Definitions of five different classes.
75 *************************************************************************/
76 #define FNET_IP4_CLASS_A(i) (((fnet_ip4_addr_t)(i) & FNET_HTONL(0x80000000U)) == 0U)
77 #define FNET_IP4_CLASS_A_NET FNET_HTONL(0xff000000U)
78 
79 #define FNET_IP4_CLASS_B(i) (((fnet_ip4_addr_t)(i) & FNET_HTONL(0xc0000000U)) == FNET_HTONL(0x80000000U))
80 #define FNET_IP4_CLASS_B_NET FNET_HTONL(0xffff0000U)
81 
82 #define FNET_IP4_CLASS_C(i) (((fnet_ip4_addr_t)(i) & FNET_HTONL(0xe0000000U)) == FNET_HTONL(0xc0000000U))
83 #define FNET_IP4_CLASS_C_NET FNET_HTONL(0xffffff00U)
84 
85 #define FNET_IP4_CLASS_D(i) (((fnet_ip4_addr_t)(i) & FNET_HTONL(0xf0000000U)) == FNET_HTONL(0xe0000000U))
86 #define FNET_IP4_CLASS_D_NET FNET_HTONL(0xf0000000U)
87 /* Host groups are identified by class D IP addresses.*/
88 #define FNET_IP4_ADDR_IS_MULTICAST(addr) (FNET_IP4_CLASS_D(addr)?FNET_TRUE:FNET_FALSE)
89 
90 #define FNET_IP4_ADDR_IS_UNSPECIFIED(addr) (((addr) == INADDR_ANY)?FNET_TRUE:FNET_FALSE)
91 
92 #define FNET_IP4_CLASS_E(i) (((fnet_ip4_addr_t)(i) & FNET_HTONL(0xf0000000U)) == FNET_HTONL(0xf0000000U))
93 #define FNET_IP4_EXPERIMENTAL(i) FNET_IP4_CLASS_E(i)
94 #define FNET_IP4_BADCLASS(i) FNET_IP4_CLASS_E(i)
95 
96 #define FNET_IP4_ADDR1(ipaddr) ((fnet_uint8_t)(fnet_ntohl(ipaddr) >> 24U) & 0xffU)
97 #define FNET_IP4_ADDR2(ipaddr) ((fnet_uint8_t)(fnet_ntohl(ipaddr) >> 16U) & 0xffU)
98 #define FNET_IP4_ADDR3(ipaddr) ((fnet_uint8_t)(fnet_ntohl(ipaddr) >> 8U) & 0xffU)
99 #define FNET_IP4_ADDR4(ipaddr) ((fnet_uint8_t)(fnet_ntohl(ipaddr)) & 0xffU)
100 
103 #endif
fnet_uint32_t fnet_ip4_addr_t
32-bit IPv4 address type.
Definition: fnet_ip4.h:35

© 2005-2020 by Andrej Butok. http://fnet.sourceforge.net