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

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() ...

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".

ok thanku
but on wht way it's verifing.
can u tell me
please
thank u
sree

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.

thanku
but i typed wrongly
i need about gethostbyname()
how it works
so please provide me some useful information thank u