IceWalkers.com - Linux Software downloads and news
Name : Password :
Linux SoftwareLinux RPMLinux HowtosLink UsAboutAdvertise

gethostbyname (3)

GETHOSTBYNAME(3)           Linux Programmer's Manual          GETHOSTBYNAME(3)



NAME
       gethostbyname, gethostbyaddr, sethostent, endhostent, herror, hstrerror
       - get network host entry

SYNOPSIS
       #include<netdb.h>
       externinth_errno;

       structhostent*gethostbyname(constchar*name);

       #include<sys/socket.h>/*forAF_INET*/
       structhostent*gethostbyaddr(constchar*addr,
         int len,int type);

       voidsethostent(int stayopen);

       voidendhostent(void);

       voidherror(constchar*s);

       constchar*hstrerror(int err);


       /* GNU extensions */
       structhostent*gethostbyname2(constchar*name,int af);

       intgethostbyname_r(constchar*name,
         structhostent*ret,char*buf,size_t buflen,
         structhostent**result,int*h_errnop);

       intgethostbyname2_r(constchar*name,int af,
         structhostent*ret,char*buf,size_t buflen,
         structhostent**result,int*h_errnop);

DESCRIPTION
       The gethostbyname() function returns a structure of  type  hostent  for
       the  given  host  name.   Here  name  is either a host name, or an IPv4
       address in standard dot notation, or an IPv6 address in colon (and pos-
       sibly  dot)  notation.  (See  RFC  1884  for  the  description  of IPv6
       addresses.)  If name is an IPv4 or IPv6 address, no lookup is performed
       and  gethostbyname()  simply  copies name into the h_name field and its
       struct in_addr equivalent into the h_addr_list[0] field of the returned
       hostent  structure.   If  name doesn't end in a dot and the environment
       variable HOSTALIASES is set, the alias file pointed to  by  HOSTALIASES
       will  first be searched for name (see hostname(7) for the file format).
       The current domain and its parents are searched unless name ends  in  a
       dot.

       The  gethostbyaddr()  function  returns a structure of type hostent for
       the given host address addr of length len and address type  type.   The
       only valid address type is currently AF_INET.

       The  sethostent()  function  specifies, if stayopen is true (1), that a
       connected TCP socket should be used for the  name  server  queries  and
       that the connection should remain open during successive queries.  Oth-
       erwise, name server queries will use UDP datagrams.

       The endhostent() function ends the use of a  TCP  connection  for  name
       server queries.

       The  (obsolete)  herror()  function prints the error message associated
       with the current value of h_errno on stderr.

       The (obsolete) hstrerror() function takes an  error  number  (typically
       h_errno) and returns the corresponding message string.

       The  domain  name  queries  carried out by gethostbyname() and gethost-
       byaddr() use a combination of any or all of the name server named(8), a
       broken  out  line  from /etc/hosts, and the Network Information Service
       (NIS or  YP),  depending  upon  the  contents  of  the  order  line  in
       /etc/host.conf.   (See  resolv+(8)).   The  default  action is to query
       named(8), followed by /etc/hosts.

       The hostent structure is defined in <netdb.h> as follows:

              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 */
              }
              #define h_addr  h_addr_list[0]  /* for backward compatibility */

       The members of the hostent structure are:

       h_name The official name of the host.

       h_aliases
              A zero-terminated array of alternative names for the host.

       h_addrtype
              The type of address; always AF_INET at present.

       h_length
              The length of the address in bytes.

       h_addr_list
              A zero-terminated array of network addresses  for  the  host  in
              network byte order.

       h_addr The first address in h_addr_list for backward compatibility.

RETURNVALUE
       The  gethostbyname()  and  gethostbyaddr() functions return the hostent
       structure or a NULL pointer if an error occurs.  On error, the  h_errno
       variable holds an error number.

ERRORS
       The variable h_errno can have the following values:

       HOST_NOT_FOUND
              The specified host is unknown.

       NO_ADDRESS or NO_DATA
              The requested name is valid but does not have an IP address.

       NO_RECOVERY
              A non-recoverable name server error occurred.

       TRY_AGAIN
              A temporary error occurred on an authoritative name server.  Try
              again later.

FILES
       /etc/host.conf
              resolver configuration file

       /etc/hosts
              host database file

CONFORMINGTO
       BSD 4.3.

