Skip to content

Commit

Permalink
Added Samba libreplace implementation for freeifaddrs and getifaddrs
Browse files Browse the repository at this point in the history
In case if system doesn't provide above functions, don't fail and use
Samba project libreplace implementation.
This allows to run app on embedded systems.
  • Loading branch information
mobrembski authored and Michał Obrembski committed Jan 19, 2021
1 parent e9e6864 commit d3955c6
Show file tree
Hide file tree
Showing 7 changed files with 964 additions and 11 deletions.
3 changes: 3 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ openfortivpn_SOURCES = src/config.c src/config.h src/hdlc.c src/hdlc.h \
src/xml.h src/userinput.c src/userinput.h \
src/openssl_hostname_validation.c \
src/openssl_hostname_validation.h
if LIBREPLACE_REQUIRED
openfortivpn_SOURCES += src/ifaddrs.c
endif
openfortivpn_CFLAGS = -Wall -pedantic
openfortivpn_CPPFLAGS = -DSYSCONFDIR=\"$(sysconfdir)\" \
-DPPP_PATH=\"@PPP_PATH@\" \
Expand Down
42 changes: 38 additions & 4 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@ AC_TYPE_UINT8_T
AC_CHECK_TYPES([struct termios], [], [], [#include <termios.h>])

# Checks for library functions.
AC_FUNC_MALLOC
AC_FUNC_REALLOC
AC_CHECK_FUNCS([ \
access \
atoi \
Expand All @@ -125,15 +123,13 @@ fputs \
fread \
free \
freeaddrinfo \
freeifaddrs \
freopen \
fwrite \
gai_strerror \
getaddrinfo \
getchar \
getenv \
geteuid \
getifaddrs \
getopt_long \
htons \
index \
Expand Down Expand Up @@ -502,6 +498,44 @@ AC_ARG_WITH([resolvconf-config-file],
AC_DEFINE_UNQUOTED([RESOLV_CONF_FILE_PATH],["$withval"])
)

AC_COMPILE_IFELSE([AC_LANG_SOURCE([
#include <sys/types.h>
#if STDC_HEADERS
#include <stdlib.h>
#include <stddef.h>
#endif
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <ifaddrs.h>
#include <netdb.h>
int main(int argc, char **argv){
struct ifaddrs *ifp = NULL;
int ret = getifaddrs (&ifp);
freeifaddrs(ifp);
}
])], [
libreplace_required=no
AC_MSG_NOTICE([HAVE_IFADDRS... 1])
],[
libreplace_required=yes
AC_MSG_NOTICE([HAVE_IFADDRS... 0])
])

AC_ARG_ENABLE([libreplace],
[AS_HELP_STRING([--enable-libreplace], [Force to use libreplace ifaddrs implementation])],
[enable_libreplace=yes],
[enable_libreplace=no])
AS_CASE(["$enable_libreplace"],
[yes], [
AC_MSG_NOTICE([Force using libreplace...])
],
[no], [
],
[AC_MSG_ERROR([unknown option '$enable_libreplace' for --enable-libreplace])])
AS_IF([test "x$enable_libreplace" != "xno" -o "x$libreplace_required" != "xno"], [AC_DEFINE([HAVE_IFADDRS],[0])], [AC_DEFINE([HAVE_IFADDRS],[1])])
AM_CONDITIONAL([LIBREPLACE_REQUIRED], [test "x$enable_libreplace" = "xyes" -o "x$libreplace_required" = "xyes"])

# prepare to get rid of obsolete code (FortiOS 4)
AC_ARG_ENABLE([obsolete],
[AS_HELP_STRING([--disable-obsolete], [disable support for FortiOS 4])],,
Expand Down
Loading

0 comments on commit d3955c6

Please sign in to comment.