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