LINUX programming

Moderators: ITA
Number of threads: 1347
Number of posts: 2935

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
How do I find out the IP address of the host? Posted by hvatum on 31 Oct 2007 at 12:29 AM
I just need to get the IP address of the machine that the program is running on, within C. I'm aware of the

gethostbyname(argv[1]);

Function, but this needs the host name. Basically I just need it to spit out the IP of the computer the program is running on. Of course I know one can easily run a program like ifconfig, but I want to quickly find the IP so I have it within my program, using a quick system call.

Thanks!
Report
Re: How do I find out the IP address of the host? Posted by ITA on 21 Jan 2008 at 6:19 AM
: I just need to get the IP address of the machine that the program is
: running on, within C. I'm aware of the
:
: gethostbyname(argv[1]);
:
: Function, but this needs the host name. Basically I just need it to
: spit out the IP of the computer the program is running on. Of course
: I know one can easily run a program like ifconfig, but I want to
: quickly find the IP so I have it within my program, using a quick
: system call.

You need to use the gethostname() system call.

--
Isaac
Report
Re: How do I find out the IP address of the host? Posted by hacker(wan) on 21 Jan 2008 at 10:07 PM
: : I just need to get the IP address of the machine that the program is
: : running on, within C. I'm aware of the
: :
: : gethostbyname(argv[1]);
: :
: : Function, but this needs the host name. Basically I just need it to
: : spit out the IP of the computer the program is running on. Of course
: : I know one can easily run a program like ifconfig, but I want to
: : quickly find the IP so I have it within my program, using a quick
: : system call.
:
: You need to use the gethostname() system call.
:
: --
: Isaac
u just tell ur teacher la..




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.