`sendto` failed with 10022 error code when sending raw packets on Win10-x64

27 Views Asked by At

I'm developing application for scanning opening ports with libtins, but I got error (10022 - WSAEINVAL) when sending raw packet. Here is my minimal test code, which will print Send failed immediately meaning no response(just because WSAEINVAL error happens inside libtins):

void sendSynPacket()
{
  Tins::PacketSender sender;
  Tins::IP pkt = Tins::IP(IPv4Address("172.18.0.3")) / Tins::TCP(20001, 30000);

  pkt.rfind_pdu<Tins::TCP>().set_flag(Tins::TCP::SYN, 1);
  std::unique_ptr<Tins::PDU> response(sender.send_recv(pkt));
  if(response)
  {
    if(response->rfind_pdu<Tins::TCP>().flags() == (Tins::TCP::SYN|Tins::TCP::ACK))
      std::cout << "open " << std::endl;
    else
      std::cout << "close " << std::endl;
  }
  else
    std::cout << "Send failed" << std::endl;
}

System info:

Edition Windows 11 Pro
Version 22H2
Installed on    ‎11/‎21/‎2023
OS build    22621.2715
Experience  Windows Feature Experience Pack 1000.22677.1000.0

Besides, destination ip("172.18.0.3") and port(20001) is known opening port and reachable. and I have searched a lot and find no solutions, like this question . I find some important things related to my problem, like:

  1. Run as administrator;
  2. Check if my computer enabling RAW socket by WSAEnumProtocols,netsh winsock show catalog, and I get some logs contain "MSAFD Tcpip [RAW/IP]" in description filed, so it is enabled, right?
  3. Close all firewall;
  4. Check source codes within libtins, no obvious incorrect codes found

What did I missed? Or just because my platform doesn't support raw socket, if so, is there any way to make work done on my laptop?

0

There are 0 best solutions below