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.
ip4.h
00001 /** 00002 * @file 00003 * IPv4 API 00004 */ 00005 00006 /* 00007 * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 00008 * All rights reserved. 00009 * 00010 * Redistribution and use in source and binary forms, with or without modification, 00011 * are permitted provided that the following conditions are met: 00012 * 00013 * 1. Redistributions of source code must retain the above copyright notice, 00014 * this list of conditions and the following disclaimer. 00015 * 2. Redistributions in binary form must reproduce the above copyright notice, 00016 * this list of conditions and the following disclaimer in the documentation 00017 * and/or other materials provided with the distribution. 00018 * 3. The name of the author may not be used to endorse or promote products 00019 * derived from this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 00022 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00023 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 00024 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00025 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 00026 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00027 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00028 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 00029 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 00030 * OF SUCH DAMAGE. 00031 * 00032 * This file is part of the lwIP TCP/IP stack. 00033 * 00034 * Author: Adam Dunkels <adam@sics.se> 00035 * 00036 */ 00037 #ifndef LWIP_HDR_IP4_H 00038 #define LWIP_HDR_IP4_H 00039 00040 #include "lwip/opt.h" 00041 00042 #if LWIP_IPV4 00043 00044 #include "lwip/def.h" 00045 #include "lwip/pbuf.h" 00046 #include "lwip/ip4_addr.h" 00047 #include "lwip/err.h" 00048 #include "lwip/netif.h" 00049 00050 #ifdef __cplusplus 00051 extern "C" { 00052 #endif 00053 00054 #ifdef LWIP_HOOK_IP4_ROUTE_SRC 00055 #define LWIP_IPV4_SRC_ROUTING 1 00056 #else 00057 #define LWIP_IPV4_SRC_ROUTING 0 00058 #endif 00059 00060 /** Currently, the function ip_output_if_opt() is only used with IGMP */ 00061 #define IP_OPTIONS_SEND (LWIP_IPV4 && LWIP_IGMP) 00062 00063 #define IP_HLEN 20 00064 00065 00066 #ifdef PACK_STRUCT_USE_INCLUDES 00067 # include "arch/bpstruct.h" 00068 #endif 00069 PACK_STRUCT_BEGIN 00070 struct ip_hdr { 00071 /* version / header length */ 00072 PACK_STRUCT_FLD_8(u8_t _v_hl); 00073 /* type of service */ 00074 PACK_STRUCT_FLD_8(u8_t _tos); 00075 /* total length */ 00076 PACK_STRUCT_FIELD(u16_t _len); 00077 /* identification */ 00078 PACK_STRUCT_FIELD(u16_t _id); 00079 /* fragment offset field */ 00080 PACK_STRUCT_FIELD(u16_t _offset); 00081 #define IP_RF 0x8000U /* reserved fragment flag */ 00082 #define IP_DF 0x4000U /* don't fragment flag */ 00083 #define IP_MF 0x2000U /* more fragments flag */ 00084 #define IP_OFFMASK 0x1fffU /* mask for fragmenting bits */ 00085 /* time to live */ 00086 PACK_STRUCT_FLD_8(u8_t _ttl); 00087 /* protocol*/ 00088 PACK_STRUCT_FLD_8(u8_t _proto); 00089 /* checksum */ 00090 PACK_STRUCT_FIELD(u16_t _chksum); 00091 /* source and destination IP addresses */ 00092 PACK_STRUCT_FLD_S(ip4_addr_p_t src); 00093 PACK_STRUCT_FLD_S(ip4_addr_p_t dest); 00094 } PACK_STRUCT_STRUCT; 00095 PACK_STRUCT_END 00096 #ifdef PACK_STRUCT_USE_INCLUDES 00097 # include "arch/epstruct.h" 00098 #endif 00099 00100 #define IPH_V(hdr) ((hdr)->_v_hl >> 4) 00101 #define IPH_HL(hdr) ((hdr)->_v_hl & 0x0f) 00102 #define IPH_TOS(hdr) ((hdr)->_tos) 00103 #define IPH_LEN(hdr) ((hdr)->_len) 00104 #define IPH_ID(hdr) ((hdr)->_id) 00105 #define IPH_OFFSET(hdr) ((hdr)->_offset) 00106 #define IPH_TTL(hdr) ((hdr)->_ttl) 00107 #define IPH_PROTO(hdr) ((hdr)->_proto) 00108 #define IPH_CHKSUM(hdr) ((hdr)->_chksum) 00109 00110 #define IPH_VHL_SET(hdr, v, hl) (hdr)->_v_hl = (u8_t)((((v) << 4) | (hl))) 00111 #define IPH_TOS_SET(hdr, tos) (hdr)->_tos = (tos) 00112 #define IPH_LEN_SET(hdr, len) (hdr)->_len = (len) 00113 #define IPH_ID_SET(hdr, id) (hdr)->_id = (id) 00114 #define IPH_OFFSET_SET(hdr, off) (hdr)->_offset = (off) 00115 #define IPH_TTL_SET(hdr, ttl) (hdr)->_ttl = (u8_t)(ttl) 00116 #define IPH_PROTO_SET(hdr, proto) (hdr)->_proto = (u8_t)(proto) 00117 #define IPH_CHKSUM_SET(hdr, chksum) (hdr)->_chksum = (chksum) 00118 00119 #define ip_init() /* Compatibility define, no init needed. */ 00120 struct netif *ip4_route(const ip4_addr_t *dest); 00121 #if LWIP_IPV4_SRC_ROUTING 00122 struct netif *ip4_route_src(const ip4_addr_t *dest, const ip4_addr_t *src); 00123 #else /* LWIP_IPV4_SRC_ROUTING */ 00124 #define ip4_route_src(dest, src) ip4_route(dest) 00125 #endif /* LWIP_IPV4_SRC_ROUTING */ 00126 err_t ip4_input(struct pbuf *p, struct netif *inp); 00127 err_t ip4_output(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest, 00128 u8_t ttl, u8_t tos, u8_t proto); 00129 err_t ip4_output_if(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest, 00130 u8_t ttl, u8_t tos, u8_t proto, struct netif *netif); 00131 err_t ip4_output_if_src(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest, 00132 u8_t ttl, u8_t tos, u8_t proto, struct netif *netif); 00133 #if LWIP_NETIF_HWADDRHINT 00134 err_t ip4_output_hinted(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest, 00135 u8_t ttl, u8_t tos, u8_t proto, u8_t *addr_hint); 00136 #endif /* LWIP_NETIF_HWADDRHINT */ 00137 #if IP_OPTIONS_SEND 00138 err_t ip4_output_if_opt(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest, 00139 u8_t ttl, u8_t tos, u8_t proto, struct netif *netif, void *ip_options, 00140 u16_t optlen); 00141 err_t ip4_output_if_opt_src(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest, 00142 u8_t ttl, u8_t tos, u8_t proto, struct netif *netif, void *ip_options, 00143 u16_t optlen); 00144 #endif /* IP_OPTIONS_SEND */ 00145 00146 #if LWIP_MULTICAST_TX_OPTIONS 00147 void ip4_set_default_multicast_netif(struct netif* default_multicast_netif); 00148 #endif /* LWIP_MULTICAST_TX_OPTIONS */ 00149 00150 #define ip4_netif_get_local_ip(netif) (((netif) != NULL) ? netif_ip_addr4(netif) : NULL) 00151 00152 #if IP_DEBUG 00153 void ip4_debug_print(struct pbuf *p); 00154 #else 00155 #define ip4_debug_print(p) 00156 #endif /* IP_DEBUG */ 00157 00158 #ifdef __cplusplus 00159 } 00160 #endif 00161 00162 #endif /* LWIP_IPV4 */ 00163 00164 #endif /* LWIP_HDR_IP_H */ 00165 00166
Generated on Tue Jul 12 2022 17:34:44 by
