教程学院
图像设计 多媒体类 机械制图 办公软件 操作系统 系统编程 网站编程 网页制作 数据库类 网络路由 网络工程 网络安全 考试认证
酷网学院
CAD
AutoCad Cam350 ProEngineer GCcam MATLAB Unigraphics SolidWorks CAXA Solid3000 Cimatron EdgeCAM
系统
安全 防火墙 病毒 WinXP Win2003 Vista
数据库
编程
网络
  网站导航: 库库中文网 · 系统编程教程 · VC语言 · VC实例分析  

ping地源程序

教程推荐
『ping地源程序』如果文章有大量图片,显示会较慢,请等待图片下载完成
 
点击数: 更新时间:2005-3-28 
/ Module Name: Ping.c
//
// Description:
// This sample illustrates how an ICMP ping app can be written
// using the SOCK_RAW socket type and IPPROTO_ICMP protocol.
// By creating a raw socket, the underlying layer does not change
// the protocol header so that when we submit the ICMP header
// nothing is changed so that the receiving end will see an
// ICMP packet. Additionally, we use the record route IP option
// to get a round trip path to the endpoint. Note that the size
// of the IP option header that records the route is limited to
// nine IP addresses.
//
// Compile:
// cl -o Ping Ping.c ws2_32.lib /Zp1
//
// Command Line Options/Parameters:
// Ping [host] [packet-size]
//
// host String name of host to ping
// packet-size Integer size of packet to send
// (smaller than 1024 bytes)
//
//#pragma pack(1)

#define WIN32_LEAN_AND_MEAN
#include
#include
#include
#include

#define IP_RECORD_ROUTE 0x7
//
// IP header structure
//
typedef struct _iphdr
{
unsigned int h_len:4; // Length of the header
unsigned int version:4; // Version of IP
unsigned char tos; // Type of service
unsigned short total_len; // Total length of the packet
unsigned short ident; // Unique identifier
unsigned short frag_and_flags; // Flags
unsigned char ttl; // Time to live
unsigned char proto; // Protocol (TCP, UDP etc)
unsigned short checksum; // IP checksum

unsigned int sourceIP;
unsigned int destIP;
} IpHeader;

#define ICMP_ECHO 8
#define ICMP_ECHOREPLY 0
#define ICMP_MIN 8 // Minimum 8-byte ICMP packet (header)

//
// ICMP header structure
//
typedef struct _icmphdr
{
BYTE i_type;
BYTE i_code; // Type sub code
USHORT i_cksum;
USHORT i_id;
USHORT i_seq;
// This is not the standard header, but we reserve space for time
ULONG timestamp;
} IcmpHeader;

//
// IP option header - use with socket option IP_OPTIONS
//
typedef struct _ipoptionhdr
{
unsigned char code; // Option type
unsigned char len; // Length of option hdr
unsigned char ptr; // Offset into options
unsigned long addr[9]; // List of IP addrs
} IpOptionHeader;

#define DEF_PACKET_SIZE 32 // Default packet size
#define MAX_PACKET 1024 // Max ICMP packet size
#define MAX_IP_HDR_SIZE 60 // Max IP header size w/options

BOOL bRecordRoute;
int datasize;
char *lpdest;

//
// Function: usage
//
// Description:
// Print usage information
//
void usage(char *progname)
{
printf("usage: ping -r [data size]\n");
printf(" -r record route\n");
printf(" host remote machine to ping\n");
printf(" datasize can be up to 1KB\n");
ExitProcess(-1);
}

//
// Function: FillICMPData
//
// Description:
// Helper function to fill in various fields for our ICMP request
//
void FillICMPData(char *icmp_data, int datasize)
{
IcmpHeader *icmp_hdr = NULL;
char *datapart = NULL;

icmp_hdr = (IcmpHeader*)icmp_data;
icmp_hdr->i_type = ICMP_ECHO; // Request an ICMP echo
icmp_hdr->i_code = 0;
icmp_hdr->i_id = (USHORT)GetCurrentProcessId();
icmp_hdr->i_c

[1] [2] [3] [4] 下一页

】【关闭窗口
  上一页:
  下一页:
 ·网站导航: 库库中文网 · 系统编程教程 · VC语言 · VC实例分析
VC实例分析:相关文章
VC实例分析点击榜
普通教程编制程序高手 实际示例解释分析
普通教程HOOK API示例
普通教程VC开发的软件中对CHM帮助文档的
普通教程向其余进程注入代码地三种办法(
普通教程仅通过崩溃地址找出源代码地出错
普通教程Visual C#设计3D游戏框架示例
普通教程P2P地简略示例(VB.net版)
普通教程一个CTreeView与CListView联合与
普通教程基于Visual C++ 6.0地Add-in编制
普通教程实际示例演练ASP+XML编制程序
PHOTOSHOP - 基础教程 抠图专题 蒙版专题 3DsMax 基础 设计实例 Maya设计实例
3D设计教程
advertisement
关于站点 - 广告服务 - 联系我们 - 版权隐私 - 免责声明 - 合作伙伴 - 程序支持 - 网站地图 - 返回顶部
网站文本地图
版权所有:库库中文 2005-2007 欢迎各种媒体转载我们的原创作品[转载请注明出处]
copyright ? 2005-2008 www.QQGB.com online services. all rights reserved. 蜀ICP备05015578
Optimized for 1024x768 to Firefox,Opera and MS-IE6. Site powered by EQL. 电脑硬件 电脑知识 教程学习
红盾
热爱电脑,热爱生活
拥有电脑,拥有生命
让我们享受拥有电脑的时光