📄 ip.h
字号:
/***********************************************************************//* *//* Module: tcp_ip/ip/ip.h *//* Release: 2001.3 *//* Version: 99.0 *//* Purpose: IP Private Header File *//* *//*---------------------------------------------------------------------*//* *//* Copyright 1999, Blunk Microsystems *//* ALL RIGHTS RESERVED *//* *//* Licensees have the non-exclusive right to use, modify, or extract *//* this computer program for software development at a single site. *//* This program may be resold or disseminated in executable format *//* only. The source code may not be redistributed or resold. *//* *//***********************************************************************//***********************************************************************//* Symbol Definitions *//***********************************************************************//*** Route Flags*/#define RT_BRDCST (1 << 0)#define RT_GATEWAY (1 << 1)/*** Protocol Numbers*/#define IPT_ICMP 1 /* protocol type for ICMP packets */#define IPT_IGMP 2 /* protocol type for IGMP packets */#define IPT_TCP 6 /* protocol type for TCP packets */#define IPT_EGP 8 /* protocol type for EGP packets */#define IPT_UDP 17 /* protocol type for UDP packets *//*** IP Header Constants*/#define IP_VERSION 4 /* current version value */#define IP_MAXOPT 40 /* largest option field, bytes */#define IP_MF 0x2000 /* more fragments bit */#define IP_DF 0x4000 /* don't fragment bit */#define IP_FRAGOFF 0x1FFF /* fragment offset mask */#define IP_PREC 0xE0 /* precedence portion of TOS *//*** IP Options*/#define IPO_COPY 0x80 /* copy on fragment mask */#define IPO_CLASS 0x60 /* option class */#define IPO_NUM 0x1F /* option number */#define IPO_EOOP 0x00 /* end of options */#define IPO_NOP 0x01 /* no operation */#define IPO_SEC 0x82 /* DoD security/compartmentalization */#define IPO_LSRCRT 0x83 /* loose source routing */#define IPO_SSRCRT 0x89 /* strict source routing */#define IPO_RECRT 0x07 /* record route */#define IPO_STRID 0x88 /* stream ID */#define IPO_TIME 0x44 /* internet timestamp *//*** ICMP Code Field*/#define ICC_NETUR 0 /* dest unreachable, net unreachable */#define ICC_HOSTUR 1 /* dest unreachable, host unreachable */#define ICC_PROTOUR 2 /* dest unreachable, proto unreachable */#define ICC_PORTUR 3 /* dest unreachable, port unreachable */#define ICC_FRAGREQ 4 /* dest unr, frag needed & don't frag */#define ICC_SRCRT 5 /* dest unreachable, src route failed */#define ICC_NETUNK 6 /* dest unreachable, dest network unknown */#define ICC_HOSTUNK 7 /* dest unreachable, dest host unknown */#define ICC_NETTYP 11 /* dest unr, network service type unreachable */#define ICC_HOSTTYP 12 /* dest unr, host service type unreachable */#define ICC_COMMPRO 13 /* dest unreachable, communication prohibited */#define ICC_PRECVIO 14 /* dest unreachable, host precedence violation */#define ICC_PRECCUT 15 /* dest unreachable, precedence cutoff */#define ICC_NETRD 0 /* redirect: net */#define ICC_HOSTRD 1 /* redirect: host */#define IC_TOSNRD 2 /* redirect: type of service, net */#define IC_TOSHRD 3 /* redirect: type of service, host */#define ICC_TIMEX 0 /* time exceeded, ttl */#define ICC_FTIMEX 1 /* time exceeded, frag *//***********************************************************************//* Macro Definitions *//***********************************************************************//*** IP header length macro must work on possibly unaligned segments*/#define IP_HLEN(ip) \ (((((ui8 *)(ip))[offsetof(Ip, ver_len)]) & 0xF) << 2)/***********************************************************************//* Type Definitions *//***********************************************************************//*** IP Packet Structure*/typedef struct ip{ ui8 ver_len; /* IP version & header length (in longs) */ ui8 ip_tos; /* type of service */ ui16 length; /* total packet length (in bytes) */ ui16 ip_id; /* datagram id */ ui16 frag_off; /* fragment offset (in 8-octet's) */ ui8 ttl; /* time to live, in gateway hops */ ui8 protocol; /* IP protocol */ ui16 checksum; /* header checksum */ ui32 src_ip; /* IP address of source */ ui32 dst_ip; /* IP address of destination */ ui8 options[IP_MAXOPT]; /* variable length options */} Ip;/*** Routing Table Entry Structure*/struct route{ ui32 addr; /* network or host address */ ui32 mask; /* mask for this route */ ui32 gw; /* next IP hop */ Ni *ni; /* pointer to network interface structure */ struct route *next; /* next entry for this hash value */ ui8 key; /* sort key (number of 1's) */ ui16 flags; /* RT_BRDCST, etc. */};/***********************************************************************//* Function Prototypes *//***********************************************************************/ui16 IpChecksum(void *src, uint len);void IpSend(const Route *route, NetBuf *buf, int datalen, ui8 tos);void IpOut(void *object);ui32 IpNetMask(ui32 net);ui32 IpSubnetMask(ui32 net);void IpLocalIn(void);/*** Fragmentation related*/int IpJoinFrag(void);void IpFragInit(void);/*** Routing related*/void RtInit(void);int RtAdd(ui32 gw, ui32 mask, ui32 addr, Ni *ni, int flags);int RtDel(ui32 gw, ui32 mask, ui32 addr);void RtDump(void);void NiRtDel(Ni *ni);Route *RtSearch(ui32 dest);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -