2

所以,我想通过使用 pcap_sendpacket 通过 TCP 发送数据包

TCP_Packet.Set_Ethernet_Source_MAC(1, 1, 1, 1, 1, 1);
TCP_Packet.Set_Ethernet_Destination_MAC(2, 2, 2, 2, 2, 2);
TCP_Packet.Set_Ethernet_Type(0x0800);
TCP_Packet.Set_IPv4_Version(4);
TCP_Packet.Set_IPv4_IHL(5);
TCP_Packet.Set_IPv4_ToS(0);
TCP_Packet.Set_IPv4_Total_Length(sizeof(IPv4_Address_s) + sizeof(TCP_s));
TCP_Packet.Set_IPv4_Identification(2);
TCP_Packet.Set_IPv4_Flag(0);
TCP_Packet.Set_IPv4_Offset(0);
TCP_Packet.Set_IPv4_Live_Time(0x80);
TCP_Packet.Set_IPv4_Protocol(0x06);
TCP_Packet.Set_IPv4_Checksum(0);
TCP_Packet.Set_IPv4_Destination_Address(192, 168, 1, 2);
TCP_Packet.Set_IPv4_Source_Address(192, 168, 1, 2);

TCP_Packet.Set_TCP_Destination_Port(45578); //In method is htons
TCP_Packet.Set_TCP_Source_Port(45578); //In method is htons
TCP_Packet.Set_TCP_Sequence_Number(0);
TCP_Packet.Set_TCP_Acknowledgment_Number(0);
TCP_Packet.Set_TCP_Flag_SYN(1);
TCP_Packet.Set_TCP_Offset(5);
TCP_Packet.Set_TCP_Window_Size(64240);
TCP_Packet.Set_TCP_Checksum(0);
TCP_Packet.Set_TCP_Urgent_Pointer(0);
if (FAILURE == TCP_Packet.Send_Packet(Capture_Instance)) //Here is all good
{
    cerr << "Can't send packet: " << pcap_geterr(Capture_Instance) << endl;
    return FAILURE;
}
else
    cout << "Sended" << endl;

问题:它似乎不起作用。服务器也没有检测到端口 45578 和wireshark 上的任何数据包,但它应该可以工作。

4

0 回答 0