- 1、本文档共16页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
网络ping--源代码(注有详细注释)(Network ping-- source code (note in detail))
网络ping--源代码(注有详细注释)(Network ping-- source code (note in detail))
头文件部分/ * * /
#包括 Winsock2。h // Windows下插座通信所必须的函数库
#包括 stdio. h / / C语言标准库
#包括时间。h //导入系统滴答计时器函数,为计算报文传输时间
#包括字符串。h //字符串处理函数库
#包括“平。H /用户自己的函数声明与数据结构体定义内容导入
#语用评论(库,“ws2_32”)
#定义cmd_param_help真实
#定义icmp_echo 8
#定义icmp_echoreply 0
#定义icmp_min 8 / 8字节的头最小
#定义max_packet 1024 / /最大ICMP包长度
#定义max_ip_hdr_size 60
typedef struct {头
unsigned int h_len:4;/ / 4位首部长度
unsigned int版本:4;/ / IP版本号,4表示IPv4
unsigned char TOS;/ / 8位服务类型TOS
无符号短total_len;/ / 16位总长度(字节)
无符号短识别;/ / 16位标识
无符号短frag_and_flags;/ / 3位标志位
unsigned char TTL;/ / 8位生存时间TTL
unsigned char原;/ / 8位协议(TCP,UDP或其他)
无符号短校验;/ / 16位IP首部校验和
unsigned int sourceip;/ / 32位源IP地址
unsigned int destip;/ / 32位目的IP地址
} IpHeader;
/ /定义ICMP首位
/ ************************************************
/ /主程序入口
************************************************ /
_ihdr { typedef struct
字节i_type;/ / 8位类型
字节i_code;/ / 8位代码
UShort i_cksum;/ / 16位校验和
UShort i_id;/ /识别号(一般用进程号作为识别号)
UShort i_seq;/ /报文序列号
同步时间戳;/ /时间戳
} IcmpHeader;
#定义status_failed 0xffff
#定义def_packet_size 32 / /包的大小
#定义max_packet 1024 / /最大ICMP包长度
#定义的xmalloc(S)(getprocessheap() HeapAlloc,heap_zero_memory,(S))
#定义Xfree heapfree(getprocessheap()(P),0,(P))
无效fill_icmp_data(char,int);/ /填补数据
UShort校验(UShort *,int);/ /校验数据
无效decode_resp(char,int,结构sockaddr_in *);
无效的使用(char * progname){
fprintf(stderr,”用法:\n”);//传送格式化数据
fprintf(stderr,“%s 主机 [ data_size ] \n”,progname);
fprintf(stderr,“DataSize可达1KB \n”);
是(status_failed);
}
int main(int argc、argv char *){ //初始化套接字
wsadata wsadata;
插座sockraw;
结构sockaddr_in dest,从;
结构hostent * HP;
int数据大小;/ /定义面包,面包,数据大小
国际fromlen = sizeof(从);
int超时= 1000;//等待每次回复的超时时间,默认1秒
char * dest_ip;/ /发送IP地址
char * icmp_data;
char * recvbuf;
unsigned int addr = 0;//初始化地址
UShort seq_no = 0;//序列号初始化
如果(WSAStartup(makeword(2,1),与wsadata)!= 0){ //初始化函数
fprintf(stderr,”WSAStartup失败:%d\n”,getlasterror());/ /设置显示
是(status_failed);/ /退出
}
如果(argc 2){ //残数个数小于2,即执行
使用(argv [ 0 ]);//调用函数argv
}
sockraw = wsas
您可能关注的文档
- 浅析我国企业所得税征管问题及策略(Problems and Strategies of enterprise income tax collection and management in China).doc
- 浅析最后一个匈奴(A brief analysis of the last Hun).doc
- 浅析监控系统传输线与使用(Analysis of transmission line and usage monitoring system).doc
- 浅埋公路隧道洞口段施工技术探讨(Discussion on construction technology of portal section of shallow buried highway tunnel).doc
- 浅析话语面面观结构主义到关联理论(A brief analysis of the Discourse, from the perspective of structuralism to relevance theory).doc
- 浅析非线性编辑系统在节目制作中所遇到的问题(Analysis of the problems encountered in the programming of non-linear editing system).doc
- 浅浅谈谈做品牌(Shallow talk do brand).doc
- 浅析项目组织边界管理(Analysis of project organization boundary management).doc
- 浅析我国会计环境的现状与改善途径(Analysis of the current situation of accounting environment in China and the ways to improve it).doc
- 浅议规范和改进我国金融业的对策(On Countermeasures for standardizing and improving China's financial industry).doc
- 网络丢包的原因以及解决办法(Causes of network packet loss and Solutions).doc
- 网络产品文字介绍(Network product text introduction).doc
- 网络交易税收征管模式的变革(Reform of tax collection and management model in network transaction).doc
- 网络基础学习之二》常见局域网拓扑及操作系统(Network basic learning two. Common local area network topology and operating system).doc
- 网络侵权问题浅析(Analysis of network infringement).doc
- 网络安全词汇新(New vocabulary of network security).doc
- 网络不是渠道,而是市场(The network is not the channel, but the market).doc
- 网络不通故障排查(Network troubleshooting).doc
- 网络故障浅析(Analysis of network fault).doc
- 网络新词1(Network neologism 1).doc
文档评论(0)