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
00033
00034
00035
00036
00037
00038 #ifndef __LWIP_IP_H__
00039 #define __LWIP_IP_H__
00040
00041 #include "lwip/arch.h"
00042
00043 #include "lwip/def.h"
00044 #include "lwip/pbuf.h"
00045 #include "lwip/ip_addr.h"
00046
00047 #include "lwip/err.h"
00048
00049 struct netif;
00050
00051 void ip_init(void);
00052 u8_t ip_lookup(void *header, struct netif *inp);
00053 struct netif *ip_route(struct ip_addr *dest);
00054 err_t ip_input(struct pbuf *p, struct netif *inp);
00055 err_t ip_output(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
00056 u8_t ttl, u8_t proto);
00057 err_t ip_output_if(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
00058 u8_t ttl, u8_t proto,
00059 struct netif *netif);
00060
00061 #define IP_HLEN 20
00062
00063 #define IP_PROTO_ICMP 1
00064 #define IP_PROTO_UDP 17
00065 #define IP_PROTO_UDPLITE 170
00066 #define IP_PROTO_TCP 6
00067
00068
00069
00070
00071 #ifdef IP_HDRINCL
00072 #undef IP_HDRINCL
00073 #endif
00074 #define IP_HDRINCL NULL
00075
00076 #ifdef PACK_STRUCT_USE_INCLUDES
00077 # include "arch/bpstruct.h"
00078 #endif
00079 PACK_STRUCT_BEGIN
00080 struct ip_hdr {
00081
00082 PACK_STRUCT_FIELD(u16_t _v_hl_tos);
00083
00084 PACK_STRUCT_FIELD(u16_t _len);
00085
00086 PACK_STRUCT_FIELD(u16_t _id);
00087
00088 PACK_STRUCT_FIELD(u16_t _offset);
00089 #define IP_RF 0x8000
00090 #define IP_DF 0x4000
00091 #define IP_MF 0x2000
00092 #define IP_OFFMASK 0x1fff
00093
00094 PACK_STRUCT_FIELD(u16_t _ttl_proto);
00095
00096 PACK_STRUCT_FIELD(u16_t _chksum);
00097
00098 PACK_STRUCT_FIELD(struct ip_addr src);
00099 PACK_STRUCT_FIELD(struct ip_addr dest);
00100 } PACK_STRUCT_STRUCT;
00101 PACK_STRUCT_END
00102 #ifdef PACK_STRUCT_USE_INCLUDES
00103 # include "arch/epstruct.h"
00104 #endif
00105
00106 #define IPH_V(hdr) (ntohs((hdr)->_v_hl_tos) >> 12)
00107 #define IPH_HL(hdr) ((ntohs((hdr)->_v_hl_tos) >> 8) & 0x0f)
00108 #define IPH_TOS(hdr) (htons((ntohs((hdr)->_v_hl_tos) & 0xff)))
00109 #define IPH_LEN(hdr) ((hdr)->_len)
00110 #define IPH_ID(hdr) ((hdr)->_id)
00111 #define IPH_OFFSET(hdr) ((hdr)->_offset)
00112 #define IPH_TTL(hdr) (ntohs((hdr)->_ttl_proto) >> 8)
00113 #define IPH_PROTO(hdr) (ntohs((hdr)->_ttl_proto) & 0xff)
00114 #define IPH_CHKSUM(hdr) ((hdr)->_chksum)
00115
00116 #define IPH_VHLTOS_SET(hdr, v, hl, tos) (hdr)->_v_hl_tos = (htons(((v) << 12) | ((hl) << 8) | (tos)))
00117 #define IPH_LEN_SET(hdr, len) (hdr)->_len = (len)
00118 #define IPH_ID_SET(hdr, id) (hdr)->_id = (id)
00119 #define IPH_OFFSET_SET(hdr, off) (hdr)->_offset = (off)
00120 #define IPH_TTL_SET(hdr, ttl) (hdr)->_ttl_proto = (htons(IPH_PROTO(hdr) | ((ttl) << 8)))
00121 #define IPH_PROTO_SET(hdr, proto) (hdr)->_ttl_proto = (htons((proto) | (IPH_TTL(hdr) << 8)))
00122 #define IPH_CHKSUM_SET(hdr, chksum) (hdr)->_chksum = (chksum)
00123
00124 #if IP_DEBUG
00125 void ip_debug_print(struct pbuf *p);
00126 #endif
00127
00128 #endif
00129
00130