Function: network-lookup-address-info
network-lookup-address-info is a function defined in process.c.
Signature
(network-lookup-address-info NAME &optional FAMILY)
Documentation
Look up Internet Protocol (IP) address info of NAME.
Optional parameter FAMILY controls whether to look up IPv4 or IPv6
addresses. The default of nil means both, symbol ipv4 means IPv4
only, symbol ipv6 means IPv6 only. Returns a list of addresses, or
nil if none were found. Each address is a vector of integers, as per
the description of ADDRESS in make-network-process. In case of
error displays the error message.
Probably introduced at or before Emacs version 27.1.
Source Code
// Defined in /usr/src/emacs/src/process.c
{
Lisp_Object addresses = Qnil;
Lisp_Object msg = Qnil;
struct addrinfo *res, *lres;
struct addrinfo hints;
memset (&hints, 0, sizeof hints);
if (EQ (family, Qnil))
hints.ai_family = AF_UNSPEC;
else if (EQ (family, Qipv4))
hints.ai_family = AF_INET;
#ifdef AF_INET6
else if (EQ (family, Qipv6))
hints.ai_family = AF_INET6;
#endif
else
error ("Unsupported lookup type");
hints.ai_socktype = SOCK_DGRAM;
msg = network_lookup_address_info_1 (name, NULL, &hints, &res);
if (!EQ (msg, Qt))
message ("%s", SSDATA(msg));
else
{
for (lres = res; lres; lres = lres->ai_next)
{
#ifndef AF_INET6
if (lres->ai_family != AF_INET)
continue;
#endif
addresses = Fcons (conv_sockaddr_to_lisp (lres->ai_addr,
lres->ai_addrlen),
addresses);
}
addresses = Fnreverse (addresses);
freeaddrinfo (res);
}
return addresses;
}