NOTES
       The SUS-v2 standard is buggy and declares the len parameter of gethost-
       byaddr()  to  be  of type size_t.  (That is wrong, because it has to be
       int, and size_t is not. POSIX 1003.1-2001 makes it socklen_t, which  is
       OK.)

       The  functions  gethostbyname() and gethostbyaddr() may return pointers
       to static data, which may be overwritten by later  calls.  Copying  the
       struct  hostent  does  not suffice, since it contains pointers - a deep
       copy is required.

       Glibc2 also has a gethostbyname2() that works like gethostbyname(), but
       permits to specify the address family to which the address must belong.

       Glibc2 also has reentrant  versions  gethostbyname_r()  and  gethostby-
       name2_r().   These return 0 on success and nonzero on error. The result
       of the call is now stored in the struct with address  ret.   After  the
       call,  *result will be NULL on error or point to the result on success.
       Auxiliary data is stored in the buffer buf of length buflen.   (If  the
       buffer  is  too  small, these functions will return ERANGE.)  No global
       variable h_errno is modified, but the address of a variable in which to
       store error numbers is passed in h_errnop.

       POSIX 1003.1-2001 marks gethostbyaddr() and gethostbyname() legacy, and
       introduces

       structhostent*getipnodebyaddr(constvoid*restrict addr,
         socklen_t len,int type,int*restrict error_num);

       structhostent*getipnodebyname(constchar*name,
         int type,int flags,int*error_num);

SEEALSO
       resolver(3), hosts(5), hostname(7), resolv+(8), named(8)



BSD                               2000-08-12                  GETHOSTBYNAME(3)

