chickadee » socket » ni/dgram

name-information saddr #!optional (flags 0)procedure

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:

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.
Do not attempt to resolve the service number to a name.
If hostname lookup fails, raise an error.
Return only the local part of the hostname for local hosts.
Look up the service as a datagram service. A few service names may differ between TCP and UDP.


(name-information (inet-address "" 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 "" 80))
  ; => ("" . "http")
(name-information (inet-address "" 80) ni/namereqd)
  ; => error: nodename nor servname provided, or not known
(name-information (inet-address "2001:470:0:64::2" 80) ni/numericserv)
  ; => ("" . 80)
(name-information (socket-peer-name s))  ;; s being an accept()ed socket
  ; => ("taco.universe12.dim" . 31828)