*** ./lib/helper.c.ORIG	Sat Apr  5 22:04:40 2014
--- ./lib/helper.c	Sat Apr  5 22:05:06 2014
***************
*** 35,41 ****
--- 35,45 ----
  #include <sys/ioctl.h>  /* For TIOCNOTTY */
  
  #include <stdlib.h>
+ #if defined(_AIX) && !defined(_AIX52)
+ #include <inttypes.h>
+ #else
  #include <stdint.h>
+ #endif
  #include <stdio.h>
  #include <inttypes.h>
  #include <signal.h>

--- ./src/plugins/ipmi_intf.c.orig      2020-08-07 01:08:52 +0000
+++ ./src/plugins/ipmi_intf.c   2020-08-07 01:09:51 +0000
@@ -45,8 +45,12 @@
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
+#ifndef _AIX
 #include <ifaddrs.h>
 #include <unistd.h>
+#else
+#include "getifaddrs_aix.c"
+#endif
 #include <netdb.h>
 #endif

--- ./src/plugins/getifaddrs_aix.c.orig	2020-08-06 05:50:35 +0000
+++ ./src/plugins/getifaddrs_aix.c	2020-08-06 05:50:18 +0000
@@ -0,0 +1,207 @@
+/*
+ * Use of this source code is governed by the below BSD-2-Clause license
+ *
+ * Copyright (c) 2020, Ayappan Perumal. All rights reserved. 
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *	@(#)getifaddrs_aix.c	1.0
+ */
+
+#include <string.h>
+#include <sys/ioctl.h>
+#include <stdlib.h>
+#include <net/if.h>
+#include "ifaddrs.h"
+#include <unistd.h>
+
+int getifaddrs(struct ifaddrs **ifap)
+{
+    char *buf;
+    int fd4, fd6, fd;
+    unsigned i;
+    int ifconf_size;
+    int ifsize;
+    sa_family_t ifr_af;
+    struct ifconf ifc;
+    struct ifreq *ifrp=NULL;
+    struct ifreq ifr4;
+    struct in6_ifreq ifr6;
+    struct ifaddrs *curif, *lastif;
+
+
+    if ((fd4 = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
+        return -1;
+    }
+    if ((fd6 = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
+        close(fd4);
+        return -1;
+    }
+
+    if (ioctl(fd4, SIOCGSIZIFCONF, &ifconf_size) < 0)
+        goto fail;
+
+    ifc.ifc_len = ifconf_size;
+    buf = calloc(1, ifconf_size);
+    ifc.ifc_buf = buf;
+
+    if (ioctl(fd4, SIOCGIFCONF, &ifc) < 0) {
+        free(buf);
+        close(fd4);
+        close(fd6);
+        return -1;
+    }
+
+    ifrp = ifc.ifc_req;
+
+    i = ifc.ifc_len;
+
+    *ifap = NULL;
+    lastif = NULL;
+
+    /* Loop through all the available interfaces */
+    while (i > 0)
+    {
+		ifsize = sizeof(struct ifreq);
+
+		if (ifrp->ifr_addr.sa_len > sizeof(ifrp->ifr_ifru)) {
+			ifsize += ifrp->ifr_addr.sa_len - sizeof(ifrp->ifr_ifru);
+		}
+
+		strncpy(ifr4.ifr_name, ifrp->ifr_name, sizeof(ifr4.ifr_name));
+		strncpy(ifr6.ifr_name, ifrp->ifr_name, sizeof(ifr6.ifr_name));
+		ifr_af = ifrp->ifr_addr.sa_family;
+
+		if (ifr_af != AF_INET && ifr_af != AF_INET6)
+			goto next;
+
+		fd = (ifr_af == AF_INET ? fd4 : fd6);
+
+        /* Get interface flags */
+		if (ioctl(fd, SIOCGIFFLAGS, &ifr4) < 0)
+			goto fail;
+
+		if (!(ifr4.ifr_flags & IFF_UP)) {
+			goto next;
+		}
+
+		curif = calloc(1, sizeof (struct ifaddrs));
+		if (curif == NULL)
+			goto fail;
+
+		if (lastif != NULL) {
+			lastif->ifa_next = curif;
+		} else {
+			*ifap = curif;
+		}
+		lastif = curif;
+
+		curif->ifa_flags = ifr4.ifr_flags;
+		if ((curif->ifa_name = strdup(ifrp->ifr_name)) == NULL)
+			goto fail;
+
+        /* Store interface address */
+		curif->ifa_addr = calloc(1, sizeof(struct sockaddr_storage));
+        if (curif->ifa_addr == NULL)
+            goto fail;
+        memcpy(curif->ifa_addr, &ifrp->ifr_addr, sizeof(struct sockaddr_storage));
+
+		/* Get netmask */
+		if (ifr_af == AF_INET) {
+			if (ioctl(fd, SIOCGIFNETMASK, &ifr4) < 0) {
+				goto fail;
+			}
+            curif->ifa_netmask = calloc(1, sizeof(struct sockaddr_storage));
+            if (curif->ifa_netmask == NULL)
+                goto fail;
+            memcpy(curif->ifa_netmask, &ifr4.ifr_addr, sizeof(struct sockaddr_storage));
+		} else {
+			if (ioctl(fd, SIOCGIFNETMASK6, &ifr6) < 0) {
+				goto fail;
+			}
+            curif->ifa_netmask = calloc(1, sizeof(struct sockaddr_storage));
+            if (curif->ifa_netmask == NULL)
+                goto fail;
+            memcpy(curif->ifa_netmask, &ifr6.ifr_Addr, sizeof(struct sockaddr_storage));
+		}
+
+		/* Get destination address for P2P interface */
+		if (curif->ifa_flags & IFF_POINTOPOINT) {
+			if (ifr_af == AF_INET) {
+				if (ioctl(fd, SIOCGIFDSTADDR, &ifr4) < 0) {
+					goto fail;
+                }
+                curif->ifa_dstaddr = calloc(1, sizeof(struct sockaddr_storage));
+                if (curif->ifa_dstaddr == NULL)
+                    goto fail;
+                memcpy(curif->ifa_dstaddr, &ifr4.ifr_addr, sizeof(struct sockaddr_storage));
+			} else {
+				if (ioctl(fd, SIOCGIFDSTADDR6, &ifr6) < 0) {
+					goto fail;
+                }
+                curif->ifa_dstaddr = calloc(1, sizeof(struct sockaddr_storage));
+                if (curif->ifa_dstaddr == NULL)
+                    goto fail;
+                memcpy(curif->ifa_dstaddr, &ifr6.ifr_Addr, sizeof(struct sockaddr_storage));
+			}
+
+        /* Get broadcast address (only for IPv4) */
+		} else if ((curif->ifa_flags & IFF_BROADCAST) && (ifr_af == AF_INET)) {
+			if (ioctl(fd, SIOCGIFBRDADDR, &ifr4) < 0) {
+				goto fail;
+            }
+            curif->ifa_broadaddr = calloc(1, sizeof(struct sockaddr_storage));
+            if (curif->ifa_broadaddr == NULL)
+                goto fail;
+            memcpy(curif->ifa_broadaddr, &ifr4.ifr_addr, sizeof(struct sockaddr_storage));
+		}
+next:
+        ifrp = (struct ifreq*)((char*)ifrp + ifsize);
+		i -= ifsize;
+	}
+
+	free(buf);
+	close(fd4);
+	close(fd6);
+	return 0;
+fail:
+	free(buf);
+	freeifaddrs(*ifap);
+	*ifap = NULL;
+	close(fd4);
+	close(fd6);
+	return -1;
+}
+
+void freeifaddrs(struct ifaddrs *ifa)
+{
+    struct ifaddrs *curif;
+
+    while (ifa != NULL) {
+        curif = ifa; 
+        ifa = ifa->ifa_next;
+        free(curif->ifa_name);
+        free(curif->ifa_addr);
+        free(curif->ifa_netmask);
+        free(curif->ifa_dstaddr);
+        free(curif);
+    }
+}
--- ./src/plugins/ifaddrs.h.orig	2020-08-07 01:13:58 +0000
+++ ./src/plugins/ifaddrs.h	2020-08-07 01:13:35 +0000
@@ -0,0 +1,67 @@
+/*
+ * Use of this source code is governed by the below BSD-2-Clause license
+ *
+ * Copyright (c) 2020, Ayappan Perumal. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *      @(#)ifaddrs.h   1.0
+ */
+
+#ifndef AIX_IFADDRS_H
+#define AIX_IFADDRS_H
+
+#include <sys/socket.h>
+#include <net/if.h>
+#include <netinet/in6_var.h>
+
+#undef  ifa_dstaddr
+#undef  ifa_broadaddr
+
+struct ifaddrs {
+    struct ifaddrs  *ifa_next;    /* Next item in list */
+    char            *ifa_name;    /* Name of interface */
+    unsigned int     ifa_flags;   /* Flags from SIOCGIFFLAGS */
+    struct sockaddr *ifa_addr;    /* Address of interface */
+    struct sockaddr *ifa_netmask; /* Netmask of interface */
+    union {
+        struct sockaddr *ifu_broadaddr;
+        struct sockaddr *ifu_dstaddr;
+    } ifa_ifu;
+#define ifa_broadaddr ifa_ifu.ifu_broadaddr /* Broadcast address of non-P2P interface */
+#define ifa_dstaddr   ifa_ifu.ifu_dstaddr   /* Destination address of P2P interface*/
+    void            *ifa_data;    /* Address-specific data */
+};
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern int getifaddrs (struct ifaddrs **);
+
+extern void freeifaddrs (struct ifaddrs *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // AIX_IFADDRS_H
+
