Solved

How can we get the ip of my computer using C program?

Posted on 2002-07-09
2
205 Views
Last Modified: 2010-04-22
How can we get the IP of my computer using C program?
Please tell me the sample code by C.
0
Comment
Question by:mathematics
2 Comments
 
LVL 10

Accepted Solution

by:
makerp earned 50 total points
ID: 7140673
you will need to include the socket headers and link to the sockets library, this uses stl, so include <string> aswell

string get_ip_address_from_host_name(string host_name)
{
     string retval;
     struct hostent *host;
     struct sockaddr_in addr;
     if((host = gethostbyname(host_name.c_str())) != NULL)          
     {
          memcpy((char*)&addr.sin_addr,host->h_addr,host->h_length);
          retval = inet_ntoa(addr.sin_addr);
     }
     return retval;
}
0
 

Author Comment

by:mathematics
ID: 7142237
Thank you very much,makerp.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now