//Check the chain in the file /tmp/.ipt, whether it has already existed.
// return 1 (already existed) return 0 (not find)
#include <stdio.h>
#include <string.h>
int check_ipt_existed_chain(char *find_str)
{
FILE *fp;
char *find;
char buf_tmp[256] = "";
fp = fopen("./tmp/.ipt", "r");
if (fp == NULL)
{
printf("error\n");
return 0;
}
while(fgets(buf_tmp, sizeof(buf_tmp), fp) != NULL)
{
find = strstr(buf_tmp, find_str);
if(find != NULL)
{
return 1;
}
}
return 0;
}
int main()
{
int x;
x = check_ipt_existed_chain(":TR69_RULES");
printf("x:%d\n",x);
return 0;
}