iptables c++ control

c++, firewall, linux, networking

Solution

An year back I was having the same requirement and probed around. But after contacting some open source kernel guys this is what I came to know -

The kernel APIs of iptables are not externalised, means to say, they are not documented APIs. In the sense, the APIs can change any moment. They should be used only by the iptables tool. they should not be used by the application developers.

-satish

Problem

I need to control inbound and outbound traffic to/from a linux box from within a C++ program. I could call `iptables` from within my program, but I'd much rather cut out the middle man and access the kernel API functions myself. I believe I need to use libnfnetlink, however, I have not been able to find any API documentation or example programs. The rules I need to construct are fairly simple - things like dropping packets with a destination port equal to X etc. I do NOT intend to write a full firewall application. can anyone suggest a better approach, or provide a link to some documentation or example apps? I'd rather avoid reading the iptables code, but i guess I may have to, if I can't find any better resources.

Original source

Related problems