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:
- Run as administrator;
- Check if my computer enabling
RAW socketby WSAEnumProtocols,netsh winsock show catalog, and I get some logs contain "MSAFD Tcpip [RAW/IP]" in description filed, so it is enabled, right? - Close all firewall;
- 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?