Next: Network Socket Address, Previous: Network Address Conversion, Up: Networking
This section describes procedures which query various network databases. Care should be taken when using the database routines since they are not reentrant.
A host object is a structure that represents what is known about a network host, and is the usual way of representing a system's network identity inside software.
The following functions accept a host object and return a selected component:
The host address type, one of the
AF
constants, such asAF_INET
orAF_INET6
.
The list of network addresses associated with host. For
AF_INET
these are integer IPv4 address (see Network Address Conversion).
The following procedures are used to search the host database:
Look up a host by name or address, returning a host object. The
gethost
procedure will accept either a string name or an integer address; if given no arguments, it behaves likegethostent
(see below). If a name or address is supplied but the address can not be found, an error will be thrown to one of the keys:host-not-found
,try-again
,no-recovery
orno-data
, corresponding to the equivalenth_error
values. Unusual conditions may result in errors thrown to thesystem-error
ormisc_error
keys.(gethost "www.gnu.org") => #("www.gnu.org" () 2 4 (3353880842)) (gethostbyname "www.emacs.org") => #("emacs.org" ("www.emacs.org") 2 4 (1073448978))
The following procedures may be used to step through the host database from beginning to end.
Initialize an internal stream from which host objects may be read. This procedure must be called before any calls to
gethostent
, and may also be called afterward to reset the host entry stream. If stayopen is supplied and is not#f
, the database is not closed by subsequentgethostbyname
orgethostbyaddr
calls, possibly giving an efficiency gain.
Return the next host object from the host database, or
#f
if there are no more hosts to be found (or an error has been encountered). This procedure may not be used beforesethostent
has been called.
Close the stream used by
gethostent
. The return value is unspecified.
If stayopen is omitted, this is equivalent to
endhostent
. Otherwise it is equivalent tosethostent stayopen
.
The following functions accept an object representing a network and return a selected component:
The type of the network number. Currently, this returns only
AF_INET
.
The following procedures are used to search the network database:
Look up a network by name or net number in the network database. The net-name argument must be a string, and the net-number argument must be an integer.
getnet
will accept either type of argument, behaving likegetnetent
(see below) if no arguments are given.
The following procedures may be used to step through the network database from beginning to end.
Initialize an internal stream from which network objects may be read. This procedure must be called before any calls to
getnetent
, and may also be called afterward to reset the net entry stream. If stayopen is supplied and is not#f
, the database is not closed by subsequentgetnetbyname
orgetnetbyaddr
calls, possibly giving an efficiency gain.
If stayopen is omitted, this is equivalent to
endnetent
. Otherwise it is equivalent tosetnetent stayopen
.
The following functions accept an object representing a protocol and return a selected component:
The following procedures are used to search the protocol database:
Look up a network protocol by name or by number.
getprotobyname
takes a string argument, andgetprotobynumber
takes an integer argument.getproto
will accept either type, behaving likegetprotoent
(see below) if no arguments are supplied.
The following procedures may be used to step through the protocol database from beginning to end.
Initialize an internal stream from which protocol objects may be read. This procedure must be called before any calls to
getprotoent
, and may also be called afterward to reset the protocol entry stream. If stayopen is supplied and is not#f
, the database is not closed by subsequentgetprotobyname
orgetprotobynumber
calls, possibly giving an efficiency gain.
Close the stream used by
getprotoent
. The return value is unspecified.
If stayopen is omitted, this is equivalent to
endprotoent
. Otherwise it is equivalent tosetprotoent stayopen
.
The following functions accept an object representing a service and return a selected component:
The protocol used by the service. A service may be listed many times in the database under different protocol names.
The following procedures are used to search the service database:
Look up a network service by name or by service number, and return a network service object. The protocol argument specifies the name of the desired protocol; if the protocol found in the network service database does not match this name, a system error is signalled.
The
getserv
procedure will take either a service name or number as its first argument; if given no arguments, it behaves likegetservent
(see below).(getserv "imap" "tcp") => #("imap2" ("imap") 143 "tcp") (getservbyport 88 "udp") => #("kerberos" ("kerberos5" "krb5") 88 "udp")
The following procedures may be used to step through the service database from beginning to end.
Initialize an internal stream from which service objects may be read. This procedure must be called before any calls to
getservent
, and may also be called afterward to reset the service entry stream. If stayopen is supplied and is not#f
, the database is not closed by subsequentgetservbyname
orgetservbyport
calls, possibly giving an efficiency gain.