.C file for packet sniffer(socket)

Brothers,

Can any one help me to find the .c file written in c language that responsible for packet socket or packet capture ? Can any one tell me the path of this file ?
(.C file)

why not use tcpdump or wireshark ?

I need the .c file to see the way of programming, not to use program .

then it'd probably be in the linux kernel source.

and it's not really a openwrt question...

There is a firewall.conf that responsible for the roles of firewall, but I search on the .c file that the firewall depend on it in order to get the details of packet like source IP , source Port ..etc, so What is this file ?

https://git.netfilter.org/iptables

the conf file is probably parsed by a script/application, setting up the rules.

If you want to capture traffic, I suggest you look at the tcpdump source, since it's one of the tools capable of doing just that.

Or be specific about the use case, currently you're all over the place.

My case:
I want to find the .c file the responsible for packet capture like raw socket that make NATING
or FILTER like netfilter in order to make some changes on the code.

In other word, Networking in the Linux Kernel.
Can you tell me the path of this?

it's files in /net/ipv4/netfilter and /net/ipv6/netfilter in kernel source folder, for ipv4 and ipv6 type of firewall/network

1 Like

Please brother, Can you tell me more about the path in openwrt source code?

/openwrt/build_dir/target-x86_64_musl/linux-x86_64/linux-5.4.128/net/ipv4/netfilter
and
openwrt/build_dir/target-x86_64_musl/linux-x86_64/linux-5.4.128/net/ipv6/netfilter

for a x86_64 target and kernel version 5.4.xx (adjust that to your own target and kernel version)

That folder is deleted and re-created from original source package every time you rebuild, so if you want to make changes you must create a patch and integrate it in the OpenWrt buildsystem, see the instructions here

First, I installed the openwrt source code using: git clone https://git.openwrt.org/openwrt/openwrt.git

In this folder, I want to find /net/ipv4/netfilter , because I didn't find the build_dir

Openwrt source code is a "build system", it contains tools and makefiles to download and compile source code from many other projects.

The build_dir folder contains the files downloaded and compiled to assemble a firmware. It is created by the build system when it is running.

Compile a firmware for a device and the build_dir will be created and filled with files.
Then you can look in it and find the folder I said

1 Like