inettype.h
资源名称:SNMP范例源代码.zip [点击查看]
上传用户:shgx688
上传日期:2009-12-27
资源大小:855k
文件大小:4k
源码类别:
SNMP编程
开发平台:
MultiPlatform
- union w{
- unsigned long dwords;
- struct {unsigned int high;unsigned int low;}words;
- struct {unsigned char byte3;unsigned char byte2;unsigned char byte1;unsigned char byte0;}bytes;
- };
- union ethernet_address_type{
- unsigned int words[3];
- unsigned char bytes[6];
- };
- union ip_address_type{
- unsigned long dwords;
- unsigned int words[2];
- unsigned char bytes[4];
- };
- union arp_table_type{
- unsigned char bytes[12];
- unsigned int words[6];
- struct{
- unsigned char status;
- unsigned char ttl;
- union ip_address_type ip_address;
- union ethernet_address_type ethernet_address;
- }arp; //状态,生存时间,ip地址,以太网地址
- };
- //以太网帧
- struct ethernet{
- unsigned char status; //接收状态
- unsigned char nextpage; //下一个页
- unsigned int length; //以太网长度,以字节为单位
- unsigned int destnodeid[3]; //目的网卡地址
- unsigned int sourcenodeid[3]; //源网卡地址
- unsigned int protocal; //下一层协议
- unsigned char packet[1500]; //包的内容
- };
- //IP包 仅当IHL=5时用 当不=5时作转换
- struct ip{
- unsigned int head[9]; //以太网包头
- unsigned char verandihl; //版本与头长度
- unsigned char typeofserver; //服务类型
- unsigned int totallength; //总长度
- unsigned int frameindex; //IP帧序号
- unsigned int segment; //分段标志
- unsigned char ttl; //生存时间
- unsigned char protocal; //下一层协议
- unsigned int crc; //校验和
- unsigned int sourceip[2]; //源IP
- unsigned int destip[2]; //目的IP
- unsigned char packet[1484]; //IP包的内容
- };
- struct ippacket{
- unsigned int head[9]; //以太网包头
- unsigned int ippacket[750]; //IP包的内容
- };
- struct arp{
- unsigned int head[9]; //以太网头
- //arp报文的内容总长28字节
- unsigned int harewaretype; //以太网为0x0001
- unsigned int protocaltype; //ip 为0X0800
- unsigned char halength; //=0X06
- unsigned char palength; //=0X04
- unsigned int operation; //操作 0X0001为请求 0X0002为应答 0X0003为反向地址请求 0X0004为反向地址应答
- unsigned int sourcenodeid[3]; //源网卡地址
- unsigned int sourceip[2]; //源IP地址
- unsigned int destnodeid[3]; //目的网卡地址
- unsigned int destip[2]; //目的IP地址
- };
- struct icmp{ //包含在IP包中,是IP的上层为0X01的应用
- unsigned int head[9]; //以太网头
- unsigned int iphead[10]; //IP头
- unsigned char type; //0X08 PING请求 0X00 PING应答
- unsigned char option; //0X00 PING
- unsigned int crc;
- unsigned int id;
- unsigned int seq;
- unsigned char icmpdata[1472];
- };
- struct tcp{
- unsigned int head[9];
- unsigned int iphead[10];
- unsigned int sourceport; //源端口
- unsigned int destport; //目的端口
- unsigned long seqnumber; //顺序号
- unsigned long acknumber; //确认号
- unsigned char offset; //数据偏移量
- unsigned char control; //连接控制
- unsigned int window; //流控
- unsigned int crc; //校验和 ,包括伪头部,TCP头部,数据
- unsigned int urg; //紧急指针
- unsigned char tcpdata[1460]; //TCP数据
- };
- struct udp{
- unsigned int head[9];
- unsigned int iphead[10];
- unsigned int sourceport; //源端口
- unsigned int destport; //目的端口
- unsigned int length;
- unsigned int crc; //校验和 ,包括伪头部,udp头部,数据
- unsigned char udpdata[1472]; //udp数据
- };
- //所有协议的共用体
- union netcard{
- struct {unsigned char bytebuf[1536];}bytes;
- struct{ unsigned int wordbuf[768];}words;
- struct ethernet etherframe;
- struct arp arpframe;
- struct icmp icmpframe;
- struct tcp tcpframe;
- struct ip ipframe;
- struct udp udpframe;
- struct ippacket ippacket;
- };