473,399 Members | 2,478 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

problem in getting host ip using gethostbyname() and hstent structure

i am making an application for fetching the IP address from the domain name using the hostent structure i am able to insert all the data in the structure successfully and i am able to fetch the
Host Name:
Type:
Length:
but not able to fetch the IP address in the dotted format using by the below function

int get_ip()
{
int i;

const char *hostname="www.google.co.in";
struct hostent **he;
struct hostent *VAL;
he= (struct hostent**)malloc(sizeof(struct hostent));
write_at("Success",7,1,1);
SVC_WAIT(2000);
i = gethostbyname(hostname,he);
if (i==0)
{
char buff[50]={'\0'};
clrscr();
write_at("Success",7,6,4);
SVC_WAIT(2000);
//sprintf(buff,"Type: %d Length: %d", (*he)->h_addrtype,(*he)->h_length);
sprintf(buff,"Type: %s", (*he)->h_addr);
write_at(buff,strlen(buff),1,2);
SVC_WAIT(3000);
}
else
{
clrscr();
write_at("fail",4,1,1);
SVC_WAIT(2000);
}

return 0;

}

STRUCTURE:
struct hostent
{
char * h_name; /* Official name of host. */
char **h_aliases; /* Alias list. */
int h_addrtype; /* Host address type. */
int h_length; /* Length of address. */
char **h_addr_list; /* List of addresses from name server. */
#define h_addr h_addr_list[0] /* Address, for backward compatibility. */
};


but the output is not the expected. output is not readable.


please help me.
thanks in advance
Aug 6 '14 #1
0 966

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Punit | last post by:
Hi, Could someone please suggest where I am going wrong... Iam using MSXML 3.0 and VC++ but i end up getting blank response XML try { hr =...
1
by: Darrel Yurychuk | last post by:
I'm having a problem getting the window.onresize to work properly. Here is a simple test case I wrote: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">...
0
by: ree32 | last post by:
Is there one using a tree structure to collapse nodes, while editing. What I had in mind was something similar to Visual Studio.net where you can collapse functions to make it easier to read. So...
6
by: Brian Henry | last post by:
is there a way to get the host name of someone? like mine is 68-23-123-123-pitt-pa.adelphia.net? Request.UserHostName doesn't seem to return the host name like it states in the documentation,...
5
by: Tom | last post by:
I have a function that restricts access to a page to logged in users. When a user who isn't logged in goes to the page, it will dynamically generate a login form. I'm trying to use it in...
0
by: cty | last post by:
Title: Problem in session using php5 Good day, I use php5+mySQL4+IIS5.x Previuosly i use php4 and no error occur,
1
by: simbarashe | last post by:
Hie could someone please help me with getting and using the current page url. I have a function that gets the url, I want to use it with header(location : XXX) but it wont work. The code is as...
3
by: DaveoB | last post by:
Hey Im wonderin if anyone can help me with this question,Sum the odd numbers between 1 and 97, using a for structure. Might seem a bit simple but i cant get it to work. Anyone help?
1
by: =?Utf-8?B?RGFydGgtQ3ot?= | last post by:
Hi, I'm beginner in Visual C++ so I want to ask you a question. And I'm not good in English:D So I have the program which communicates over sockets. The program has to connect to the server and...
0
by: microcool1024 | last post by:
I am having a problem getting a C callback to correctly activate in a C# program after using a dllimport. Here is the declaration of the C code in the C header: typedef BOOL (CALLBACK...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.