Link to home
Start Free TrialLog in
Avatar of mathematics
mathematics

asked on

How can we get the ip address like ifconfig using C program?

How can we get the ip address like ifconfig using C program?
The question is not the same as what I asked.
The Ip I got was not same as the ifconfig.
I beleive that using ifconfig can get the true ip address
and can ping the IP.
So gethostent(),gethostbyname(), maybe retrieve the ip
address from /etc/hosts,....
Can you help me to write a code like ifconfig
which is not use gethostent with reading /etc/hosts,
(Because /etc/hosts is wrong in my computer.)
 




Because I use rc.inet1 to set the IP of mycomputer,
These files /etc/hosts , /etc/hostname  was not corrected.
That is to say,for example ,
the ip /etc/hosts is 192.168.0.1,
but in the rc.inet1 192.168.0.3,
when using ifconfig , I find the eth0 is 192.168.0.3.
I used Slakware 7.0 distribution.
Avatar of dhanaspace1
dhanaspace1


some bad way & quick way
system ("ifconfig > /tmp/temp_file")
open the file
then strstr (buffer,"inet addr)
read the next token.
ASKER CERTIFIED SOLUTION
Avatar of bryanh
bryanh

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Split: bryanh {http:#7151625} & pianopan {http:#7213250}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jmcg
EE Cleanup Volunteer