| Visioscan Set SDK Libraries 1.0.28 Visioscan Set SDK Help documentation file for C++ and C++/CLI |

Loading...
Searching...
No Matches
DevicePinger.h
1#pragma once
2#include <winsock2.h>
3#include <ws2tcpip.h>
4#include <stdio.h>
5#include <stdlib.h>
6#include<string>;
7
8#include "iphdr.h"
9
10#ifdef STARFLEETTOOLBOX_EXPORTS
11#define ETHDEVICEPINGER __declspec(dllexport)
12#else
13#define ETHDEVICEPINGER __declspec(dllimport)
14#endif
15
16#define DEFAULT_DATA_SIZE 32 // default data size
17#define DEFAULT_SEND_COUNT 4 // number of ICMP requests to send
18#define DEFAULT_RECV_TIMEOUT 1000 // one second
19#define DEFAULT_TTL 128
20#define MAX_RECV_BUF_LEN 0xFFFF // Max incoming packet size.
21#define PING_SLEEP 250 // sleep between ping
22
23 using namespace std;
24
28 class ETHDEVICEPINGER DevicePinger
29{
30 public:
34 DevicePinger();
35
40 DevicePinger(string address);
41
47 DevicePinger(string address, int timeout);
48
53 void SetAddress(string address);
54
55
60 PING_RESULT Ping();
61
62
68 PING_RESULT Ping(int packetAmount);
69
70 private:
71 SOCKET _s = INVALID_SOCKET;
72 WSAOVERLAPPED _recvol;
73 char* _icmpbuf = NULL;
74 int _packetlen = 0;
75 int _receiveTimeOut = DEFAULT_RECV_TIMEOUT;
76 struct addrinfo* _dest = NULL;
77
78
79 int _addressFamily = AF_INET,
80 _protocol = IPPROTO_ICMP,
81 _ttl = DEFAULT_TTL;
82 int _dataSize = DEFAULT_DATA_SIZE;
83 BOOL _recordRoute = FALSE;
84 char* _destination = NULL,
85 _recvbuf[MAX_RECV_BUF_LEN];
86 int _recvbuflen = MAX_RECV_BUF_LEN;
87 char _lastKnownIp[100];
91 bool Initialize();
92
98 void InitIcmpHeader(char* buf, int datasize);
99
106 USHORT Checksum(USHORT* buffer, int size);
107
111 void SetIcmpSequence(char* buf);
112
125 void ComputeIcmpChecksum(SOCKET s, char* buf, int packetlen, struct addrinfo* dest);
126
137 int PostRecvfrom(SOCKET s, char* buf, int buflen, SOCKADDR* from, int* fromlen, WSAOVERLAPPED* ol);
138
145 int SetTtl(SOCKET s, int ttl);
146
159 struct addrinfo* ResolveAddress(char* addr, char* port, int af, int type, int proto);
160};
161
DevicePinger
The ETHERNET device pinger: a helper to allow sending ICMP packets to a host.
Definition DevicePinger.h:29
ping_result
Definition iphdr.h:5