read and write files

read and write files

    FILE *fpin = NULL;
    FILE *fpout = NULL;
    char str1[512] = {0};
    char str2[512] = {0};
    system("iptables-save >/tmp/.currentipt");          
    fpin = fopen(IPTABLES_CURRENT_FILE,"r") ;
    fpout = fopen(IPTABLES_MINIUPNPD_FILE,"w+");    
    if(fpin !=NULL && fpout !=NULL)
    {
        while(fgets(str1,512,fpin) != NULL)
        {
            if(strncmp(str1,"-A MINIUPNPD",strlen("-A MINIUPNPD")) == 0)
            {
                strcpy(str2,str1);
                cprintf("[%s_%d]###str2:%s\n", __FUNCTION__, __LINE__,str2);
                fprintf(fpout,"%s",str2);                   
            }
            else
                continue;   
        }
        fclose(fpin);
        fclose(fpout);
    }       

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325882953&siteId=291194637