CMSG_ALIGNfmodllroundfstrncmp
CMSG_FIRSTHDRfnmatchllroundlstrncpy
CMSG_NXTHDRfopenlocaleconvstrndup
CMSG_SPACEforkptylocaltimestrndupa
MB_CUR_MAXfpathconflockfstrnlen
MB_LEN_MAXfprintflogstrpbrk
__fbufsizefpurgelog10strptime
__flbffputclog1pstrrchr
__fpendingfputc_unlockedlogin_ttystrsep
__fpurgefputslogwtmpstrsignal
__freadablefputs_unlockedlongjmpstrspn
__freadingfputwclrand48strstr
__fsetlockingfputwc_unlockedlrintstrtod
__fwritablefputwslrintfstrtof
__fwritingfputws_unlockedlrintlstrtok
__malloc_hookfreadlroundstrtok_r
__setfpucwfread_unlockedlroundfstrtol
_flushlbffreelroundlstrtold
a64lfreeaddrinfolsearchstrtoll
abortfreehostentmakecontextstrtoq
absfreopenmallocstrtoul
acosfrexpmalloc_hookstrtoull
acoshfscanfmblenstrtouq
addmntentfseekmbrlenstrverscmp
allocafseekombrtowcstrxfrm
alphasortfsetposmbsinitsvc_destroy
argz_addftellmbsnrtowcssvc_freeargs
argz_add_sepftellombsrtowcssvc_getargs
argz_appendftimembstowcssvc_getcaller
argz_countftokmbtowcsvc_getreq
argz_createftrylockfilememalignsvc_getreqset
argz_create_sepftsmemccpysvc_register
argz_deletefts_childrenmemchrsvc_run
argz_extractfts_closememcmpsvc_sendreply
argz_insertfts_openmemcpysvc_unregister
argz_nextfts_readmemfrobsvcerr_auth
argz_replacefts_setmemmemsvcerr_decode
argz_stringifyftwmemmovesvcerr_noproc
asctimefunlockfilememrchrsvcerr_noprog
asinfwidememsetsvcerr_progvers
asinhfwprintfmkdtempsvcerr_systemerr
asprintffwritemkfifosvcerr_weakauth
assertfwrite_unlockedmkstempsvcfd_create
assert_perrorgai_strerrormktempsvcraw_create
atangammamktimesvctcp_create
atan2gammafmodfsvcudp_bufcreate
atanhgammalmpoolsvcudp_create
atexitgcvtmrand48swab
atofget_current_dir_namemtraceswapcontext
atoiget_myaddressmuntraceswprintf
atolgetaddrinfonansysconf
atollgetcnanfsyslog
atoqgetc_unlockednanlsystem
auth_destroygetcharnearbyinttan
authnone_creategetchar_unlockednearbyintftanh
authunix_creategetcwdnearbyintltcdrain
authunix_create_defaultgetdatenetlinktcflow
basenamegetdate_rnextaftertcflush
bcmpgetdelimnextafterftcgetattr
bcopygetdirentriesnextafterltcgetpgrp
bindresvportgetenvnexttowardtcgetsid
bsearchgetfsentnexttowardftcsendbreak
bstringgetfsfilenexttowardltcsetattr
btowcgetfsspecnftwtcsetpgrp
btreegetgrentnl_langinfotdelete
byteordergetgrgidnrand48telldir
bzerogetgrnamntohltempnam
callocgethostbyaddrntohstermios
callrpcgethostbynameon_exittfind
catclosegethostbyname2opendirtgamma
catgetsgethostbyname2_ropenlogtgammaf
catopengethostbyname_ropenptytgammal
cbrtgetipnodebyaddrpathconftimegm
ceilgetipnodebynamepclosetimelocal
ceilfgetlineperrortmpfile
ceillgetloadavgpmap_getmapstmpnam
cfgetispeedgetloginpmap_getporttoascii
cfgetospeedgetmntentpmap_rmtcalltolower
cfmakerawgetnameinfopmap_settoupper
cfsetispeedgetnetbyaddrpmap_unsettowctrans
cfsetospeedgetnetbynamepopentowlower
clearenvgetnetentposix_memaligntowupper
clearerrgetoptpowtrunc
clearerr_unlockedgetopt_longprintftruncf
clnt_broadcastgetopt_long_onlyprofiltruncl
clnt_callgetpasspsignaltsearch
clnt_controlgetprotobynameptsnamettyname
clnt_creategetprotobynumberputcttyname_r
clnt_destroygetprotoentputc_unlockedttyslot
clnt_freeresgetptputchartwalk
clnt_geterrgetpwputchar_unlockedtzset
clnt_pcreateerrorgetpwentputenvulimit
clnt_perrnogetpwnamputpwentundocumented
clnt_perrorgetpwuidputsungetc
clnt_spcreateerrorgetrpcbynamepututlineungetwc
clnt_sperrnogetrpcbynumberpututxlineunlocked_stdio
clnt_sperrorgetrpcentputwunlockpt
clntraw_creategetrpcportputwcunsetenv
clnttcp_creategetsputwc_unlockedupdwtmp
clntudp_bufcreategetservbynameputwcharusleep
clntudp_creategetservbyportputwchar_unlockedutmpname
clockgetserventqecvtva_arg
closedirgetttyentqecvt_rva_end
closeloggetttynamqfcvtva_start
cmsggetumaskqfcvt_rvalloc
confstrgetusershellqgcvtvasprintf
copysigngetutentqsortvdprintf
copysignfgetutidqueueverr
copysignlgetutlineraiseverrx
cosgetutxentrandversionsort
coshgetutxidrandomvfprintf
cryptgetutxlinercmdvfscanf
ctermidgetwre_compvfwprintf
ctimegetwcre_execvprintf
cuseridgetwc_unlockedreaddirvscanf
daemongetwcharreallocvsnprintf
dbgetwchar_unlockedrealpathvsprintf
dbopengetwdrecnovsscanf
difftimeglobregcompvswprintf
dirfdglobfreeregerrorvsyslog
dirnamegmtimeregexvwarn
divgrantptregexecvwarnx
dlclosegsignalregfreevwprintf
dlerrorhashregisterrpcwarn
dlopenhasmntoptremovewarnx
dlsymhcreateremquewcpcpy
dn_comphcreate_rres_initwcpncpy
dn_expandhdestroyres_mkquerywcrtomb
dprintfhdestroy_rres_querywcscasecmp
drand48herrorres_querydomainwcscat
dremhsearchres_searchwcschr
dysizehsearch_rres_sendwcscmp
ecvthstrerrorresolverwcscpy
ecvt_rhtonlrewindwcscspn
encrypthtonsrewinddirwcsdup
endfsenthypotrindexwcslen
endgrenticonvrintwcsncasecmp
endhostenticonv_closerintfwcsncat
endmntenticonv_openrintlwcsncmp
endnetentimaxabsroundwcsncpy
endprotoentindexroundfwcsnlen
endpwentinetroundlwcsnrtombs
endrpcentinet_addrrpcwcspbrk
endserventinet_atonrresvportwcsrchr
endttyentinet_lnaofrtnetlinkwcsrtombs
endusershellinet_makeaddrruserokwcsspn
endutentinet_netofscandirwcsstr
endutxentinet_networkscanfwcstok
envz_addinet_ntoaseed48wcstombs
envz_entryinet_ntopseekdirwcswidth
envz_getinet_ptonsetbufwctob
envz_mergeinfnansetbufferwctomb
envz_removeinitgroupssetenvwctrans
envz_stripinitstatesetfsentwctype
erand48insquesetgrentwcwidth
erfintrosethostentwmemchr
erfciruseroksetjmpwmemcmp
errisalnumsetkeywmemcpy
errnoisalphasetlinebufwmemmove
errxisasciisetlocalewmemset
ether_atonisattysetlogmaskwprintf
ether_aton_risblanksetmntentxdr
ether_hosttoniscntrlsetnetentxdr_accepted_reply
ether_lineisdigitsetprotoentxdr_array
ether_ntoaisgraphsetpwentxdr_authunix_parms
ether_ntoa_risinfsetrpcentxdr_bool
ether_ntohostislowersetserventxdr_bytes
execisnansetstatexdr_callhdr
execlisprintsetttyentxdr_callmsg
execleispunctsetusershellxdr_char
execlpisspacesetutentxdr_destroy
execvisuppersetutxentxdr_double
execvpiswalnumsetvbufxdr_enum
exitiswalphashm_openxdr_float
expiswblanksigaddsetxdr_free
expm1iswcntrlsigdelsetxdr_getpos
fabsiswctypesigemptysetxdr_inline
fabsfiswdigitsigfillsetxdr_int
fabsliswgraphsiginterruptxdr_long
fcloseiswlowersigismemberxdr_opaque
fclosealliswprintsiglongjmpxdr_opaque_auth
fcvtiswpunctsignbitxdr_pmap
fcvt_riswspacesigsetjmpxdr_pmaplist
fdopeniswuppersigsetopsxdr_pointer
feclearexceptiswxdigitsinxdr_reference
fegetenvisxdigitsinhxdr_rejected_reply
fegetexceptflagj0sleepxdr_replymsg
fegetroundj0fsnprintfxdr_setpos
feholdexceptj0lsprintfxdr_short
fenvj1sqrtxdr_string
feofj1fsrandxdr_u_char
feof_unlockedj1lsrand48xdr_u_int
feraiseexceptjnsrandomxdr_u_long
ferrorjnfsscanfxdr_u_short
ferror_unlockedjnlssignalxdr_union
fesetenvjrand48stdargxdr_vector
fesetexceptflagkey_decryptsessionstderrxdr_void
fesetroundkey_encryptsessionstdinxdr_wrapstring
fetestexceptkey_gendesstdioxdrmem_create
feupdateenvkey_secretkey_is_setstdio_extxdrrec_create
fflushkey_setsecretstdoutxdrrec_endofrecord
fflush_unlockedkillpgstpcpyxdrrec_eof
ffsklogctlstpncpyxdrrec_skiprecord
fgetcl64astrcasecmpxdrstdio_create
fgetc_unlockedlabsstrcatxprt_register
fgetgrentlcong48strchrxprt_unregister
fgetposldexpstrcmpy0
fgetpwentldivstrcolly0f
fgetslfindstrcpyy0l
fgets_unlockedlgammastrcspny1
fgetwclgamma_rstrdupy1f
fgetwc_unlockedlgammafstrdupay1l
fgetwslgammaf_rstrerroryn
fgetws_unlockedlgammalstrerror_rynf
filenolgammal_rstrfmonynl
fileno_unlockedllabsstrfry 
finitelldivstrftime 
flockfilellrintstring 
floorllrintfstrlen 
floorfllrintlstrncasecmp 


