How to get syn flags, ack flags, sequence number and acknowledgement number in tcp packets with nfqueue?

I am working on a project which can redirect the network traffic in tcp (packets sent by client to server1 will be redirected to server2) with netfilterqueue, so I need to classify the packets by their syn and ack flags, and I also needs to modify the sequence number and acknowledgement number in packets so that I can convince server2 to establish the connection with client. But I didn’t find the method to get the syn, ack flags and seq, acknowledgement number in tcp packets (not just show the packet information, but get the syn and ack flags, and seq, ack number to print and modify them), if anyone can help me, I would be grateful for that!

Answer

You need to parse the IP packet as included in the PAYLOAD attribute in the netlink message.

You can use kernel headers ip.h and tcp.h to parse the packets.

Attribution
Source : Link , Question Author : Alive , Answer Author : Tero Kilkanen

Leave a Comment