Linux and the BSDs have getifaddrs(). Use it and save a bunch of complex coding.
authorJeremy Harris <jgh146exb@wizmail.org>
Wed, 17 Mar 2021 14:33:46 +0000 (14:33 +0000)
committerJeremy Harris <jgh146exb@wizmail.org>
Wed, 17 Mar 2021 14:33:46 +0000 (14:33 +0000)
src/OS/os.h-FreeBSD
src/OS/os.h-Linux
src/OS/os.h-OpenBSD
src/src/host.c
src/src/os.c

index 0083642b432c0d9879d5b41ed76bf695d105fbe1..4f135842383f086b2ae7989f229c16d3bbddc37f 100644 (file)
@@ -11,6 +11,7 @@
 #define HAVE_SETCLASSRESOURCES
 #define HAVE_MMAP
 #define HAVE_SYS_MOUNT_H
+#define HAVE_GETIFADDR
 #define SIOCGIFCONF_GIVES_ADDR
 #define HAVE_SRANDOMDEV
 #define HAVE_ARC4RANDOM
index 287e15465fbcc9c11297b2e038369057ca1da528..f2c243e9f7dc7ce356565cad88bf3c0e1ce6e311 100644 (file)
@@ -16,6 +16,7 @@ with the issue. */
 #define HAVE_MMAP
 #define HAVE_BSD_GETLOADAVG
 #define HAVE_SYS_STATVFS_H
+#define HAVE_GETIFADDRS
 #define NO_IP_VAR_H
 #define SIG_IGN_WORKS
 
index 08f2dcaa56e71cd13f565d89d504053dbde432dd..eaa2f6b1d05fbb34ca33b2f450f681a8d310e757 100644 (file)
@@ -6,6 +6,7 @@
 #define HAVE_BSD_GETLOADAVG
 #define HAVE_MMAP
 #define HAVE_SYS_MOUNT_H
+#define HAVE_GETIFADDR
 #define SIOCGIFCONF_GIVES_ADDR
 #define EXIM_HAVE_OPENAT
 #define EXIM_HAVE_FUTIMENS
index 5f254a28de0bddf7e3f98b6d7cd8b6d35f483243..6b9f674b83805e3a74c46d8913d674cc139f16c3 100644 (file)
@@ -815,7 +815,7 @@ host_find_interfaces(void)
 {
 ip_address_item *running_interfaces = NULL;
 
-if (local_interface_data == NULL)
+if (!local_interface_data)
   {
   void *reset_item = store_mark();
   ip_address_item *dlist = host_build_ifacelist(CUS local_interfaces,
index ae9c6043cdb1f81e74852acf55b116ada20658f7..9a450a8656c98fe35df7206bc9e5bb7cbf855c8e 100644 (file)
@@ -495,9 +495,11 @@ if (getifaddrs(&ifalist) != 0)
 
 for (struct ifaddrs * ifa = ifalist; ifa; ifa = ifa->ifa_next)
   {
-  if (ifa->ifa_addr->sa_family != AF_INET
+  struct sockaddr * ifa_addr = ifa->ifa_addr;
+  if (!ifa_addr) continue;
+  if (ifa_addr->sa_family != AF_INET
 #if HAVE_IPV6
-    && ifa->ifa_addr->sa_family != AF_INET6
+    && ifa_addr->sa_family != AF_INET6
 #endif /* HAVE_IPV6 */
     )
     continue;
@@ -511,9 +513,9 @@ for (struct ifaddrs * ifa = ifalist; ifa; ifa = ifa->ifa_next)
   next = store_get(sizeof(ip_address_item), FALSE);
   next->next = NULL;
   next->port = 0;
-  (void)host_ntoa(-1, ifa->ifa_addr, next->address, NULL);
+  (void)host_ntoa(-1, ifa_addr, next->address, NULL);
 
-  if (yield == NULL)
+  if (!yield)
     yield = last = next;
   else
     {