Click here to Skip to main content
15,868,161 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more: , +
I catch my packets on router using packet sniffer, then I want to use c-code to filter these packets according to port number, IP address ... etc.

(Not I want to use only c language).

What I have tried:

I catch the packets using packet sniffer.
Posted
Updated 9-Nov-21 6:14am
Comments
Dave Kreskowiak 9-Nov-21 10:37am    
The terms "simple code" and "packet filtering" should never be used in the same sentence.

So what did you use to capture the traffic?
Shao Voon Wong 11-Nov-21 1:46am    
Follow these links for packet capturing. Filter them on your own after capturing.
For Linux, libpcap: https://www.tcpdump.org/
For Windows, WinPCAP: https://www.winpcap.org/ or https://nmap.org/npcap/

1 solution

Than it is a very simple packet filter. The first problem is to acquire the packets for sniffing and than tell the decision to the driver and after that you can write a simple function like:
C++
BOOL acceptPacketFromPort(int port) {
  return port == 42;
}
Maybe you should strart with some tcpdump tutorial. Sometimes a batch help to solve "simple" problems.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900