Monday, August 17, 2009

get IP address in C under Linux

Today my work was to write a C code that gives the IP address of the system. For 2 hours, I searched on the internet to find if they are any predefined functions to do this. I didnot find anything useful. Then my friend Srikanth Parupati helped me solve my problem. He taught me to run shell commands from a C program. 'ifconfig' can be used at shell to get the info of the system and 'grep','cut' commands can be used on the ifconfig output to extract the IP address. If we want a C program to give out the IP, simply call this command from C using 'system'
Thanks Srikanth.

No comments:

Post a Comment