I have a multidimensional array containing IP addresses and their corresponding Gateways. The structure of the array is shown below. I'd like to loop through the array and assign the first column of IP addresses to my network interface. I expect the interface to at some point to have several IP Addresses assigned to it. Later I intend to add a function to ping the gateways.
I can't seem to get the value of just the first column with which to use to execute my command. I'm sure I'm referencing the array incorrectly. Here's what I have so far.
char eth0IntName[256];
const char *arrayIPAddress[3][2]={
{"192.168.16.65", "192.168.16.66"},
{"192.168.17.65", "192.168.17.66"},
{"192.168.18.65", "192.168.18.66"}};
int main(int argc, char *argv[])
{
char cmdStr[256];
strcpy(eth0IntName, "eth0");
for(int i=0; i<3; i++)
{
sprintf(cmdStr, "/sbin/ip addr add %s/30 dev %s", (char *)&arrayIPAddress[i][0], eth0IntName);
printf("Executing: /sbin/ip addr add %s/30 dev %s", (char *)&arrayIPAddress[i][0], eth0IntName);
}
return 0;
}