Re: C code rule modifying

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Ok im trying to add the rule to a table named charz, here is the code :

char *command;
        FILE *fp = popen("/sbin/iptables",'w');
        if (fp==NULL){
        printf("\nerror opening pipe\n");
        return -1;
        }else{
        sprintf(command,"-A charz -p tcp --dport %s --source %s -j
%s\0",port,currentIp,action2);
        printf("\n\n\n%s\n\n\n",command);
        fwrite(command,strlen(command),1,fp);
        pclose(fp);


that is all...
commenting out the popen code and just printing command gives out
folowing output:

-A charz -p tcp --dport 22 --source 10.0.1.197 -j ACCEPT


thank you for your answer

ps: this is just a sample of the code, since there are pcap modules
and crypto modules also.
On Tue, Apr 22, 2008 at 6:12 PM, Jan Engelhardt <jengelh@xxxxxxxxxxxxxxx> wrote:
>
>  On Tuesday 2008-04-22 00:05, Charles Romestant wrote:
>
>  >Hello, anyone happen to have some C sample code to modify existing
>  >ruleset, can t seem to get it to work with
>  >popen ( get segfault) even running as root.
>
>  Uh, if you get a segfault with a simple popen, there's likely
>  a bug in your code. (Suggestion to post the offending lines.)
>



-- 
Charz
--
To unsubscribe from this list: send the line "unsubscribe netfilter" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Netfilter Development]     [Linux Kernel Networking Development]     [Netem]     [Berkeley Packet Filter]     [Linux Kernel Development]     [Advanced Routing & Traffice Control]     [Bugtraq]

  Powered by Linux