I got those code snippets for reading the MAC address. Shouldn't be a great deal to change it to read the IP address. UCHAR is "unsigned char".
The first code snippet seems to be what you're looking for. The second one is writing it in a shell variable. Just here for completeness.
================================================
writing into C array
================================================
Code:
#define ENET_ADDR_SIZE 6
static int get_eth_mac_address( int eth_port )
{
FILE *get_mac;
char mac_string[ENET_ADDR_SIZE * 3 + 1];
// int i;
switch (eth_port)
{
case 0:
get_mac = popen("ifconfig eth0 | grep HWaddr | awk '{print $5}'", "r");
break;
case 2:
get_mac = popen("ifconfig eth2 | grep HWaddr | awk '{print $5}'", "r");
break;
default:
printf("Error: ethernet port not supported\n");
return -1;
}
printf("Reading MAC address from eth0\n");
while (fgets(mac_string, sizeof(mac_string), get_mac))
{
fprintf(stdout, "%s", mac_string);
}
Mac[0] = (UCHAR) strtol(&mac_string[0], NULL, 16);
Mac[1] = (UCHAR) strtol(&mac_string[3], NULL, 16);
Mac[2] = (UCHAR) strtol(&mac_string[6], NULL, 16);
Mac[3] = (UCHAR) strtol(&mac_string[9], NULL, 16);
Mac[4] = (UCHAR) strtol(&mac_string[12], NULL, 16);
Mac[5] = (UCHAR) strtol(&mac_string[15], NULL, 16);
/*
for (i=0; i < ENET_ADDR_SIZE; i++)
{
printf("%02x ", Mac[i]);
}
printf("\n");
*/
return 0;
}
================================================
writing into shell variable
================================================
Code:
printf("MAC address from eth2\n");
system("MAC_ETH2=`ifconfig eth2 | grep HWaddr | awk '{print $5}'`");
system("echo $MAC_ETH2");