Next: , Previous: Network Address Conversion, Up: Networking


38.11.2 Network Databases

This section describes procedures which query various network databases. Care should be taken when using the database routines since they are not reentrant.

38.11.2.1 The Host Database

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:

— Scheme Procedure: hostent:name obj

The "official" hostname for host.

— Scheme Procedure: hostent:aliases obj

A list of aliases for host.

— Scheme Procedure: hostent:addrtype obj

The host address type. For hosts with Internet addresses, this will return AF_INET.

— Scheme Procedure: hostent:length obj

The length of each address for host, in bytes.

— Scheme Procedure: hostent:addr-list obj

The list of network addresses associated with host.

The following procedures are used to search the host database:

— Scheme Procedure: gethost name/address
— Scheme Procedure: gethostbyname name/address
— Scheme Procedure: gethostbyaddr name/address
— C Function: scm_gethost (name/address)

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 like gethostent (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 or no-data, corresponding to the equivalent h_error values. Unusual conditions may result in errors thrown to the system-error or misc_error keys.

The following procedures may be used to step through the host database from beginning to end.

— Scheme Procedure: sethostent [stayopen...]

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 subsequent gethostbyname or gethostbyaddr calls, possibly giving an efficiency gain.

— Scheme Procedure: gethostent

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 before sethostent has been called.

— Scheme Procedure: endhostent

Close the stream used by gethostent. The return value is unspecified.

— Scheme Procedure: sethost [stayopen]
— C Function: scm_sethost (stayopen) |0 |1 |0

If stayopen is omitted, this is equivalent to endhostent. Otherwise it is equivalent to sethostent stayopen.

38.11.2.2 The Network Database

The following functions accept an object representing a network and return a selected component:

— Scheme Procedure: netent:name obj

The "official" network name.

— Scheme Procedure: netent:aliases obj

A list of aliases for the network.

— Scheme Procedure: netent:addrtype obj

The type of the network number. Currently, this returns only AF_INET.

— Scheme Procedure: netent:net obj

The network number.

The following procedures are used to search the network database:

— Scheme Procedure: getnet name/number
— Scheme Procedure: getnetbyname name/number
— Scheme Procedure: getnetbyaddr name/number
— C Function: scm_getnet (name/number)

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 like getnetent (see below) if no arguments are given.

The following procedures may be used to step through the network database from beginning to end.

— Scheme Procedure: setnetent [stayopen...]

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 subsequent getnetbyname or getnetbyaddr calls, possibly giving an efficiency gain.

— Scheme Procedure: getnetent

Return the next entry from the network database.

— Scheme Procedure: endnetent

Close the stream used by getnetent. The return value is unspecified.

— Scheme Procedure: setnet [stayopen]
— C Function: scm_setnet (stayopen) |0 |1 |0

If stayopen is omitted, this is equivalent to endnetent. Otherwise it is equivalent to setnetent stayopen.

38.11.2.3 The Protocol Database

The following functions accept an object representing a protocol and return a selected component:

— Scheme Procedure: protoent:name obj

The "official" protocol name.

— Scheme Procedure: protoent:aliases obj

A list of aliases for the protocol.

— Scheme Procedure: protoent:proto obj

The protocol number.

The following procedures are used to search the protocol database:

— Scheme Procedure: getproto name/number
— Scheme Procedure: getprotobyname name/number
— Scheme Procedure: getprotobynumber name/number
— C Function: scm_getproto (name/number)

Look up a network protocol by name or by number. getprotobyname takes a string argument, and getprotobynumber takes an integer argument. getproto will accept either type, behaving like getprotoent (see below) if no arguments are supplied.

The following procedures may be used to step through the protocol database from beginning to end.

— Scheme Procedure: setprotoent [stayopen...]

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 subsequent getprotobyname or getprotobynumber calls, possibly giving an efficiency gain.

— Scheme Procedure: getprotoent

Return the next entry from the protocol database.

— Scheme Procedure: endprotoent

Close the stream used by getprotoent. The return value is unspecified.

— Scheme Procedure: setproto [stayopen]
— C Function: scm_setproto (stayopen) |0 |1 |0

If stayopen is omitted, this is equivalent to endprotoent. Otherwise it is equivalent to setprotoent stayopen.

38.11.2.4 The Service Database

The following functions accept an object representing a service and return a selected component:

— Scheme Procedure: servent:name obj

The "official" name of the network service.

— Scheme Procedure: servent:aliases obj

A list of aliases for the network service.

— Scheme Procedure: servent:port obj

The Internet port used by the service.

— Scheme Procedure: servent:proto obj

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:

— Scheme Procedure: getserv service protocol
— Scheme Procedure: getservbyname service protocol
— Scheme Procedure: getservbyport service protocol
— C Function: scm_getserv (service, protocol)

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, signal a system error.

The getserv procedure will take either a service name or number as its first argument; if given no arguments, it behaves like getservent (see below).

The following procedures may be used to step through the service database from beginning to end.

— Scheme Procedure: setservent [stayopen...]

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 subsequent getservbyname or getservbyport calls, possibly giving an efficiency gain.

— Scheme Procedure: getservent

Return the next entry from the services database.

— Scheme Procedure: endservent

Close the stream used by getservent. The return value is unspecified.

— Scheme Procedure: setserv [stayopen]
— C Function: scm_setserv (stayopen) |0 |1 |0

If stayopen is omitted, this is equivalent to endservent. Otherwise it is equivalent to setservent stayopen.