00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef __LWIP_IP_H__
00033 #define __LWIP_IP_H__
00034
00035 #include "lwip/opt.h"
00036
00037 #include "lwip/def.h"
00038 #include "lwip/pbuf.h"
00039 #include "lwip/ip_addr.h"
00040 #include "lwip/err.h"
00041 #include "lwip/netif.h"
00042
00043 #ifdef __cplusplus
00044 extern "C" {
00045 #endif
00046
00047
00048 #define IP_OPTIONS_SEND LWIP_IGMP
00049
00050 #define IP_HLEN 20
00051
00052 #define IP_PROTO_ICMP 1
00053 #define IP_PROTO_UDP 17
00054 #define IP_PROTO_UDPLITE 136
00055 #define IP_PROTO_TCP 6
00056
00057
00058
00059
00060 #ifdef IP_HDRINCL
00061 #undef IP_HDRINCL
00062 #endif
00063 #define IP_HDRINCL NULL
00064
00065 #if LWIP_NETIF_HWADDRHINT
00066 #define IP_PCB_ADDRHINT ;u8_t addr_hint
00067 #else
00068 #define IP_PCB_ADDRHINT
00069 #endif
00070
00071
00072
00073
00074
00075 #define IP_PCB \
00076 \
00077 struct ip_addr local_ip; \
00078 struct ip_addr remote_ip; \
00079 \
00080 u16_t so_options; \
00081 \
00082 u8_t tos; \
00083 \
00084 u8_t ttl \
00085 \
00086 IP_PCB_ADDRHINT
00087
00088 struct ip_pcb {
00089
00090 IP_PCB;
00091 };
00092
00093
00094
00095
00096 #define SOF_DEBUG (u16_t)0x0001U
00097 #define SOF_ACCEPTCONN (u16_t)0x0002U
00098 #define SOF_REUSEADDR (u16_t)0x0004U
00099 #define SOF_KEEPALIVE (u16_t)0x0008U
00100 #define SOF_DONTROUTE (u16_t)0x0010U
00101 #define SOF_BROADCAST (u16_t)0x0020U
00102 #define SOF_USELOOPBACK (u16_t)0x0040U
00103 #define SOF_LINGER (u16_t)0x0080U
00104 #define SOF_OOBINLINE (u16_t)0x0100U
00105 #define SOF_REUSEPORT (u16_t)0x0200U
00106
00107
00108 #ifdef PACK_STRUCT_USE_INCLUDES
00109 # include "arch/bpstruct.h"
00110 #endif
00111 PACK_STRUCT_BEGIN
00112 struct ip_hdr {
00113
00114 PACK_STRUCT_FIELD(u16_t _v_hl_tos);
00115
00116 PACK_STRUCT_FIELD(u16_t _len);
00117
00118 PACK_STRUCT_FIELD(u16_t _id);
00119
00120 PACK_STRUCT_FIELD(u16_t _offset);
00121 #define IP_RF 0x8000
00122 #define IP_DF 0x4000
00123 #define IP_MF 0x2000
00124 #define IP_OFFMASK 0x1fff
00125
00126 PACK_STRUCT_FIELD(u16_t _ttl_proto);
00127
00128 PACK_STRUCT_FIELD(u16_t _chksum);
00129
00130 PACK_STRUCT_FIELD(struct ip_addr src);
00131 PACK_STRUCT_FIELD(struct ip_addr dest);
00132 } PACK_STRUCT_STRUCT;
00133 PACK_STRUCT_END
00134 #ifdef PACK_STRUCT_USE_INCLUDES
00135 # include "arch/epstruct.h"
00136 #endif
00137
00138 #define IPH_V(hdr) (ntohs((hdr)->_v_hl_tos) >> 12)
00139 #define IPH_HL(hdr) ((ntohs((hdr)->_v_hl_tos) >> 8) & 0x0f)
00140 #define IPH_TOS(hdr) (ntohs((hdr)->_v_hl_tos) & 0xff)
00141 #define IPH_LEN(hdr) ((hdr)->_len)
00142 #define IPH_ID(hdr) ((hdr)->_id)
00143 #define IPH_OFFSET(hdr) ((hdr)->_offset)
00144 #define IPH_TTL(hdr) (ntohs((hdr)->_ttl_proto) >> 8)
00145 #define IPH_PROTO(hdr) (ntohs((hdr)->_ttl_proto) & 0xff)
00146 #define IPH_CHKSUM(hdr) ((hdr)->_chksum)
00147
00148 #define IPH_VHLTOS_SET(hdr, v, hl, tos) (hdr)->_v_hl_tos = (htons(((v) << 12) | ((hl) << 8) | (tos)))
00149 #define IPH_LEN_SET(hdr, len) (hdr)->_len = (len)
00150 #define IPH_ID_SET(hdr, id) (hdr)->_id = (id)
00151 #define IPH_OFFSET_SET(hdr, off) (hdr)->_offset = (off)
00152 #define IPH_TTL_SET(hdr, ttl) (hdr)->_ttl_proto = (htons(IPH_PROTO(hdr) | ((u16_t)(ttl) << 8)))
00153 #define IPH_PROTO_SET(hdr, proto) (hdr)->_ttl_proto = (htons((proto) | (IPH_TTL(hdr) << 8)))
00154 #define IPH_CHKSUM_SET(hdr, chksum) (hdr)->_chksum = (chksum)
00155
00156
00157 extern struct netif *current_netif;
00158
00159 extern const struct ip_hdr *current_header;
00160
00161 #define ip_init()
00162 struct netif *ip_route(struct ip_addr *dest);
00163 err_t ip_input(struct pbuf *p, struct netif *inp);
00164 err_t ip_output(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
00165 u8_t ttl, u8_t tos, u8_t proto);
00166 err_t ip_output_if(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
00167 u8_t ttl, u8_t tos, u8_t proto,
00168 struct netif *netif);
00169 #if LWIP_NETIF_HWADDRHINT
00170 err_t ip_output_hinted(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
00171 u8_t ttl, u8_t tos, u8_t proto, u8_t *addr_hint);
00172 #endif
00173 #if IP_OPTIONS_SEND
00174 err_t ip_output_if_opt(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
00175 u8_t ttl, u8_t tos, u8_t proto, struct netif *netif, void *ip_options,
00176 u16_t optlen);
00177 #endif
00178
00179
00180
00181 #define ip_current_netif() (current_netif)
00182
00183
00184
00185 #define ip_current_header() (current_header)
00186 #if IP_DEBUG
00187 void ip_debug_print(struct pbuf *p);
00188 #else
00189 #define ip_debug_print(p)
00190 #endif
00191
00192 #ifdef __cplusplus
00193 }
00194 #endif
00195
00196 #endif
00197
00198