Hi,
imagine a TCP connection request (TH_SYN). I want to drop this packet (no problem). But I want to signal the originating application the failed request through a injected packet sending it to MSTcp. This would mean not just only to modify a packet, but to inject a totally converted packet in opposite direction. Would this work like this:
//
begin snippet pseudo code
// clear “send” flag -> turn this into a “receive”-packet
m_PacketBuffer.m_dwDeviceFlags &= ~PACKET_FLAG_ON_SEND;
// exchange source and destination (eth address)
ether_header_ptr pEth = _GetEtherHeader();
_exchange(pEth->h_dest, pEth->h_source);
// exchange source and destination (ip address)
iphdr_ptr pIp = _GetIpHeader();
_exchange(pIp->ip_dst, pIp->ip_src);
pIp->ip_hl = 5;
pIp->ip_v = 4;
pIp->ip_tos = 0;
pIp->ip_len = 10240;
pIp->ip_id = 6156;
pIp->ip_off = 0;
pIp->ip_ttl = 128;
pIp->ip_p = 6;
// exchange source and destination (port numbers)
tcphdr_ptr pTcp = _GetTcpHeader();
_exchange(pTcp->th_dport, pTcp->th_sport);
pTcp->th_flags = TH_RST | TH_ACK;
pTcp->th_ack = pTcp->th_seq+1;
pTcp->th_seq = 0;
pTcp->th_win = 0;
pTcp->th_x2 = 0;
pTcp->th_off = 5;
pTcp->th_urp = 0;
// recalc checksums
RecalculateIPChecksum();
RecalculateTCPChecksum();
// send this packet into opposite direction
pApi->SendPacketToMstcp(&m_Request);
//
end snippet pseudo code
My application won’t react on this packet. So I guess I’ve done something wrong converting this packet, or this won’t work generally. Any clue?
Thanks in advance!