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_IGMP 2
00054 #define IP_PROTO_UDP 17
00055 #define IP_PROTO_UDPLITE 136
00056 #define IP_PROTO_TCP 6
00057
00058
00059
00060
00061 #ifdef IP_HDRINCL
00062 #undef IP_HDRINCL
00063 #endif
00064 #define IP_HDRINCL NULL
00065
00066 #if LWIP_NETIF_HWADDRHINT
00067 #define IP_PCB_ADDRHINT ;u8_t addr_hint
00068 #else
00069 #define IP_PCB_ADDRHINT
00070 #endif
00071
00072
00073
00074
00075
00076 #define IP_PCB \
00077 \
00078 ip_addr_t local_ip; \
00079 ip_addr_t remote_ip; \
00080 \
00081 u8_t so_options; \
00082 \
00083 u8_t tos; \
00084 \
00085 u8_t ttl \
00086 \
00087 IP_PCB_ADDRHINT
00088
00089 struct ip_pcb {
00090
00091 IP_PCB;
00092 };
00093
00094
00095
00096
00097
00098 #define SOF_ACCEPTCONN 0x02U
00099 #define SOF_REUSEADDR 0x04U
00100 #define SOF_KEEPALIVE 0x08U
00101
00102 #define SOF_BROADCAST 0x20U
00103
00104 #define SOF_LINGER 0x80U
00105
00106
00107
00108
00109 #define SOF_INHERITED (SOF_REUSEADDR|SOF_KEEPALIVE|SOF_LINGER)
00110
00111
00112 #ifdef PACK_STRUCT_USE_INCLUDES
00113 # include "arch/bpstruct.h"
00114 #endif
00115 PACK_STRUCT_BEGIN
00116 struct ip_hdr {
00117
00118 PACK_STRUCT_FIELD(u8_t _v_hl);
00119
00120 PACK_STRUCT_FIELD(u8_t _tos);
00121
00122 PACK_STRUCT_FIELD(u16_t _len);
00123
00124 PACK_STRUCT_FIELD(u16_t _id);
00125
00126 PACK_STRUCT_FIELD(u16_t _offset);
00127 #define IP_RF 0x8000U
00128 #define IP_DF 0x4000U
00129 #define IP_MF 0x2000U
00130 #define IP_OFFMASK 0x1fffU
00131
00132 PACK_STRUCT_FIELD(u8_t _ttl);
00133
00134 PACK_STRUCT_FIELD(u8_t _proto);
00135
00136 PACK_STRUCT_FIELD(u16_t _chksum);
00137
00138 PACK_STRUCT_FIELD(ip_addr_p_t src);
00139 PACK_STRUCT_FIELD(ip_addr_p_t dest);
00140 } PACK_STRUCT_STRUCT;
00141 PACK_STRUCT_END
00142 #ifdef PACK_STRUCT_USE_INCLUDES
00143 # include "arch/epstruct.h"
00144 #endif
00145
00146 #define IPH_V(hdr) ((hdr)->_v_hl >> 4)
00147 #define IPH_HL(hdr) ((hdr)->_v_hl & 0x0f)
00148 #define IPH_TOS(hdr) ((hdr)->_tos)
00149 #define IPH_LEN(hdr) ((hdr)->_len)
00150 #define IPH_ID(hdr) ((hdr)->_id)
00151 #define IPH_OFFSET(hdr) ((hdr)->_offset)
00152 #define IPH_TTL(hdr) ((hdr)->_ttl)
00153 #define IPH_PROTO(hdr) ((hdr)->_proto)
00154 #define IPH_CHKSUM(hdr) ((hdr)->_chksum)
00155
00156 #define IPH_VHL_SET(hdr, v, hl) (hdr)->_v_hl = (((v) << 4) | (hl))
00157 #define IPH_TOS_SET(hdr, tos) (hdr)->_tos = (tos)
00158 #define IPH_LEN_SET(hdr, len) (hdr)->_len = (len)
00159 #define IPH_ID_SET(hdr, id) (hdr)->_id = (id)
00160 #define IPH_OFFSET_SET(hdr, off) (hdr)->_offset = (off)
00161 #define IPH_TTL_SET(hdr, ttl) (hdr)->_ttl = (u8_t)(ttl)
00162 #define IPH_PROTO_SET(hdr, proto) (hdr)->_proto = (u8_t)(proto)
00163 #define IPH_CHKSUM_SET(hdr, chksum) (hdr)->_chksum = (chksum)
00164
00165
00166 extern struct netif *current_netif;
00167
00168 extern const struct ip_hdr *current_header;
00169
00170 extern ip_addr_t current_iphdr_src;
00171
00172 extern ip_addr_t current_iphdr_dest;
00173
00174 #define ip_init()
00175 struct netif *ip_route(ip_addr_t *dest);
00176 err_t ip_input(struct pbuf *p, struct netif *inp);
00177 err_t ip_output(struct pbuf *p, ip_addr_t *src, ip_addr_t *dest,
00178 u8_t ttl, u8_t tos, u8_t proto);
00179 err_t ip_output_if(struct pbuf *p, ip_addr_t *src, ip_addr_t *dest,
00180 u8_t ttl, u8_t tos, u8_t proto,
00181 struct netif *netif);
00182 #if LWIP_NETIF_HWADDRHINT
00183 err_t ip_output_hinted(struct pbuf *p, ip_addr_t *src, ip_addr_t *dest,
00184 u8_t ttl, u8_t tos, u8_t proto, u8_t *addr_hint);
00185 #endif
00186 #if IP_OPTIONS_SEND
00187 err_t ip_output_if_opt(struct pbuf *p, ip_addr_t *src, ip_addr_t *dest,
00188 u8_t ttl, u8_t tos, u8_t proto, struct netif *netif, void *ip_options,
00189 u16_t optlen);
00190 #endif
00191
00192
00193
00194 #define ip_current_netif() (current_netif)
00195
00196
00197
00198 #define ip_current_header() (current_header)
00199
00200 #define ip_current_src_addr() (¤t_iphdr_src)
00201
00202 #define ip_current_dest_addr() (¤t_iphdr_dest)
00203
00204
00205 #define ip_get_option(pcb, opt) ((pcb)->so_options & (opt))
00206
00207 #define ip_set_option(pcb, opt) ((pcb)->so_options |= (opt))
00208
00209 #define ip_reset_option(pcb, opt) ((pcb)->so_options &= ~(opt))
00210
00211 #if IP_DEBUG
00212 void ip_debug_print(struct pbuf *p);
00213 #else
00214 #define ip_debug_print(p)
00215 #endif
00216
00217 #ifdef __cplusplus
00218 }
00219 #endif
00220
00221 #endif
00222
00223