Dialysis ICMP protocol (3): One of the initial tests of the cow knife PING (ICMP.DLL)

zhaozj2021-02-16  43

Dialysis ICMP protocol (3): One of the initial tests of the cow knife PING (ICMP.DLL) =============================== This article is from: http://tangentsoft.net/wskfaq/examples/dllping.html Translation: Bugfree / 9CBS, add some comment on the original code: VC6 Windows XP

Principle: -------- This example demonstrates the application of Microsoft's ICMP.dll € "ping" another machine. This DLL is the send ICMP return package API interface without documentation, also known as "Pings, "Just like the diver is the same as the terminology of the sonar signal. This code comes from a Gui program called Markg, his webpage has disappeared.

ICMP.dll API is now working with Microsoft Winsocks on the Windows platform, but Microsoft said that better products come out and they will replace it. Microsoft said this is in Windows 95 era, these features are in Windows 2000 still exists.

For more information on the icmp.dll api, check out sockets.com's ICMP API Page. Information to the ICMP API page of Sockets.com is available.

Specific implementation: -------- // Borland C 5.0: bcc32.cpp ping.cpp // Visual C 5.0: CL ping.cpp wsock32.lib //// this sample program is hereby placed in public domain .

#include #include #include #include "icmpdefs.h"

================== ping implementation part =========================== Int DOIT (int Argc, char * argv [ ]) {// [bugfree] Recommended this ARGC and Argv's processing to the main function // check the command line parameter IF (Argc <2) {CERR << "usage: ping << end1; return 1;} // Load ICMP.DLL connection library Hinstance HiCMP = LoadLibrary ("icmp.dll"); if (hiCMP == 0) {CERR << "Unable to locate icmp.dll!" << endl; return 2; }

/ / Find the IP address information of a given machine Struct Hostent * Phe; if ((PHE = gethostByname) == 0) {CERR << "Could Not Find IP Address for" << argv [1] << Endl; Return 3;} // Define Function Three Pointer Type TypeDef Handle (WinApi * PfnHV) (VOID); TypeDef Bool (WinAPI * PFNBH) (Handlef DWORD (WinApi * PfndHdpWPPDD) (Handle, DWord) , LPVOID, WORD, PIP_OPTION_INFORMATION, LPVOID, DWORD, DWORD); // evil, no // pointer to the function defined three pfnHV pIcmpCreateFile;? pfnBH pIcmpCloseHandle; pfnDHDPWPipPDD pIcmpSendEcho; // pIcmpCreateFile function entry address obtained from the ICMP.DLL = ( pfnHV) GetProcAddress (hIcmp, "IcmpCreateFile"); pIcmpCloseHandle = (pfnBH) GetProcAddress (hIcmp, "IcmpCloseHandle"); pIcmpSendEcho = (pfnDHDPWPipPDD) GetProcAddress (hIcmp, "IcmpSendEcho"); if ((pIcmpCreateFile == 0) || ( PicmpCloseHandle == 0) || (PICMPSENDECHO == 0)) {CERR << "Failed to get proc addr for function." << endl; return 4;

// Open the service handle HIP = PICMPCreateFile (); if (hip == invalid_handle_value) {CERR << "Unable to open service." << endl; return 5;} // Constructing ping data package char ACPINGBUFFER [64] ; memset (acPingBuffer, '/ xAA', sizeof (acPingBuffer)); PIP_ECHO_REPLY pIpe = (PIP_ECHO_REPLY) GlobalAlloc (GMEM_FIXED | GMEM_ZEROINIT, sizeof (IP_ECHO_REPLY) sizeof (acPingBuffer)); if (pIpe == 0) {cerr << "Failed to Allocate Global Ping Ping Packet Buffer." << Endl; Return 6;} Pipe-> Data = ACPINGBUFFER; PIPE-> DATASIZE = SIZEOF (ACPINGBUFFER);

// send ping packet DWORD dwStatus = pIcmpSendEcho (hIP, * ((DWORD *) phe-> h_addr_list [0]), acPingBuffer, sizeof (acPingBuffer), NULL, pIpe, sizeof (IP_ECHO_REPLY) sizeof (acPingBuffer), 5000 ); If (dwstatus! = 0) {cout << "addr: << int (LOBYTE (LOBYTE (LOBYTE (LOWORD (Pipe-> Address)) <<" << Int (Hibyte (Pipe-> Address) << "<<") << "<<")) << "<<")) << "<<") <<< "<<") <<< "<<") <<<<.com RTT: "<< INTTRIPTIME) <<" MS, "<<" TTL: "INT (Pipe-> Options.ttl) << Endl;} else {CERR <<" Error Obtaining Info from O Ping packet. "<< Endl;} // Off, recycled resources GlobalFree (PIPE); FreeELBRARY (HICMP); return 0;} ================== Primitive = ================= Int main (int Argc, char * argv []) {wsadata wsadata; if (WsaStartup (MakeWord (1, 1), & WSADATA)! = 0) {RETURN 255;

int RetVal = DOIT (ARGC, ARGV);

Washnup (); return retval;}

================== header file ================== ketmpdefs.h // ICMP.dll function is required structure

typedef struct {unsigned char Ttl; // Time To Live unsigned char Tos; // Type Of Service unsigned char Flags; // IP header flags unsigned char OptionsSize; // Size in bytes of options data unsigned char * OptionsData; // Pointer to options data} IP_OPTION_INFORMATION, * PIP_OPTION_INFORMATION; typedef struct {DWORD address; // Replying address unsigned long Status; // Reply status unsigned long RoundTripTime; // RTT in milliseconds unsigned short DataSize; // Echo data size unsigned short Reserved; / / Reserved for system use void * data; // pointer to the echo data ip_option_information option // reply options} ip_echo_reply, * pip_echo_reply

Link: ------- My other article, << dialysis ICMP protocol >>, and other articles see: http://www.9cbs.net/develop/author/netauthor/bugfree/

Contact: ------- zhangliangsd@hotmail.com

转载请注明原文地址:https://www.9cbs.com/read-24462.html

New Post(0)