summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJeremy Harris <jgh146exb@wizmail.org>2021-03-17 14:33:46 +0000
committerJeremy Harris <jgh146exb@wizmail.org>2021-03-17 14:33:46 +0000
commit995e599afd3e6468d3396fb351ed0cd0ea212779 (patch)
tree159ceee53c1dcd922fb26336c517db74a98d31a1 /src
parent376fa78ab65917689a9eb5d4bcd44ce6e41feb35 (diff)
Linux and the BSDs have getifaddrs(). Use it and save a bunch of complex coding.
Diffstat (limited to 'src')
-rw-r--r--src/OS/os.h-FreeBSD1
-rw-r--r--src/OS/os.h-Linux1
-rw-r--r--src/OS/os.h-OpenBSD1
-rw-r--r--src/src/host.c2
-rw-r--r--src/src/os.c10
5 files changed, 10 insertions, 5 deletions
diff --git a/src/OS/os.h-FreeBSD b/src/OS/os.h-FreeBSD
index 0083642b4..4f1358423 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 287e15465..f2c243e9f 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 08f2dcaa5..eaa2f6b1d 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 5f254a28d..6b9f674b8 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 ae9c6043c..9a450a865 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
{