473,387 Members | 1,569 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,387 software developers and data experts.

can anyone help me with this?

i need a C program which gets hostname as the input and prints the IP address of that hostname.
(Hostname's IP addresses will be given using a seperate file in define.....

just guide me with respect to this...

thanks....
Oct 12 '07 #1
3 909
look into the winsock functions, there are a couple that can do the translation between hostnames and ip addresses
Oct 12 '07 #2
i need a C program which gets hostname as the input and prints the IP address of that hostname.
(Hostname's IP addresses will be given using a seperate file in define.....

just guide me with respect to this...

thanks....

#include <stdio.h>
#include <netdb.h>
#include <netinet/in.h>

struct hostent *he;
struct in_addr a;

int
main (int argc, char **argv)
{
if (argc != 2)
{
fprintf(stderr, "usage: %s hostname\n", argv[0]);
return 1;
}
he = gethostbyname (argv[1]);
if (he)
{
printf("name: %s\n", he->h_name);
while (*he->h_aliases)
printf("alias: %s\n", *he->h_aliases++);
while (*he->h_addr_list)
{
bcopy(*he->h_addr_list++, (char *) &a, sizeof(a));
printf("address: %s\n", inet_ntoa(a));
}
}
else
herror(argv[0]);
return 0;
}


can any one please explain me this program....

struct hostent *he;
struct in_addr a;

what these two structures are? waht they will do?
Oct 15 '07 #3
#include <stdio.h>
#include <netdb.h>
#include <netinet/in.h>

struct hostent *he;
struct in_addr a;

int
main (int argc, char **argv)
{
if (argc != 2)
{
fprintf(stderr, "usage: %s hostname\n", argv[0]);
return 1;
}
he = gethostbyname (argv[1]);
if (he)
{
printf("name: %s\n", he->h_name);
while (*he->h_aliases)
printf("alias: %s\n", *he->h_aliases++);
while (*he->h_addr_list)
{
bcopy(*he->h_addr_list++, (char *) &a, sizeof(a));
printf("address: %s\n", inet_ntoa(a));
}
}
else
herror(argv[0]);
return 0;
}


can any one please explain me this program....

struct hostent *he;
struct in_addr a;

what these two structures are? waht they will do?
You will need to find the structure definitions, this will tell you what elements are within the structure. This in turn will give you the answer.
Nov 23 '07 #4

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

Similar topics

0
by: asdf sdf | last post by:
i have an install issue with moinmoin on win2k. i've tried the mailing list, but it appears to be a very low traffic, low subscriber list. can i get a reality check? is anyone using moinmoin in...
1
by: Simon Harvey | last post by:
Hi chaps, Does anyone know if the beast is going to release Visual Tools for office to work with Visual Studio 2002 and not just 2003, or are they quite happy to shaft those that supported them...
1
by: Greg Steele | last post by:
Does anyone have a copy or know where I can get an installation executable for chiliReports 2.0 from chili! soft? The company I'm working for bought a copy several years ago, then moved their...
2
by: Ken Shaw | last post by:
G'day, I'm trying to tack down any delta compression library that I could licence for use in a project. Does anyone know of a decent binary delta compression library? cheers, Ken Shaw
0
by: james | last post by:
Hi guys! I´ve got a centerd table on my site with a black 1 pixel border. What i would like to do is to add a drop shadow to the table. Anyone know if it's possible to create a drop shadow for a...
162
by: Isaac Grover | last post by:
Hi everyone, Just out of curiosity I recently pointed one of my hand-typed pages at the W3 Validator, and my hand-typed code was just ripped to shreds. Then I pointed some major sites...
0
by: Jay1969 | last post by:
Hey all, I heard there was a new service offered to Microsoft partners called ISV Advisory Services (see link) where MS is giving free dev consulting to their Partners. ...
13
by: penguin732901 | last post by:
Checking back for discussions, there was a lot of talk about 2000 being slower than 97, but not so much lately. What is the latest opinion? Anyone care to set up a poll for how many NG members...
2
by: Brent Taylor via AccessMonster.com | last post by:
HELP----DOES ANYONE HAVE A SIMPLE .mdb for MLM structure? Does anyone have an example database for multi-level marketing for a 3 Tier setup? Thank you, brenttaylor@actionimports.net
2
by: Bruno Alexandre | last post by:
Hi guys, does anyone know where is the Website used in the MSDN "Lear ASP.NET 2.0 with Jeff Prosise" (http://msdn.microsoft.com/asp.net/beta2/multimedia/default.aspx) events? The website used...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.