static void create_pty (Lisp_Object);
static void exec_sentinel (Lisp_Object, Lisp_Object);
+static Lisp_Object
+network_lookup_address_info_1 (Lisp_Object host, const char *service,
+ struct addrinfo *hints, struct addrinfo **res);
+
/* Number of bits set in connect_wait_mask. */
static int num_pending_connects;
if (!NILP (host))
{
struct addrinfo *res, *lres;
- int ret;
+ Lisp_Object msg;
maybe_quit ();
hints.ai_family = family;
hints.ai_socktype = socktype;
- ret = getaddrinfo (SSDATA (host), portstring, &hints, &res);
- if (ret)
-#ifdef HAVE_GAI_STRERROR
- {
- synchronize_system_messages_locale ();
- char const *str = gai_strerror (ret);
- if (! NILP (Vlocale_coding_system))
- str = SSDATA (code_convert_string_norecord
- (build_string (str), Vlocale_coding_system, 0));
- error ("%s/%s %s", SSDATA (host), portstring, str);
- }
-#else
- error ("%s/%s getaddrinfo error %d", SSDATA (host), portstring, ret);
-#endif
+ msg = network_lookup_address_info_1 (host, portstring, &hints, &res);
+ if (!EQ(msg, Qt))
+ {
+ error ("%s", SSDATA (msg));
+ }
for (lres = res; lres; lres = lres->ai_next)
addrinfos = Fcons (conv_addrinfo_to_lisp (lres), addrinfos);
#endif
}
+static Lisp_Object
+network_lookup_address_info_1 (Lisp_Object host, const char *service,
+ struct addrinfo *hints, struct addrinfo **res)
+{
+ Lisp_Object msg = Qt;
+ int ret;
+
+ if (SBYTES (host) != SCHARS (host))
+ error ("Non-ASCII hostname %s detected, please use puny-encode-domain",
+ SSDATA (host));
+ ret = getaddrinfo (SSDATA (host), service, hints, res);
+ if (ret)
+ {
+ if (service == NULL)
+ service = "0";
+#ifdef HAVE_GAI_STRERROR
+ synchronize_system_messages_locale ();
+ char const *str = gai_strerror (ret);
+ if (! NILP (Vlocale_coding_system))
+ str = SSDATA (code_convert_string_norecord
+ (build_string (str), Vlocale_coding_system, 0));
+ AUTO_STRING (format, "%s/%s %s");
+ msg = CALLN (Fformat, format, host, build_string (service), build_string (str));
+#else
+ AUTO_STRING (format, "%s/%s getaddrinfo error %d");
+ msg = CALLN (Fformat, format, host, build_string (service), make_number (ret));
+#endif
+ }
+ return msg;
+}
+
DEFUN ("network-lookup-address-info", Fnetwork_lookup_address_info,
Snetwork_lookup_address_info, 1, 2, 0,
doc: /* Look up ip address info of NAME.
(Lisp_Object name, Lisp_Object family)
{
Lisp_Object addresses = Qnil;
- struct addrinfo *res, *lres;
- int ret;
+ Lisp_Object msg = Qnil;
+ struct addrinfo *res, *lres;
struct addrinfo hints;
- if (STRING_MULTIBYTE (name))
- error ("Non-ASCII hostname \"%s\" detected, please use puny-encode-string",
- SSDATA (name));
memset (&hints, 0, sizeof hints);
if (EQ (family, Qnil))
hints.ai_family = AF_UNSPEC;
- if (EQ (family, Qipv4))
+ else if (EQ (family, Qipv4))
hints.ai_family = AF_INET;
- if (EQ (family, Qipv6))
+ else if (EQ (family, Qipv6))
#ifdef AF_INET6
hints.ai_family = AF_INET6;
#else
/* If we don't support IPv6, querying will never work anyway */
return addresses;
#endif
+ else
+ error ("Unsupported lookup type");
hints.ai_socktype = SOCK_DGRAM;
- ret = getaddrinfo (SSDATA (name), NULL, &hints, &res);
- if (ret)
-#ifdef HAVE_GAI_STRERROR
+ msg = network_lookup_address_info_1 (name, NULL, &hints, &res);
+ if (!EQ(msg, Qt))
{
- synchronize_system_messages_locale ();
- char const *str = gai_strerror (ret);
- if (! NILP (Vlocale_coding_system))
- str = SSDATA (code_convert_string_norecord
- (build_string (str), Vlocale_coding_system, 0));
- message ("\"%s\" \"%s\"", SSDATA (name), str);
+ message ("%s", SSDATA(msg));
}
-#else
- message ("%s network-lookup-address-info error %d", SSDATA (name), ret);
-#endif
else
{
for (lres = res; lres; lres = lres->ai_next)