Embedded TCP/IP stack: fnet_ip4.h Source File

FNET

fnet_ip4.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 * IPv4 protocol API.
23 *
24 ***************************************************************************/
25 
26 #ifndef _FNET_IP4_H_
27 
28 #define _FNET_IP4_H_
29 
33 /**************************************************************************/
36 typedef fnet_uint32_t fnet_ip4_addr_t;
37 
38 /**************************************************************************/
48 #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))))
49 
50 /**************************************************************************/
58 #define FNET_IP4_ADDR_STR_SIZE sizeof("255.255.255.255")
59 
60 /* 169.254/16 prefix that is valid for Link-Local communication. RFC3927*/
61 #define FNET_IP4_ADDR_LINK_LOCAL_PREFIX FNET_IP4_ADDR_INIT(169,254,0,0)
62 
63 /* IPv4 Link-Local broadcast. RFC3927*/
64 #define FNET_IP4_ADDR_LINK_LOCAL_BROADCAST FNET_IP4_ADDR_INIT(169,254,255,255)
65 
66 /************************************************************************
67 * Definitions for IP type of service.
68 *************************************************************************/
69 #define FNET_IP4_TOS_NORMAL (0x0U)
70 #define FNET_IP4_TOS_LOWDELAY (0x10U)
71 #define FNET_IP4_TOS_THROUGHPUT (0x08U)
72 #define FNET_IP4_TOS_RELIABILITY (0x04U)
73 
74 /************************************************************************
75 * Definitions of five different classes.
76 *************************************************************************/
77 #define FNET_IP4_CLASS_A(i) (((fnet_ip4_addr_t)(i) & FNET_HTONL(0x80000000U)) == 0U)
78 #define FNET_IP4_CLASS_A_NET FNET_HTONL(0xff000000U)
79 
80 #define FNET_IP4_CLASS_B(i) (((fnet_ip4_addr_t)(i) & FNET_HTONL(0xc0000000U)) == FNET_HTONL(0x80000000U))
81 #define FNET_IP4_CLASS_B_NET FNET_HTONL(0xffff0000U)
82 
83 #define FNET_IP4_CLASS_C(i) (((fnet_ip4_addr_t)(i) & FNET_HTONL(0xe0000000U)) == FNET_HTONL(0xc0000000U))
84 #define FNET_IP4_CLASS_C_NET FNET_HTONL(0xffffff00U)
85 
86 #define FNET_IP4_CLASS_D(i) (((fnet_ip4_addr_t)(i) & FNET_HTONL(0xf0000000U)) == FNET_HTONL(0xe0000000U))
87 #define FNET_IP4_CLASS_D_NET FNET_HTONL(0xf0000000U)
88 /* Host groups are identified by class D IP addresses.*/
89 #define FNET_IP4_ADDR_IS_MULTICAST(addr) (FNET_IP4_CLASS_D(addr)?FNET_TRUE:FNET_FALSE)
90 
91 #define FNET_IP4_ADDR_IS_UNSPECIFIED(addr) (((addr) == INADDR_ANY)?FNET_TRUE:FNET_FALSE)
92 
93 #define FNET_IP4_CLASS_E(i) (((fnet_ip4_addr_t)(i) & FNET_HTONL(0xf0000000U)) == FNET_HTONL(0xf0000000U))
94 #define FNET_IP4_EXPERIMENTAL(i) FNET_IP4_CLASS_E(i)
95 #define FNET_IP4_BADCLASS(i) FNET_IP4_CLASS_E(i)
96 
97 #define FNET_IP4_ADDR1(ipaddr) ((fnet_uint8_t)(fnet_ntohl(ipaddr) >> 24U) & 0xffU)
98 #define FNET_IP4_ADDR2(ipaddr) ((fnet_uint8_t)(fnet_ntohl(ipaddr) >> 16U) & 0xffU)
99 #define FNET_IP4_ADDR3(ipaddr) ((fnet_uint8_t)(fnet_ntohl(ipaddr) >> 8U) & 0xffU)
100 #define FNET_IP4_ADDR4(ipaddr) ((fnet_uint8_t)(fnet_ntohl(ipaddr)) & 0xffU)
101 
104 #endif
fnet_uint32_t fnet_ip4_addr_t
32-bit IPv4 address type.
Definition: fnet_ip4.h:36

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