Click here to Skip to main content
11,638,173 members (76,995 online)
Click here to Skip to main content
Add your own
alternative version

Ping for Windows

, 15 Feb 2001 308.3K 15.5K 69
A simple Windows based ping program
// Ping.h

#pragma pack(1)

#define ICMP_ECHOREQ	8

class CPing
	HWND m_hWnd;
	void Ping(UINT nRetries,LPCSTR pstrHost,HWND hWnd);
	int  WaitForEchoReply(SOCKET s);
	// ICMP Echo Request/Reply functions
	int		SendEchoRequest(SOCKET, LPSOCKADDR_IN);
	DWORD	RecvEchoReply(SOCKET, LPSOCKADDR_IN, u_char *);
	u_short in_cksum(u_short *addr, int len);

	void WSAError(LPCSTR pstrFrom);


// IP Header -- RFC 791
typedef struct tagIPHDR
	u_char  VIHL;			// Version and IHL
	u_char	TOS;			// Type Of Service
	short	TotLen;			// Total Length
	short	ID;				// Identification
	short	FlagOff;		// Flags and Fragment Offset
	u_char	TTL;			// Time To Live
	u_char	Protocol;		// Protocol
	u_short	Checksum;		// Checksum
	struct	in_addr iaSrc;	// Internet Address - Source
	struct	in_addr iaDst;	// Internet Address - Destination

// ICMP Header - RFC 792
typedef struct tagICMPHDR
	u_char	Type;			// Type
	u_char	Code;			// Code
	u_short	Checksum;		// Checksum
	u_short	ID;				// Identification
	u_short	Seq;			// Sequence
	char	Data;			// Data

#define REQ_DATASIZE 32		// Echo Request Data size

// ICMP Echo Request
typedef struct tagECHOREQUEST
	ICMPHDR icmpHdr;
	DWORD	dwTime;
	char	cData[REQ_DATASIZE];

// ICMP Echo Reply
typedef struct tagECHOREPLY
	IPHDR	ipHdr;
	ECHOREQUEST	echoRequest;
	char    cFiller[256];

#pragma pack()

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Software Developer (Senior) Software Kinetics
United Kingdom United Kingdom

Software Kinetics
are experts in developing customised and bespoke applications and have expertise in the development of desktop, mobile and internet applications on Windows.

We specialise in:

  • User Interface Design
  • Desktop Development
  • Windows Phone Development
  • Windows Presentation Framework
  • Windows Forms
  • Windows Communication Framework
  • Windows Services
  • Network Applications
  • Database Applications
  • Web Development
  • Web Services
  • Silverlight

Visit Software Kinetics

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150728.1 | Last Updated 16 Feb 2001
Article Copyright 2000 by NormDroid
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid