Solved

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

Posted on 2002-07-09
2
207 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
updating the repos in yum 4 114
what does "puppet agent -t" do ? 2 236
linux / python expert needed 3 93
looking for a CENTOS ISO to download with x window installed 2 39
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
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…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

809 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