Any way to change the behavior of the synchronous Windows API SendArP?

I am writing a local network scanner in Windows to find online hosts with IP assistants, which is equivalent to nmap -PR , but without WinPcap. I know SendARP will block and send an ARP request 3 times if the remote host does not respond, so I use std::aync to create one thread for each of them, but the problem is that I want to send an ARP request every 20 ms. so that there are not too many ARP packets in a very short time.

 #include <iostream> #include <future> #include <vector> #include <winsock2.h> #include <iphlpapi.h> #pragma comment(lib, "iphlpapi.lib") #pragma comment(lib, "ws2_32.lib") using namespace std; int main(int argc, char **argv) { ULONG MacAddr[2]; /* for 6-byte hardware addresses */ ULONG PhysAddrLen = 6; /* default to length of six bytes */ memset(&MacAddr, 0xff, sizeof (MacAddr)); PhysAddrLen = 6; IPAddr SrcIp = 0; IPAddr DestIp = 0; char buf[64] = {0}; size_t start = time(NULL); std::vector<std::future<DWORD> > vResults; for (auto i = 1; i< 255; i++) { sprintf(buf, "192.168.1.%d", i); DestIp = inet_addr(buf); vResults.push_back(std::async(std::launch::async, std::ref(SendARP), DestIp, SrcIp, MacAddr, &PhysAddrLen)); Sleep(20); } for (auto it= vResults.begin(); it != vResults.end(); ++it) { if (it->get() == NO_ERROR) { std::cout<<"host up\n"; } } std::cout<<"time elapsed "<<(time(NULL) - start)<<std::endl; return 0; } 

First, I can do this by calling Sleep(20) after the thread starts, but one day SendARP in these threads will resend the ARP requests, if there are no responses from the remote host, this is out of my control and I see a lot of requests in a very short time (< 10ms) in Wireshark, so my question is:

  • Any way to make SendARP asynchronous?
  • If not, can I control SendARP send SendARP in streams?
+8
c ++ multithreading asynchronous winapi arp
source share

No one has answered this question yet.

See similar questions:

sixteen
ARP request and response using c-socket programming

or similar:

696
Is there a way to kill a thread?
nine
Getting synchronous behavior in javascript?
8
Asynchronous io in c using the Windows API: which method to use and why is my code running synchronously?
7
Is there a way to call Windows Native API functions from user mode?
3
Is there a way to synchronize processes that account for failures?
0
Best way to implement synchronous and asynchronous behavior in client code?
0
An efficient way to synchronously and asynchronously behave in an application
0
Force the Async task to stop from the main thread
-one
MessageQueue synchronization using the Windows API

All Articles