Skip to content

Commit a684511

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 2090067 commit a684511

5 files changed

Lines changed: 924 additions & 7 deletions

File tree

Makefile.am

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ 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
1114
openfortivpn_CFLAGS = -Wall -pedantic
1215
openfortivpn_CPPFLAGS = -DSYSCONFDIR=\"$(sysconfdir)\" \
1316
-DPPP_PATH=\"@PPP_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 \
@@ -498,6 +494,44 @@ AC_ARG_WITH([resolvconf-config-file],
498494
AC_DEFINE_UNQUOTED([RESOLV_CONF_FILE_PATH],["$withval"])
499495
)
500496

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

0 commit comments

Comments
 (0)