My Money 2.0.53
Personal financial software
Deluge 1.2.2
Bittorrent client written in Python and GTK+
DbVisualizer 7.0.5
The Universal Database Tool
Linux Kernel 2.6 2.6.34-rc2
Linux Kernel
Postfix 2.6.6
Alternative to the Sendmail program
ImageMagick 6.6.0-7
ImageMagick image processing studio
Phorum 5.2.15
Web based discussion software written in PHP.
Gnucash 2.3.13
A full-featured application to keep track of your finances.
Wine 1.1.41
Free implementation of Windows on Unix
NVidia driver 195.36.15
Linux unified nVidia driver
Free IT Magazines, White Papers, eBooks, and more !
Oracle Magazine

Contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more.

Vulnerability Management for Dummies

Get all the Facts and See How to Implement a Successful Vulnerability Management Program.

Website Magazine

Has tapped premier talent in the Internet industry for our content and each and every issue will contain practical advice and insights for website owners.

Linux Software Map
Find Linux RPM
Best Rated Linux Software
Most Rated Linux Software
Linux Distributions
Linux Howtos
Quick Survey

Please take our survey and help us improve our website to serve you better.

Thank you.
Linux Software
Linux / IT Resources
Site Resources
Google
Privacy Policy
Contact Us
Submit Software
Advertising info