The integrated cross-platform development tool for ANSI Common Lisp LispWorks logo

Lisp Knowledgebase



Title: How to query TCP host address and name details

ID: 17001


Product: LispWorks
Version: All
OS: All

Description: The C functions gethostbyname() and gethostbyaddr() can be used to find details of hosts from TCP naming services. These can be called easily from Lisp via the function COMM:GET-HOST-ENTRY documented below.


get-host-entry

Function

Summary
Returns address or name information about a given host.

Package
comm

Signature
get-host-entry host &key fields => field-values

Arguments
host
A number or a string.
fields
A list of keywords.

Values
field-values
Values, one for each field.

Description
Using whatever host naming services are configured on the current machine, get-host-entry returns address or name information about the given host. NIL is returned if the host is unknown.

The host argument can be one of the following:
  • a name string, e.g. "www.foobar.com"
  • a dotted inet address string, e.g. "209.130.14.246"
  • a integer representing the inet address, e.g. #xD1820EF6

    The fields argument is a list of keywords describing what information to return for the host. If get-host-entry succeeds, it returns multiple values, one value for each field specified. The following fields are allowed:
    field returned value
    :address the IP address as in integer
    :name the primary name as a string
    :aliases the alias names as a list of strings

    Examples

    CL-USER 1 > (comm:get-host-entry "www.foobar.com" :fields '(:address))
    3514961654

    CL-USER 2 > (comm:get-host-entry 3514961654 :fields '(:name))
    "www.foobar.com"

    CL-USER 3 > (comm:get-host-entry "www.foobar.com"
                                    :fields '(:name :aliases :address))
    "www.foobar.com"
    NIL
    3514961654

    CL-USER 4 >


  • See Also:
    Workaround:
    Patch:

    Hardware:N/A
    Summary:
    Bug#:4966, 7322
    Patch Enhancement#:
    Reported:

    Top | Back