91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 8KB
    文件類型: .cpp
    金幣: 1
    下載: 0 次
    發布日期: 2021-06-10
  • 語言: C/C++
  • 標簽: winsockping??

資源簡介

我的作業 需要寫作業的可以參考

資源截圖

代碼片段和文件信息

/*
?*?Renkai_ping.cpp
?*
?*??Created?on:?2012-5-19
?*??????Author:?renkai
?*/
#include?
#include?
#include?
#include?“winsock2.h“
#include?“stdlib.h“
#include?“stdio.h“
#include?
using?namespace?std;

#define?ICMP_ECHO?8
#define?ICMP_ECHOREPLY?0
#define?ICMP_MIN?8???????//Minimum?8-byte?ICMP?packet
//IP首部數據結構
typedef?struct?iphdr
{
??unsigned?int?h_len?:4;?//首部長度
??unsigned?int?version?:4;?//版本
??unsigned?char?tos;?//服務類型
??unsigned?short?total_len;?//報文總長度
??unsigned?short?ident;?//標識
??unsigned?short?frag_and_flags;?//偏移量
??unsigned?char?ttl;?//壽命
??unsigned?char?proto;?//協議
??unsigned?short?checksum;?//?首部校驗和
??unsigned?int?sourceIP;?//?源站IP
??unsigned?int?destIP;?//?目的站IP
}?IpHeader;

//ICMP首部數據結構
typedef?struct?icmphdr
{
??BYTE?i_type;?//類型
??BYTE?i_code;?//代碼
??USHORT?i_cksum;?//首部校驗和
??USHORT?i_id;?//標識
??USHORT?i_seq;?//序列號
??ULONG?timestamp;?//時間戳
}?IcmpHeader;

#define?STATUS_FAILED?0xFFFF
#define?DEF_PACKET_SIZE????32???//默認發送包的長度
#define?DEF_PACKET_NUMBER??6???//默認發送包的數量
#define?MAX_PACKET?1024???????//最大ICMP發送包的長度
void
fill_icmp_data(char*?int?int);?//填充ICMP報頭
USHORT
checksum(USHORT*?int);?//計算ICMP首部校驗和
int
decode_resp(char*?int?struct?sockaddr_in*);?//解析收到的數據包

int?main(int?argcchar*?argv[])
{
??if?(argc?==?1)
????{
??????cout?<??????cout?<??????cout?<??????????<??????return?-1;
????}

??USHORT?seq_no=0;
??int?ts=0statistic=0;
??int?breaddatasize=32packnum=6;
??setbuf(stdoutNULL);
??WORD?wVersionRequested;
??WSADATA?wsaData;
??int?timeout=1000;
??//處理參數
??for?(int?j?=?1;?j?????{
??????int?temp;
??????temp?=?strcmp(argv[j]?“-n“);
??????if?(temp?==?0)
????????{
??????????j++;
??????????packnum?=?atoi(argv[j]);
??????????cout?<??????????continue;
????????}

??????temp?=?strcmp(argv[j]?“-l“);
??????if?(temp?==?0)
????????{
??????????j++;
??????????datasize?=?atoi(argv[j]);
??????????cout?<??????????continue;
????????}

??????temp?=?strcmp(argv[j]?“-w“);
??????if?(temp?==?0)
????????{
??????????j++;
??????????timeout?=?atoi(argv[j]);
??????????cout?<??????????continue;
????????}

??????temp?=?strcmp(argv[j]?“-s“);
??????if?(temp?==?0)
????????{
??????????j++;
??????????ts?=?atoi(argv[j]);
??????????cout?<??????????continue;
????????}

????}

??if?(packnum?<=?0)
????{
??????cout?<??????return?-1;
????}

??if?(datasize??1024)
????{
??????cout?<??????return?-1;
????}

??if?(timeout??10000)
???

評論

共有 條評論

相關資源