Check if firewall is enabled in Linux library via C

I would like to know how I can check if the firewall is enabled in the C / C ++ library. Is there a library for this purpose? Thank.

+3
source share
3 answers

Here iptablesuses:

$ ldd /sbin/iptables
linux-vdso.so.1 =>  (0x00007fffa69fe000)
libip4tc.so.0 => /lib/libip4tc.so.0 (0x00007fe53853c000)
libip6tc.so.0 => /lib/libip6tc.so.0 (0x00007fe538334000)
libxtables.so.7 => /lib/libxtables.so.7 (0x00007fe538127000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fe537d67000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fe537b63000)
/lib64/ld-linux-x86-64.so.2 (0x00007fe53875d000)

As you can see, libip4tc, lipip6tcand libxtables. However, they are not very good for external interfaces. I suggest that you instead turn to iptables-saveand then process the machine-readable output.

+3
source

If you really want to do this with the C program, this may solve your goal :)

   chk_fw()
   {
      const char * cmd = "service iptables status";
      system(cmd);
   }

Output: iptables: Firewall is not running.

+2
source

iptables, . "libiptc" , .

+1

All Articles