⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ip.h

📁 M5,一个功能强大的多处理器系统模拟器.很多针对处理器架构,性能的研究都使用它作为模拟平台
💻 H
📖 第 1 页 / 共 2 页
字号:
#define IP_OPT_NOP	  1			/* no operation */#define IP_OPT_SEC	 (2|IP_OPT_COPY)	/* DoD basic security */#define IP_OPT_LSRR	 (3|IP_OPT_COPY)	/* loose source route */#define IP_OPT_TS	 (4|IP_OPT_DEBMEAS)	/* timestamp */#define IP_OPT_ESEC	 (5|IP_OPT_COPY)	/* DoD extended security */#define IP_OPT_CIPSO	 (6|IP_OPT_COPY)	/* commercial security */#define IP_OPT_RR	  7			/* record route */#define IP_OPT_SATID	 (8|IP_OPT_COPY)	/* stream ID (obsolete) */#define IP_OPT_SSRR	 (9|IP_OPT_COPY)	/* strict source route */#define IP_OPT_ZSU	 10			/* experimental measurement */#define IP_OPT_MTUP	 11			/* MTU probe */#define IP_OPT_MTUR	 12			/* MTU reply */#define IP_OPT_FINN	(13|IP_OPT_COPY|IP_OPT_DEBMEAS)	/* exp flow control */#define IP_OPT_VISA	(14|IP_OPT_COPY)	/* exp access control */#define IP_OPT_ENCODE	 15			/* ??? */#define IP_OPT_IMITD	(16|IP_OPT_COPY)	/* IMI traffic descriptor */#define IP_OPT_EIP	(17|IP_OPT_COPY)	/* extended IP, RFC 1385 */#define IP_OPT_TR	(18|IP_OPT_DEBMEAS)	/* traceroute */#define IP_OPT_ADDEXT	(19|IP_OPT_COPY)	/* IPv7 ext addr, RFC 1475 */#define IP_OPT_RTRALT	(20|IP_OPT_COPY)	/* router alert, RFC 2113 */#define IP_OPT_SDB	(21|IP_OPT_COPY)	/* directed bcast, RFC 1770 */#define IP_OPT_NSAPA	(22|IP_OPT_COPY)	/* NSAP addresses */#define IP_OPT_DPS	(23|IP_OPT_COPY)	/* dynamic packet state */#define IP_OPT_UMP	(24|IP_OPT_COPY)	/* upstream multicast */#define IP_OPT_MAX	 25#define IP_OPT_COPIED(o)	((o) & 0x80)#define IP_OPT_CLASS(o)		((o) & 0x60)#define IP_OPT_NUMBER(o)	((o) & 0x1f)#define IP_OPT_TYPEONLY(o)	((o) == IP_OPT_EOL || (o) == IP_OPT_NOP)/* * Security option data - RFC 791, 3.1 */struct ip_opt_data_sec {        uint16_t	s;		/* security */        uint16_t	c;		/* compartments */        uint16_t	h;		/* handling restrictions */        uint8_t		tcc[3];		/* transmission control code */} __attribute__((__packed__));#define IP_OPT_SEC_UNCLASS	0x0000	/* unclassified */#define IP_OPT_SEC_CONFID	0xf135	/* confidential */#define IP_OPT_SEC_EFTO		0x789a	/* EFTO */#define IP_OPT_SEC_MMMM		0xbc4d	/* MMMM */#define IP_OPT_SEC_PROG		0x5e26	/* PROG */#define IP_OPT_SEC_RESTR	0xaf13	/* restricted */#define IP_OPT_SEC_SECRET	0xd788	/* secret */#define IP_OPT_SEC_TOPSECRET	0x6bc5	/* top secret *//* * {Loose Source, Record, Strict Source} Route option data - RFC 791, 3.1 */struct ip_opt_data_rr {        uint8_t		ptr;		/* from start of option, >= 4 */        uint32_t	iplist __flexarr; /* list of IP addresses */} __attribute__((__packed__));/* * Timestamp option data - RFC 791, 3.1 */struct ip_opt_data_ts {        uint8_t		ptr;		/* from start of option, >= 5 */#if DNET_BYTESEX == DNET_BIG_ENDIAN        uint8_t		oflw:4,		/* number of IPs skipped */                        flg:4;		/* address[ / timestamp] flag */#elif DNET_BYTESEX == DNET_LIL_ENDIAN        uint8_t		flg:4,                        oflw:4;#endif        uint32_t	ipts __flexarr;	/* IP address [/ timestamp] pairs */} __attribute__((__packed__));#define IP_OPT_TS_TSONLY	0	/* timestamps only */#define IP_OPT_TS_TSADDR	1	/* IP address / timestamp pairs */#define IP_OPT_TS_PRESPEC	3	/* IP address / zero timestamp pairs *//* * Traceroute option data - RFC 1393, 2.2 */struct ip_opt_data_tr {        uint16_t	id;		/* ID number */        uint16_t	ohc;		/* outbound hop count */        uint16_t	rhc;		/* return hop count */        uint32_t	origip;		/* originator IP address */} __attribute__((__packed__));/* * IP option (following IP header) */struct ip_opt {        uint8_t		opt_type;	/* option type */        uint8_t		opt_len;	/* option length >= IP_OPT_LEN */        union ip_opt_data {                struct ip_opt_data_sec	sec;	   /* IP_OPT_SEC */                struct ip_opt_data_rr	rr;	   /* IP_OPT_{L,S}RR */                struct ip_opt_data_ts	ts;	   /* IP_OPT_TS */                uint16_t		satid;	   /* IP_OPT_SATID */                uint16_t		mtu;	   /* IP_OPT_MTU{P,R} */                struct ip_opt_data_tr	tr;	   /* IP_OPT_TR */                uint32_t		addext[2]; /* IP_OPT_ADDEXT */                uint16_t		rtralt;    /* IP_OPT_RTRALT */                uint32_t		sdb[9];    /* IP_OPT_SDB */                uint8_t			data8[IP_OPT_LEN_MAX - IP_OPT_LEN];        } opt_data;} __attribute__((__packed__));#ifndef __GNUC__# pragma pack()#endif/* * Classful addressing */#define	IP_CLASSA(i)		(((uint32_t)(i) & htonl(0x80000000)) == \                                 htonl(0x00000000))#define	IP_CLASSA_NET		(htonl(0xff000000))#define	IP_CLASSA_NSHIFT	24#define	IP_CLASSA_HOST		(htonl(0x00ffffff))#define	IP_CLASSA_MAX		128#define	IP_CLASSB(i)		(((uint32_t)(i) & htonl(0xc0000000)) == \                                 htonl(0x80000000))#define	IP_CLASSB_NET		(htonl(0xffff0000))#define	IP_CLASSB_NSHIFT	16#define	IP_CLASSB_HOST		(htonl(0x0000ffff))#define	IP_CLASSB_MAX		65536#define	IP_CLASSC(i)		(((uint32_t)(i) & htonl(0xe0000000)) == \                                 htonl(0xc0000000))#define	IP_CLASSC_NET		(htonl(0xffffff00))#define	IP_CLASSC_NSHIFT	8#define	IP_CLASSC_HOST		(htonl(0x000000ff))#define	IP_CLASSD(i)		(((uint32_t)(i) & htonl(0xf0000000)) == \                                 htonl(0xe0000000))/* These ones aren't really net and host fields, but routing needn't know. */#define	IP_CLASSD_NET		(htonl(0xf0000000))#define	IP_CLASSD_NSHIFT	28#define	IP_CLASSD_HOST		(htonl(0x0fffffff))#define	IP_MULTICAST(i)		IP_CLASSD(i)#define	IP_EXPERIMENTAL(i)	(((uint32_t)(i) & htonl(0xf0000000)) == \                                 htonl(0xf0000000))#define	IP_BADCLASS(i)		(((uint32_t)(i) & htonl(0xf0000000)) == \                                 htonl(0xf0000000))#define	IP_LOCAL_GROUP(i)	(((uint32_t)(i) & htonl(0xffffff00)) == \                                 htonl(0xe0000000))/* * Reserved addresses */#define IP_ADDR_ANY		(htonl(0x00000000))	/* 0.0.0.0 */#define IP_ADDR_BROADCAST	(htonl(0xffffffff))	/* 255.255.255.255 */#define IP_ADDR_LOOPBACK	(htonl(0x7f000001))	/* 127.0.0.1 */#define IP_ADDR_MCAST_ALL	(htonl(0xe0000001))	/* 224.0.0.1 */#define IP_ADDR_MCAST_LOCAL	(htonl(0xe00000ff))	/* 224.0.0.225 */#define ip_pack_hdr(hdr, tos, len, id, off, ttl, p, src, dst) do {	\        struct ip_hdr *ip_pack_p = (struct ip_hdr *)(hdr);		\        ip_pack_p->ip_v = 4; ip_pack_p->ip_hl = 5;			\        ip_pack_p->ip_tos = tos; ip_pack_p->ip_len = htons(len);	\        ip_pack_p->ip_id = htons(id); ip_pack_p->ip_off = htons(off);	\        ip_pack_p->ip_ttl = ttl; ip_pack_p->ip_p = p;			\        ip_pack_p->ip_src = src; ip_pack_p->ip_dst = dst;		\} while (0)typedef struct ip_handle ip_t;__BEGIN_DECLSip_t	*ip_open(void);size_t	 ip_send(ip_t *i, const void *buf, size_t len);ip_t	*ip_close(ip_t *i);char	*ip_ntop(const ip_addr_t *ip, char *dst, size_t len);int	 ip_pton(const char *src, ip_addr_t *dst);char	*ip_ntoa(const ip_addr_t *ip);#define	 ip_aton ip_ptonsize_t	 ip_add_option(void *buf, size_t len,            int proto, const void *optbuf, size_t optlen);void	 ip_checksum(void *buf, size_t len);inline intip_cksum_add(const void *buf, size_t len, int cksum){        uint16_t *sp = (uint16_t *)buf;        int n, sn;        sn = len / 2;        n = (sn + 15) / 16;        /* XXX - unroll loop using Duff's device. */        switch (sn % 16) {        case 0:	do {                cksum += *sp++;        case 15:                cksum += *sp++;        case 14:                cksum += *sp++;        case 13:                cksum += *sp++;        case 12:                cksum += *sp++;        case 11:                cksum += *sp++;        case 10:                cksum += *sp++;        case 9:                cksum += *sp++;        case 8:                cksum += *sp++;        case 7:                cksum += *sp++;        case 6:                cksum += *sp++;        case 5:                cksum += *sp++;        case 4:                cksum += *sp++;        case 3:                cksum += *sp++;        case 2:                cksum += *sp++;        case 1:                cksum += *sp++;                } while (--n > 0);        }        if (len & 1)                cksum += htons(*(u_char *)sp << 8);        return (cksum);}inline uint16_tip_cksum_carry(int x){        x = (x >> 16) + (x & 0xffff);        return ~(x + (x >> 16)) & 0xffff;}__END_DECLS#endif /* DNET_IP_H */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -