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

📄 ip.h

📁 SimpleGraphicOperatingSystem 32位图形化操作系统 多进程 支持FAT32 详见www.sgos.net.cn
💻 H
字号:
#ifndef IP_H_INCLUDED
#define IP_H_INCLUDED

#include <Type.h>

//! IP version 4.
#define IP_V4			4
//! IP version 6.
#define IP_V6			6

//! Maximum IP frame length.
#define IP_FRAME_LEN		65535
//! Minimum IP header length.
#define IP_HEAD_MIN_LEN		20
//! Default TTL (Time To Live).
#define IP_DEFAULT_TTL		64

//! Generic IP packet type.
#define IPPROTO_IP		0
//! ICMP (Internet Control Message Protocol) packet type.
#define IPPROTO_ICMP		1
//! IGMP (Internet Group Message Protocol) packet type.
#define IPPROTO_IGMP		2
//! TCP (Transmition Control Protocol) packet type.
#define IPPROTO_TCP		6
//! UDP (User Datagram Protocol) packet type.
#define IPPROTO_UDP		17

//! Type of service :: Minimum delay.
#define IP_TOS_MIN_DELAY	0x10
//! Type of service :: Maximum throughput.
#define IP_TOS_MAX_THRU		0x08
//! Type of service :: Maximum rely.
#define IP_TOS_MAX_RELY		0x04
//! Type of service :: Minimum cost.
#define IP_TOS_MIN_COST		0x02

// Fragment flags							//
//! More Fragments.
#define IP_FLAG_MF		0x2000
//! Don't Fragment.
#define IP_FLAG_DF		0x4000
//! The CE flag.
#define IP_FLAG_CE		0x8000
//! The flag mask.
#define IP_FLAG_MASK		0x1FFF

//! Create an IP address in the binary network format
//! from the notation "a.b.c.d".
#define IP_ADDRESS(a, b, c, d)	((a) | (b) << 8 | (c) << 16 | (d) << 24)
//! Get the 1st most significant byte of a host-format IP address.
#define IP_A(ip)		((t_8) ((ip) >> 24))
//! Get the 2nd most significant byte of a host-format IP address.
#define IP_B(ip)		((t_8) ((ip) >> 16))
//! Get the 3rd most significant byte of a host-format IP address.
#define IP_C(ip)		((t_8) ((ip) >>  8))
//! Get the less significant byte of a host-format IP address.
#define IP_D(ip)		((t_8) ((ip) >>  0))

//! Loopback IP address.
#define INADDR_LOOPBACK		IP_ADDRESS(127, 0, 0, 1)
//! Null IP address.
#define INADDR_ANY		IP_ADDRESS(0, 0, 0, 0)
//! Broadcast IP address.
#define INADDR_BROADCAST	IP_ADDRESS(255, 255, 255, 255)

//! The IP packet structure.
typedef struct _IPPacket
{
#if __BYTE_ORDER__ == __LITTLE_ENDIAN__
	t_8 headerLength:4;	//!< The header length.
	t_8 version:4;	//!< The IP version.
#else
	t_8 version:4;	//!< The IP version.
	t_8 headerLength:4;	//!< The IP header length.
#endif
	//! Type of Service.
	//! bits0~2:priority bit3: Delay  4:Throughput 5:Reliability
	t_8 serviceType;
	//! IP packet length (both data and header).
	t_16 length;

	//! Identification.
	t_16 id;
	//! Fragment offset. 片偏移
	t_16 offset;

	//! Time To Live.
	t_8 ttl;
	//! The type of the upper-level protocol.
	t_8 protocol;
	//! IP header checksum.
	t_16 checksum;

	//! IP source address (in network format).
	t_32 source;
	//! IP destination address (in network format).
	t_32 destination;
} __attribute__ ((packed)) IPPacket, *PIPPacket;

#endif // IP_H_INCLUDED

⌨️ 快捷键说明

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