regarding gethostname()


 
Thread Tools Search this Thread
Top Forums Programming regarding gethostname()
# 1  
Old 01-30-2007
regarding gethostname()

i used
stuct hosent h;
h=gethostname("google.com");
if(h==NULL)
printf("net down");
else
printf("net down");


my question hoe this gethostname will verify whether net ia active or inactive
i eman whether by usin ping or sending socket .
if it is socket which type of socket it is usingg.
thank u
sreee
# 2  
Old 01-30-2007
It will ask the resolver which relies on how your name resolution is set:
host file lookup only (/etc/hosts) and/or querying (socket tcp/udp on port 53) a dns server (/etc/resolv.conf) the order of search is govern by /etc/nsswitch.conf

O-o-o-ps sorry Perderabo, I thought I saw gethostbyname() ...

Last edited by andryk; 01-30-2007 at 08:02 AM..
# 3  
Old 01-30-2007
gethostname() is a system call that simply returns the contents of a small data area in the kernel. It has a partner called sethostname() that can store something there. gethostname() returns an integer and 0 means it succeeded. It will fail if it is called incorrectly and this results in -1.

A different function called gethostbyname will return a pointer to a hostent structure. There are so many typos in the original post that I can't tell for sure what is really going on. "stuct"? "hosent"? Stuff like that is not going to compile. I'm not sure what "verify that the net is active" means but gethostbyname is not going to ping anything or "send a socket".
# 4  
Old 01-30-2007
ok thanku
but on wht way it's verifing.
can u tell me
please
thank u
sree
# 5  
Old 01-30-2007
Assuming I get what you want -
It can lookup the name different ways, as Andryk indicated. If it works it generally means that you can talk to whatever (by configuration) gave the answer, and that it thinks the hostname you looked up exists.

It does not mean:
1. internet is available
2. the remote hostname is available

Use ping to do that kind of check, for example.
# 6  
Old 02-01-2007
thanku
but i typed wrongly
i need about gethostbyname()
how it works
so please provide me some useful information thank u
Login or Register to Ask a Question

Previous Thread | Next Thread

1 More Discussions You Might Find Interesting

1. Programming

gethostname warning

Hi, does anyone knows how to get rid of this annoying warning? Thank you! #include <netdb.h> main() { gethostbyname("test"); } $ gcc -static test.c /tmp/ccW9HG18.o: In function `main': test.c:(.text+0x19): warning: Using 'gethostbyname' in statically linked applications requires at... (3 Replies)
Discussion started by: paulquater
3 Replies
Login or Register to Ask a Question