chickadee » socket » ni/numerichost

name-information saddr #!optional (flags 0)procedure
ni/numerichostconstant
ni/numericservconstant
ni/dgramconstant
ni/namereqdconstant
ni/nofqdnconstant

Given a socket address object saddr, performs a reverse-lookup to obtain the node and service names, returning them as the pair ("node" . "service"). If hostname lookup fails, the numeric representation of the address is returned as a string. If service number lookup fails, it is returned as an integer.

The socket address object is usually constructed with inet-address or obtained from a socket call, e.g. socket-peer-name. As a convenience in socket 0.2.1 and later, if saddr is a string, it is converted to a socket address object with (inet-address saddr #f).

The behavior of name-information can be influenced by FLAGS. FLAGS may be the bitwise-ior (or simply +) of the following constants:

ni/numerichost
Do not resolve the node address to a name; instead, return the canonical string representation of the address, as in inet_ntop(). (sockaddr-address saddr) returns the same representation.
ni/numericserv
Do not attempt to resolve the service number to a name.
ni/namereqd
If hostname lookup fails, raise an error.
ni/nofqdn
Return only the local part of the hostname for local hosts.
ni/dgram
Look up the service as a datagram service. A few service names may differ between TCP and UDP.

Examples:

(name-information (inet-address "127.0.0.1" 80))
  ; => ("localhost" . "http")
(name-information (inet-address "::1" 80))
  ; => ("localhost" . "http")
(name-information (inet-address "::1" #f))
  ; => ("localhost" . 0)
(name-information "::1")
  ; => ("localhost" . 0)
(name-information (inet-address "::1" 80) ni/numerichost)
  ; => ("::1" . "http")
(name-information (inet-address "::1" 80) (+ ni/numerichost ni/numericserv))
  ; => ("::1" . 80)
(name-information (inet-address "127.0.0.2" 80))
  ; => ("127.0.0.2" . "http")
(name-information (inet-address "127.0.0.2" 80) ni/namereqd)
  ; => error: nodename nor servname provided, or not known
(name-information (inet-address "2001:470:0:64::2" 80) ni/numericserv)
  ; => ("ipv6.he.net" . 80)
(name-information (socket-peer-name s))  ;; s being an accept()ed socket
  ; => ("taco.universe12.dim" . 31828)