Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of OmniWheels by
fnet_ip.h
00001 /************************************************************************** 00002 * 00003 * Copyright 2011-2016 by Andrey Butok. FNET Community. 00004 * Copyright 2008-2010 by Andrey Butok. Freescale Semiconductor, Inc. 00005 * 00006 *************************************************************************** 00007 * 00008 * Licensed under the Apache License, Version 2.0 (the "License"); you may 00009 * not use this file except in compliance with the License. 00010 * You may obtain a copy of the License at 00011 * 00012 * http://www.apache.org/licenses/LICENSE-2.0 00013 * 00014 * Unless required by applicable law or agreed to in writing, software 00015 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 00016 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00017 * See the License for the specific language governing permissions and 00018 * limitations under the License. 00019 * 00020 **********************************************************************/ 00021 /*! 00022 * @brief IP protocol API. 00023 * 00024 ***************************************************************************/ 00025 00026 #ifndef _FNET_IP_H_ 00027 00028 #define _FNET_IP_H_ 00029 00030 /*! @addtogroup fnet_socket */ 00031 /*! @{ */ 00032 00033 /**************************************************************************/ /*! 00034 * @brief 32-bit IPv4 address type. 00035 ******************************************************************************/ 00036 typedef fnet_uint32_t fnet_ip4_addr_t; 00037 00038 /**************************************************************************/ /*! 00039 * @def FNET_IP4_ADDR_INIT 00040 * @param a First octet of an IP address. 00041 * @param b Second octet of an IP address. 00042 * @param c Third octet of an IP address. 00043 * @param d Fourth octet of an IP address. 00044 * @hideinitializer 00045 * @brief Converts the standard dotted-decimal notation @c a.b.c.d 00046 * to an integer value, suitable for use as an Internet address (in network byte order). 00047 ******************************************************************************/ 00048 #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)))) 00049 00050 /**************************************************************************/ /*! 00051 * @def FNET_IP4_ADDR_STR_SIZE 00052 * @brief Size of the string buffer that will contain 00053 * null-terminated ASCII string of an IPv4 address 00054 * in standard "." notation. 00055 * @see fnet_inet_ntoa, fnet_inet_ntop 00056 * @showinitializer 00057 ******************************************************************************/ 00058 #define FNET_IP4_ADDR_STR_SIZE sizeof("255.255.255.255") 00059 00060 /* 169.254/16 prefix that is valid for Link-Local communication. RFC3927*/ 00061 #define FNET_IP4_ADDR_LINK_LOCAL_PREFIX FNET_IP4_ADDR_INIT(169,254,0,0) 00062 00063 /* IPv4 Link-Local broadcast. RFC3927*/ 00064 #define FNET_IP4_ADDR_LINK_LOCAL_BROADCAST FNET_IP4_ADDR_INIT(169,254,255,255) 00065 00066 /************************************************************************ 00067 * Definitions for options. 00068 *************************************************************************/ 00069 /* The type field is divided into three internal fields:*/ 00070 #define IPOPT_COPIED(t) ((t)&0x80U) /* 1-bit copied flag */ 00071 #define IPOPT_CLASS (t) ((t)&0x60U) /* 2-bit class field */ 00072 #define IPOPT_NUMBER(t) ((t)&0x1fU) /* 5-bit number field */ 00073 /* Class field: */ 00074 #define IPOPT_CONTROL (0x00U) /* control */ 00075 #define IPOPT_RESERVED1 (0x20U) /* reserved */ 00076 #define IPOPT_DEBMEAS (0x40U) /* debugging and measurement */ 00077 #define IPOPT_RESERVED2 (0x60U) /* reserved */ 00078 /* Currently defined IP options */ 00079 #define IPOPT_EOL (0U) /* end of option list */ 00080 #define IPOPT_NOP (1U) /* no operation */ 00081 00082 #define IPOPT_RR (7U) /* record route */ 00083 #define IPOPT_TS (68U) /* timestamp */ 00084 #define IPOPT_SECURITY (130U) /* basic security */ 00085 #define IPOPT_LSRR (131U) /* loose source and record route */ 00086 #define IPOPT_SATID (136U) /* stream id */ 00087 #define IPOPT_SSRR (137U) /* strict source and record route */ 00088 00089 #define IPOPT_TYPE (0U) 00090 #define IPOPT_LENGTH (1U) 00091 #define IPOPT_OFFSET (2U) 00092 #define IPOPT_OFFSET_MIN (4U) /* minimum value of 'offset'*/ 00093 00094 /************************************************************************ 00095 * Definitions for IP type of service. 00096 *************************************************************************/ 00097 #define IP_TOS_NORMAL (0x0U) 00098 #define IP_TOS_LOWDELAY (0x10U) 00099 #define IP_TOS_THROUGHPUT (0x08U) 00100 #define IP_TOS_RELIABILITY (0x04U) 00101 00102 /************************************************************************ 00103 * Timestamp option 00104 *************************************************************************/ 00105 #define IPOPT_TS_FLAG_TSONLY (0U) /* Record timestamps.*/ 00106 #define IPOPT_TS_FLAG_TSANDADDR (1U) /* Record addresses and timestamps.*/ 00107 #define IPOPT_TS_FLAG_TSPRESPEC (3U) /* Record timestamps only at the prespecified systems.*/ 00108 00109 /************************************************************************ 00110 * Definitions of five different classes. 00111 *************************************************************************/ 00112 #define FNET_IP4_CLASS_A(i) (((fnet_ip4_addr_t)(i) & FNET_HTONL(0x80000000U)) == 0U) 00113 #define FNET_IP4_CLASS_A_NET FNET_HTONL(0xff000000U) 00114 00115 #define FNET_IP4_CLASS_B(i) (((fnet_ip4_addr_t)(i) & FNET_HTONL(0xc0000000U)) == FNET_HTONL(0x80000000U)) 00116 #define FNET_IP4_CLASS_B_NET FNET_HTONL(0xffff0000U) 00117 00118 #define FNET_IP4_CLASS_C(i) (((fnet_ip4_addr_t)(i) & FNET_HTONL(0xe0000000U)) == FNET_HTONL(0xc0000000U)) 00119 #define FNET_IP4_CLASS_C_NET FNET_HTONL(0xffffff00U) 00120 00121 #define FNET_IP4_CLASS_D(i) (((fnet_ip4_addr_t)(i) & FNET_HTONL(0xf0000000U)) == FNET_HTONL(0xe0000000U)) 00122 #define FNET_IP4_CLASS_D_NET FNET_HTONL(0xf0000000U) 00123 /* Host groups are identified by class D IP addresses.*/ 00124 #define FNET_IP4_ADDR_IS_MULTICAST(addr) (FNET_IP4_CLASS_D(addr)?FNET_TRUE:FNET_FALSE) 00125 00126 #define FNET_IP4_ADDR_IS_UNSPECIFIED(addr) (((addr) == INADDR_ANY)?FNET_TRUE:FNET_FALSE) 00127 00128 #define FNET_IP4_CLASS_E(i) (((fnet_ip4_addr_t)(i) & FNET_HTONL(0xf0000000U)) == FNET_HTONL(0xf0000000U)) 00129 #define FNET_IP4_EXPERIMENTAL(i) FNET_IP4_CLASS_E(i) 00130 #define FNET_IP4_BADCLASS(i) FNET_IP4_CLASS_E(i) 00131 00132 #define FNET_IP4_ADDR1(ipaddr) ((fnet_uint8_t)(fnet_ntohl(ipaddr) >> 24U) & 0xffU) 00133 #define FNET_IP4_ADDR2(ipaddr) ((fnet_uint8_t)(fnet_ntohl(ipaddr) >> 16U) & 0xffU) 00134 #define FNET_IP4_ADDR3(ipaddr) ((fnet_uint8_t)(fnet_ntohl(ipaddr) >> 8U) & 0xffU) 00135 #define FNET_IP4_ADDR4(ipaddr) ((fnet_uint8_t)(fnet_ntohl(ipaddr)) & 0xffU) 00136 00137 /*! @} */ 00138 00139 #endif
Generated on Fri Jul 22 2022 04:53:49 by
1.7.2
