int PingSend(void)
来源:互联网 发布:135端口 编辑:程序博客网 时间:2024/05/16 07:09
int PingSend(void)
{
static uchar mac[6];
volatile IP_t *ip;
volatile ushort *s;
uchar *pkt;
/* XXX always send arp request */
memcpy(mac, NetEtherNullAddr, 6); //mac={0,0,0,0,0,0}
#ifdef ET_DEBUG
printf("sending ARP for %08lx\n", NetPingIP);
#endif
NetArpWaitPacketIP = NetPingIP; //目标ip
NetArpWaitPacketMAC = mac; //目标mac=0
pkt = NetArpWaitTxPacket; //指向NetArpWaitTxPacket
pkt += NetSetEther(pkt, mac, PROT_IP); //设置帧头(目标mac,本机mac,协议)目标mac=0
ip = (volatile IP_t *)pkt;
/*
* Construct an IP and ICMP header. (need to set no fragment bit - XXX)
*/
ip->ip_hl_v = 0x45; /* IP_HDR_SIZE / 4 (not including UDP) */ //协议版本4,协议头=5个字
ip->ip_tos = 0; //数据报优先级=0
ip->ip_len = htons(IP_HDR_SIZE_NO_UDP + 8); //数据报长度
ip->ip_id = htons(NetIPID++); //数据报编号
ip->ip_off = htons(0x4000); /* No fragmentation */ //分片设置
ip->ip_ttl = 255; //数据报寿命
ip->ip_p = 0x01; /* ICMP */ //上层协议是ICMP
ip->ip_sum = 0; //首部校验和暂设为0
NetCopyIP((void*)&ip->ip_src, &NetOurIP); /* already in network byte order */ //本机ip地址
NetCopyIP((void*)&ip->ip_dst, &NetPingIP); /* - "" - */ //目标ip地址
ip->ip_sum = ~NetCksum((uchar *)ip, IP_HDR_SIZE_NO_UDP / 2); //首部校验和计算
s = &ip->udp_src; /* XXX ICMP starts here */
s[0] = htons(0x0800); /* echo-request, code */
s[1] = 0; /* checksum */
s[2] = 0; /* identifier */
s[3] = htons(PingSeqNo++); /* sequence number */
s[1] = ~NetCksum((uchar *)s, 8/2);
/* size of the waiting packet */
NetArpWaitTxPacketSize = (pkt - NetArpWaitTxPacket) + IP_HDR_SIZE_NO_UDP + 8; //ARP等待的数据报的长度
/* and do the ARP request */
NetArpWaitTry = 1; //重试次数
NetArpWaitTimerStart = get_timer(0); //获取当前时间
ArpRequest();
return 1; /* waiting */
}
{
static uchar mac[6];
volatile IP_t *ip;
volatile ushort *s;
uchar *pkt;
/* XXX always send arp request */
memcpy(mac, NetEtherNullAddr, 6); //mac={0,0,0,0,0,0}
#ifdef ET_DEBUG
printf("sending ARP for %08lx\n", NetPingIP);
#endif
NetArpWaitPacketIP = NetPingIP; //目标ip
NetArpWaitPacketMAC = mac; //目标mac=0
pkt = NetArpWaitTxPacket; //指向NetArpWaitTxPacket
pkt += NetSetEther(pkt, mac, PROT_IP); //设置帧头(目标mac,本机mac,协议)目标mac=0
ip = (volatile IP_t *)pkt;
/*
* Construct an IP and ICMP header. (need to set no fragment bit - XXX)
*/
ip->ip_hl_v = 0x45; /* IP_HDR_SIZE / 4 (not including UDP) */ //协议版本4,协议头=5个字
ip->ip_tos = 0; //数据报优先级=0
ip->ip_len = htons(IP_HDR_SIZE_NO_UDP + 8); //数据报长度
ip->ip_id = htons(NetIPID++); //数据报编号
ip->ip_off = htons(0x4000); /* No fragmentation */ //分片设置
ip->ip_ttl = 255; //数据报寿命
ip->ip_p = 0x01; /* ICMP */ //上层协议是ICMP
ip->ip_sum = 0; //首部校验和暂设为0
NetCopyIP((void*)&ip->ip_src, &NetOurIP); /* already in network byte order */ //本机ip地址
NetCopyIP((void*)&ip->ip_dst, &NetPingIP); /* - "" - */ //目标ip地址
ip->ip_sum = ~NetCksum((uchar *)ip, IP_HDR_SIZE_NO_UDP / 2); //首部校验和计算
s = &ip->udp_src; /* XXX ICMP starts here */
s[0] = htons(0x0800); /* echo-request, code */
s[1] = 0; /* checksum */
s[2] = 0; /* identifier */
s[3] = htons(PingSeqNo++); /* sequence number */
s[1] = ~NetCksum((uchar *)s, 8/2);
/* size of the waiting packet */
NetArpWaitTxPacketSize = (pkt - NetArpWaitTxPacket) + IP_HDR_SIZE_NO_UDP + 8; //ARP等待的数据报的长度
/* and do the ARP request */
NetArpWaitTry = 1; //重试次数
NetArpWaitTimerStart = get_timer(0); //获取当前时间
ArpRequest();
return 1; /* waiting */
}
- int PingSend(void)
- void (*f(int, void (*)(int)))(int)
- void (*Pfun(int, void(*Qfun)(int))) (int)
- 理解(*(void(*)())0)()和void (*signal(int, void(*)(int)))(int)
- void (*func)(int)和void (*func)(void)
- int main (void)
- int getchar(void);
- void assert (int expression)
- typedef int (init_fnc_t) (void);
- void assert( int expression );
- void simLoop(int pause)
- typedef int(init_fnc_t) (void);
- int getpid(void)
- type void func(int)
- void (*f(int, void (*)(int)))(int) 函数解析
- void (*f(int, void (*)(int)))(int) 函数解析
- void (*signal(int sig, void (*func) (int))) (int)理解
- signal函数:void (*signal(int,void(*)(int)))(int);
- 学习Oracle需要掌握的重要知识点
- Red Hat Linux下软件的基本安装和卸载
- error while loading shared libraries
- Qt多线程同步总结 .
- devstack中rabbitmq-server启动失败
- int PingSend(void)
- 错误80004005(未指定的错误)错误行conn.open connstr
- 拼接满足条件的Id串付给变量
- BZOJ 1001 狼抓兔子(最大流-对偶图最短路)
- shiro(1)-简介
- QT线程(一):线程类
- etl工具使用
- Android网络间接——HttpURLConnection.getResponseCode() 错误
- Populating Next Right Pointers in Each Node