]> git.eshelyaron.com Git - emacs.git/commitdiff
Ensure building and running on non-IPv6 capable hosts works
authorRobert Pluim <rpluim@gmail.com>
Thu, 7 Nov 2019 15:16:39 +0000 (16:16 +0100)
committerRobert Pluim <rpluim@gmail.com>
Fri, 8 Nov 2019 09:04:13 +0000 (10:04 +0100)
* src/process.c (Fmake_network_process) [AF_INET6]: Only build ::1
localhost when IPv6 is supported.
(Fnetwork_lookup_address_info) [AF_INET6]: Move check for Qipv6 inside
ifdef, since its definition depends on AF_INET6.  Don't return IPv6
addresses when they're not supported.

* test/src/process-tests.el (lookup-family-specification,
lookup-google): Only do IPv6 lookup if IPv6 is supported.

src/process.c
test/src/process-tests.el

index 1f959e39607f109cd78e9140f0e8826255bd408a..8aa4811f7edc60e148a9d55fa06921c387e60f85 100644 (file)
@@ -4015,9 +4015,11 @@ usage: (make-network-process &rest ARGS)  */)
       if (family != AF_LOCAL)
 #endif
         {
+#ifdef AF_INET6
         if (family == AF_INET6)
           host = build_string ("::1");
         else
+#endif
           host = build_string ("127.0.0.1");
         }
     }
@@ -4027,9 +4029,11 @@ usage: (make-network-process &rest ARGS)  */)
         {
        /* Depending on setup, "localhost" may map to different IPv4 and/or
           IPv6 addresses, so it's better to be explicit (Bug#6781).  */
+#ifdef AF_INET6
         if (family == AF_INET6)
           host = build_string ("::1");
         else
+#endif
           host = build_string ("127.0.0.1");
         }
       CHECK_STRING (host);
@@ -4622,7 +4626,8 @@ DEFUN ("network-lookup-address-info", Fnetwork_lookup_address_info,
 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.  */)
+nil if none were found.  Each address is a vector of integers, as per
+the description of ADDRESS in `make-network-process'.  */)
      (Lisp_Object name, Lisp_Object family)
 {
   Lisp_Object addresses = Qnil;
@@ -4636,12 +4641,9 @@ nil if none were found.  Each address is a vector of integers.  */)
     hints.ai_family = AF_UNSPEC;
   else if (EQ (family, Qipv4))
     hints.ai_family = AF_INET;
-  else if (EQ (family, Qipv6))
 #ifdef AF_INET6
+  else if (EQ (family, Qipv6))
     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");
@@ -4653,9 +4655,15 @@ nil if none were found.  Each address is a vector of integers.  */)
   else
     {
       for (lres = res; lres; lres = lres->ai_next)
-       addresses = Fcons (conv_sockaddr_to_lisp (lres->ai_addr,
-                                                 lres->ai_addrlen),
-                          addresses);
+        {
+#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);
index 158c036aaa76c7fd3bc386906699bfd319065f7f..f065d393d2abc79f942b50050381e7ba88301444 100644 (file)
@@ -337,7 +337,8 @@ See Bug#30460."
   (skip-unless (not (getenv "EMACS_HYDRA_CI")))
   (should-error (network-lookup-address-info "google.com" 'both))
   (should (network-lookup-address-info "google.com" 'ipv4))
-  (should (network-lookup-address-info "google.com" 'ipv6)))
+  (when (featurep 'make-network-process '(:family ipv6))
+    (should (network-lookup-address-info "google.com" 'ipv6))))
 
 (ert-deftest lookup-unicode-domains ()
   "Unicode domains should fail"
@@ -354,11 +355,11 @@ See Bug#30460."
   "Check that we can look up google IP addresses"
   (skip-unless (not (getenv "EMACS_HYDRA_CI")))
   (let ((addresses-both (network-lookup-address-info "google.com"))
-        (addresses-v4 (network-lookup-address-info "google.com" 'ipv4))
-        (addresses-v6 (network-lookup-address-info "google.com" 'ipv6)))
+        (addresses-v4 (network-lookup-address-info "google.com" 'ipv4)))
     (should addresses-both)
-    (should addresses-v4)
-    (should addresses-v6)))
+    (should addresses-v4))
+  (when (featurep 'make-network-process '(:family ipv6))
+    (should (network-lookup-address-info "google.com" 'ipv6))))
 
 (ert-deftest non-existent-lookup-failure ()
   (skip-unless (not (getenv "EMACS_HYDRA_CI")))