您的位置:首页 > 其它

libiptc 例子 编译

2011-04-06 16:25 549 查看
参考 具体需要修改里面的代码,版本比较旧

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: