The dns structure contains a library for querying DNS servers. The library contains sophisticated replacements for scsh's interface to the gethostbyname and gethostbyaddr and many extensions to these functions.
The main features of the libraray include:
Complete implementation of the DNS protocol
Concurrent contacting of multiple DNS servers without blocking the scsh process
Internal caching of DNS responses
Parsing of resolv.conf, including search entries to generate FQDNs from unqualified host names
Rich condition hierarchie
The library defines a set of conditions raised by the procedures of the library. The supertype of these conditions is dns-error.
The predicate for dns-error conditions.
Returns a string with the description of the condition.
These conditons correspond to errors returned by the DNS server. They are all subtypes of the dns-server-error condition which in turn is a subtype of dns-error.
The predicate for dns-server-error conditions.
The type predicates for the conditions above.
The library uses an internal store to cache data obtained from DNS servers. All procedures take a boolean flag use-cache? that indicates whether the cache should be used or not. use-cache? defaults to true.
This procedure erases all information stored in the internal cache.
The library is further capable of parsing the contents of /etc/resolv.conf (see Section 13.5). The nameservers listed there are the default value for the optional argument nameserver list which many procedures of the library accept. Nameserver is either a IP-address or a dotted IP string.
Given the FQDN of a host, dns-lookup-ip returns the IP address. The optional argument specifes the name servers to query, it defaults to the ones found in /etc/resolv.conf.
Looks up the FQDN for the given IP address. The optional argument specifes the name servers to query, it defaults to the ones found in /etc/resolv.conf.
Looks up an authoritative name server for a hostname, returns a list of name servers.
Looks up mail-exchangers for a hostname und returns them in a list sorted by preference.
Returns the FQDN for of the address bound to argument. The argument cache? indicates whether the internal cache may be queried to obtain the information.
These procedures provide the same functionality as dns-lookup-name and dns-lookup-ip but return #f in case of an dns-error.
host-fqdn returns the fully qualified domain name (FQDN) for its argument which can be either a unqualified host name or a socket address. The procedure system-fqdn returns the FQDN of the local host. These procedures use a list of domain names obtained from /etc/resolv.conf to the generate FQDNs and try to resolve these FQDNs.
This section describes a set of data structures and procedures which directly correspond to the data flow of the DNS protocol. The central entity is a message, the abstraction of the packet sent to the server or received from the server (The DNS protocol uses the same data format for both directions). A dns-message encapsulates the query message sent to the server, the response message received from the server, and some additional information the library gathered while generating the dns-message.
Most general way to submit a DNS query. The message is sent to the name servers via protocol which can be either (network-procotcol tcp) or (network-protocol udp), both members of of the enumerated type network-protocol. After receiving the reply, dns-get-information applies the predicate answer-okay? to the message. If it returns #f and the answer is not authoritative additional name servers sent with the reply are checked until an authoritative answer is found. If the predicate returns #f but the answer is authoritative a bad-address condition is signalled.
Constructor and predicate for the enumerated type network-protocol with the possible protocol names tcp and udp.
Convenient shortcut to submit a DNS query. The return value is a dns-message structure:
A dns-message records the query sent to the server and the reply from the server. It also contains information whether the library took the reply from the cache, which protocol was used and to which nameservers the query was sent.
Pretty prints a DNS message to out-port which defaults to the current output port.
A message represents the data sent to the DNS server or received from the DNS server. The DNS protocol uses the same message format for queries and replies. In queries only the header and the questions is present, a reply may contain answers, name servers and and additional informations as resource records. Message-source returns the actual data sent over the network.
The procedure generates a message the supplied questions, header, and the standard message values for queries.
This simplified constructor generates a message with one question which is built from the parameters, and the standard header flags for queries and the standard message values for queries.
Every DNS message contains a header which stores information about the data present in the message and contains flags for the query.
Flags occur within the header of a DNS message. The boolean value returned from flags-authoritative indicates whether the message was sent from a authoritative server, flags-truncated? should always be #fas the library automatically uses the TCP protocol is the UDP message size is not sufficied.
A question sent to the DNS server.The type and class of the question and answer are elements of enumerated types:
message-class constructs a member of the enumerated type, message-class? is the type predicate, message-class-name returns the symbol and message-class-number the number used for the class in the DNS protocol.The possible names for the classes are:
message-type constructs a member of the enumeration from name <.type-name.> listed in Table 2. message-type? is the type predicate, message-type-name returns the name, and message-type-number the number used for the class the DNS protocol.
| |||||||||||||||||||||||||||||||||
| Table 2: Message types | |||||||||||||||||||||||||||||||||
A resource record as returned from the DNS server. The actual data of the record is stored in the resource-record-data field. It is one of the record types for resource record data described below.
An address resource record which holds an internet address.
A name server resource record containing the FQDN of the name server.
A canonical name resource record which contains the canonical or primary name of the owner.
A mail exchange resource record with the preference and the FQDN of a host willing to act as a mail exchange.
A pointer resource record which points to some other domain name.
A start of a zone of authority resource record.The protocol specifies other possible values for the resource-record-data field but we where no able to find test cases for them.
A cache data structure corresponds to a saved answer to a previous query. cache-answer returns the saved message, cache-ttl returns the time when the cache entry expires and cache-time returns the time the entry was created.
The code signals the condition resolv.conf-parse-error if a parse error occurs while scanning /etc/resolv.conf. It is a subtype of the dns-error condition. resolv.conf-parse-error? is the type predicate for this condition.
Returns the contents of /etc/resolv.conv as an alist with the possible keys nameserver, domain, search, sortlist and options.Note that the library caches the contents of /etc/resolv.conv and resolv.conf only really opens the file if its modification time is more recent than the modification time of the cache.
Parses the contents of /etc/resolv.conv and updates the internal cache of the library.
Returns a list of name servers from /etc/resolv.conf
Returns the first name servers found in /etc/resolv.conf. dns-find-nameserver raises no-nameservers if /etc/resolv.conf does not contain a nameserver entry.
Parses /etc/resolv.conf and extracts the domains specified by the search keyword.
The structure ips provides a small set of procedures for turning the human-readable form of IP addresses (``dotted strings'') into 32 bits numbers.
Tests whether string is a valid dotted string for an IP address.