Skip to content

Commit 69aef13

Browse files
mobrembskiMichał Obrembski
authored andcommitted
Added Samba libreplace implementation for freeifaddrs and getifaddrs
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.
1 parent 42e9e8d commit 69aef13

7 files changed

Lines changed: 965 additions & 11 deletions

File tree

Makefile.am

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ openfortivpn_SOURCES = src/config.c src/config.h src/hdlc.c src/hdlc.h \
88
src/xml.h src/userinput.c src/userinput.h \
99
src/openssl_hostname_validation.c \
1010
src/openssl_hostname_validation.h
11+
if LIBREPLACE_REQUIRED
12+
openfortivpn_SOURCES += src/ifaddrs.c
13+
endif
14+
openfortivpn_CFLAGS = -Wall -pedantic
1115
openfortivpn_CPPFLAGS = -DSYSCONFDIR=\"$(sysconfdir)\" \
1216
-DPPP_PATH=\"@PPP_PATH@\" \
1317
-DNETSTAT_PATH=\"@NETSTAT_PATH@\" \

configure.ac

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,6 @@ AC_TYPE_UINT8_T
103103
AC_CHECK_TYPES([struct termios], [], [], [#include <termios.h>])
104104

105105
# Checks for library functions.
106-
AC_FUNC_MALLOC
107-
AC_FUNC_REALLOC
108106
AC_CHECK_FUNCS([ \
109107
access \
110108
atoi \
@@ -125,15 +123,13 @@ fputs \
125123
fread \
126124
free \
127125
freeaddrinfo \
128-
freeifaddrs \
129126
freopen \
130127
fwrite \
131128
gai_strerror \
132129
getaddrinfo \
133130
getchar \
134131
getenv \
135132
geteuid \
136-
getifaddrs \
137133
getopt_long \
138134
htons \
139135
index \
@@ -502,6 +498,44 @@ AC_ARG_WITH([resolvconf-config-file],
502498
AC_DEFINE_UNQUOTED([RESOLV_CONF_FILE_PATH],["$withval"])
503499
)
504500

501+
AC_COMPILE_IFELSE([AC_LANG_SOURCE([
502+
#include <sys/types.h>
503+
#if STDC_HEADERS
504+
#include <stdlib.h>
505+
#include <stddef.h>
506+
#endif
507+
#include <sys/socket.h>
508+
#include <netinet/in.h>
509+
#include <arpa/inet.h>
510+
#include <ifaddrs.h>
511+
#include <netdb.h>
512+
int main(int argc, char **argv){
513+
struct ifaddrs *ifp = NULL;
514+
int ret = getifaddrs (&ifp);
515+
freeifaddrs(ifp);
516+
}
517+
])], [
518+
libreplace_required=no
519+
AC_MSG_NOTICE([HAVE_IFADDRS... 1])
520+
],[
521+
libreplace_required=yes
522+
AC_MSG_NOTICE([HAVE_IFADDRS... 0])
523+
])
524+
525+
AC_ARG_ENABLE([libreplace],
526+
[AS_HELP_STRING([--enable-libreplace], [Force to use libreplace ifaddrs implementation])],
527+
[enable_libreplace=yes],
528+
[enable_libreplace=no])
529+
AS_CASE(["$enable_libreplace"],
530+
[yes], [
531+
AC_MSG_NOTICE([Force using libreplace...])
532+
],
533+
[no], [
534+
],
535+
[AC_MSG_ERROR([unknown option '$enable_libreplace' for --enable-libreplace])])
536+
AS_IF([test "x$enable_libreplace" != "xno" -o "x$libreplace_required" != "xno"], [AC_DEFINE([HAVE_IFADDRS],[0])], [AC_DEFINE([HAVE_IFADDRS],[1])])
537+
AM_CONDITIONAL([LIBREPLACE_REQUIRED], [test "x$enable_libreplace" = "xyes" -o "x$libreplace_required" = "xyes"])
538+
505539
# prepare to get rid of obsolete code (FortiOS 4)
506540
AC_ARG_ENABLE([obsolete],
507541
[AS_HELP_STRING([--disable-obsolete], [disable support for FortiOS 4])],,

0 commit comments

Comments
 (0)