I need to display all the IP addresses from my local computer, using the C language. How can this be done?
$ sudo ifconfig | grep 'inet addr' | cut -d':' -f2 | cut -d' ' -f1 213.xx.xxx.xx 192.168.xx.x 127.0.0.1
And you can put that into popen():
/* not tested */
ph = popen("sudo ifconfig | grep 'inet addr' | cut -d':' -f2 | cut -d' ' -f1", "r");
while (fgets(buf, sizeof buf, ph)) {
/* ip address, in nul-terminated string format, is in `buf` */
}
pclose(ph);