Hi Codedv. Thank you for your help. Your code works.
The code is in C. There is no php code.
Below is the code where there is a \"$NIC_ADDRESS\".
If you issue the command iptables -L, you will see that port 10 did open.
char string1[100] = "iptables -A INPUT -i \"$NIC_ADDRESS\" -p tcp --dport 10 -j ACCEPT";
fp = popen (string1, "r"); <-- THIS CODE RUN
-----------------------------------------------------------
On the second code, it did not work with \"$SRCADDR\"/\"$SRCMASK\" because there is a / between the two variable.
\"$SRCADDR\" and \"$SRCMASK\"
fp_ETH0 = popen ("iptables -t nat -A OUTPUT -p tcp -d \"$SRCADDR\"/\"$SRCMASK\" -j ACCEPT", "r");
==========================================
Code:
#include <stdio.h> /* standard library. a minimum */
#include <stdlib.h> /* for oct_long = strtoul (six_oct_char, NULL, 8) */
#include <string.h> /* for strcmp, strcpy functions */
start_processes()
{
char NIC_ADDRESS[16] = "216.143.22.145";
char string1[100] = "iptables -A INPUT -i \"$NIC_ADDRESS\" -p tcp --dport 10 -j ACCEPT";
FILE *fp;
FILE *fp_ETH0;
char SRCADDR[16] = "216.143.22.145";
char SRCMASK[16] = "255.255.255.0";
/* THE CODE BELOW WORKS IF THE CODE char NIC_ADDRESS[16] = "216.143.22.145" IS DECLARED */
fp = popen (string1, "r");
/* THE CODE BELOW DID NOT WORK */
FILE *fp_ETH0;
char SRCADDR[16] = "216.143.22.145";
char SRCMASK[16] = "255.255.255.0";
fp_ETH0 = popen ("iptables -t nat -A OUTPUT -p tcp -d \"$SRCADDR\"/\"$SRCMASK\" -j ACCEPT", "r");
}
/*******************************************/
main()
{
start_processes();
}