libiptc 例子 编译

参考 具体需要修改里面的代码,版本比较旧

http://tldp.org/HOWTO/Querying-libiptc-HOWTO/

 

下载iptables源代码,然后解压

./configure --prefix=/opt/iptables && make && make install

mkdir /opt/iptablesdev

cp -r include /opt/iptablesdev

cp -r /opt/iptables/lib /opt/iptablesdev

 

vim main.c

#include <getopt.h> #include <sys/errno.h> #include <stdio.h> #include <fcntl.h> #include <stdlib.h> #include <string.h> #include <dlfcn.h> #include <time.h> #include "libiptc/libiptc.h" #include "iptables.h" int main(void) { struct iptc_handle *h; const char *chain = NULL; const char *tablename = "filter"; //program_name = "p1"; //program_version = "1.2.3"; h = iptc_init(tablename); if ( !h ) { printf("Error initializing: %s/n", iptc_strerror(errno)); exit(errno); } for (chain = iptc_first_chain(h); chain; chain = iptc_next_chain(h)) { printf("%s/n", chain); } exit(0); }

 

vim Makefile

test: main.o
    g++ -o test main.o -L/opt/iptablesdev/lib -liptc

main.o: main.c
    gcc -g -c main.c -I/opt/iptablesdev/include

 

 

export LD_LIBRARY_PATH=/opt/iptablesdev/lib

 

./test

 

你可能感兴趣的:(struct,filter,vim,Path,include,library)