[exim-cvs] Linux and the BSDs have getifaddrs(). Use it and …

Páxina inicial
Borrar esta mensaxe
Responder a esta mensaxe
Autor: Exim Git Commits Mailing List
Data:  
Para: exim-cvs
Asunto: [exim-cvs] Linux and the BSDs have getifaddrs(). Use it and save a bunch of complex coding.
Gitweb: https://git.exim.org/exim.git/commitdiff/995e599afd3e6468d3396fb351ed0cd0ea212779
Commit:     995e599afd3e6468d3396fb351ed0cd0ea212779
Parent:     376fa78ab65917689a9eb5d4bcd44ce6e41feb35
Author:     Jeremy Harris <jgh146exb@???>
AuthorDate: Wed Mar 17 14:33:46 2021 +0000
Committer:  Jeremy Harris <jgh146exb@???>
CommitDate: Wed Mar 17 14:33:46 2021 +0000


        Linux and the BSDs have getifaddrs().  Use it and save a bunch of complex coding.
---
 src/OS/os.h-FreeBSD |  1 +
 src/OS/os.h-Linux   |  1 +
 src/OS/os.h-OpenBSD |  1 +
 src/src/host.c      |  2 +-
 src/src/os.c        | 10 ++++++----
 5 files changed, 10 insertions(+), 5 deletions(-)


diff --git a/src/OS/os.h-FreeBSD b/src/OS/os.h-FreeBSD
index 0083642..4f13584 100644
--- a/src/OS/os.h-FreeBSD
+++ b/src/OS/os.h-FreeBSD
@@ -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
diff --git a/src/OS/os.h-Linux b/src/OS/os.h-Linux
index 287e154..f2c243e 100644
--- a/src/OS/os.h-Linux
+++ b/src/OS/os.h-Linux
@@ -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

diff --git a/src/OS/os.h-OpenBSD b/src/OS/os.h-OpenBSD
index 08f2dca..eaa2f6b 100644
--- a/src/OS/os.h-OpenBSD
+++ b/src/OS/os.h-OpenBSD
@@ -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
diff --git a/src/src/host.c b/src/src/host.c
index 5f254a2..6b9f674 100644
--- a/src/src/host.c
+++ b/src/src/host.c
@@ -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,
diff --git a/src/src/os.c b/src/src/os.c
index ae9c604..9a450a8 100644
--- a/src/src/os.c
+++ b/src/src/os.c
@@ -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
     {