From d38eae28a90e1de54087e4cacac32f76d014ef9a Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Tue, 29 Sep 2009 16:44:59 +0200 Subject: [PATCH] Rework autoconf stuff. Update to autoconf 2.64. Use custom macro for ethtool, netsnmp and argument handling to shorten main configure.ac file. Use less verbose build process by default. For headers, missing header is fatal for now because we don't know how to replace them. Better handling will be done later. We only target Linux for now with GNU LibC: portability issues are narrow. Display results at the end of configure process. AC_C_CONST is obsolete See: http://www.nabble.com/fix-AC_C_CONST-to-work-with-CFLAGS--O2--Wall--Werror-td17164627.html http://www.gnu.org/software/autoconf/manual/autoconf.html#index-AC_005fC_005fCONST-790 Some useful documentation about autoconf: http://sources.redhat.com/autobook/ (a bit outdated) http://www.freesoftwaremagazine.com/books/autotools_a_guide_to_autoconf_automake_libtool http://www.flameeyes.eu/autotools-mythbuster/ --- configure.ac | 343 ++++++++++++++++++++++++---------------------- m4/args.m4 | 29 ++++ m4/ethtool.m4 | 48 +++++++ m4/snmp.m4 | 40 ++++++ src/Makefile.am | 3 +- src/compat.h | 18 +++ src/lldpd.h | 20 +-- src/malloc.c | 14 ++ src/priv.c | 18 ++- src/realloc.c | 15 ++ tests/Makefile.am | 12 +- 11 files changed, 374 insertions(+), 186 deletions(-) create mode 100644 m4/args.m4 create mode 100644 m4/ethtool.m4 create mode 100644 m4/snmp.m4 create mode 100644 src/malloc.c create mode 100644 src/realloc.c diff --git a/configure.ac b/configure.ac index 217fb9c3..99ca1401 100644 --- a/configure.ac +++ b/configure.ac @@ -1,196 +1,207 @@ # -*- Autoconf -*- # Process this file with autoconf to produce a configure script. -AC_PREREQ(2.61) -AC_INIT(lldpd, 0.5.0, bernat@luffy.cx) -AM_INIT_AUTOMAKE([foreign]) +####################### +### Base configuration + +# Configure autoconf +AC_PREREQ([2.64]) +AC_INIT([lldpd], [0.5.0], [bernat@luffy.cx]) AC_CONFIG_SRCDIR([src/lldpd.c]) AC_CONFIG_HEADER([config.h]) AC_CONFIG_FILES([Makefile src/Makefile man/Makefile tests/Makefile]) AC_CONFIG_MACRO_DIR([m4]) +# Configure automake +AM_INIT_AUTOMAKE([foreign -Wall -Werror]) +AM_SILENT_RULES([yes]) + +# Configure libtool +LT_PREREQ([2.2]) +LT_INIT + +####################### +### Checks + # Checks for programs. +AC_PROG_AWK AC_PROG_CC -AC_PROG_LIBTOOL +AC_PROG_CPP +AC_PROG_INSTALL +AC_PROG_LN_S +AC_PROG_MAKE_SET +AC_PROG_CXX +AC_PROG_RANLIB +AM_PROG_CC_C_O -# Unit tests -PKG_CHECK_MODULES([CHECK], [check >= 0.9.4], have_check=yes, have_check=no) -AM_CONDITIONAL(HAVE_CHECK, test x$have_check = xyes) +# Checks for header files. +AC_HEADER_RESOLV +AC_CHECK_HEADERS([ \ + arpa/inet.h \ + fcntl.h \ + malloc.h \ + netdb.h \ + netinet/in.h \ + stdlib.h \ + string.h \ + sys/ioctl.h \ + sys/param.h \ + sys/socket.h \ + sys/time.h \ + sys/queue.h \ + syslog.h \ + unistd.h \ + linux/sockios.h \ + linux/filter.h \ + net/if.h \ +],,AC_MSG_ERROR([Required header missing.])) +AC_CHECK_HEADERS([ \ + linux/wireless.h \ + linux/if_bonding.h \ + linux/if_vlan.h \ + linux/if_bridge.h \ + linux/if_packet.h \ +],,AC_MSG_ERROR([Required header missing.]),[ +@%:@include +@%:@include +]) -# Checks for libraries. -AC_ARG_WITH(snmp, - AC_HELP_STRING( - [--with-snmp], - [Enable the use of SNMP] - ), - [], - [with_snmp=no] -) -AM_CONDITIONAL([USE_SNMP], [test "${with_snmp}" != "no"]) - -AC_ARG_WITH(privsep-user, - AC_HELP_STRING([--with-privsep-user], - [Which user to use for privilege separation]), - AC_DEFINE_UNQUOTED([PRIVSEP_USER], "$withval", [User for privilege separation]), - AC_DEFINE_UNQUOTED([PRIVSEP_USER], "_lldpd", [User for privilege separation])) -AC_ARG_WITH(privsep-group, - AC_HELP_STRING([--with-privsep-group], - [Which group to use for privilege separation]), - AC_DEFINE_UNQUOTED([PRIVSEP_GROUP], "$withval", [Group for privilege separation]), - AC_DEFINE_UNQUOTED([PRIVSEP_GROUP], "_lldpd", [Group for privilege separation])) -AC_ARG_WITH(privsep-chroot, - AC_HELP_STRING([--with-privsep-chroot], - [Which directory to use to chroot lldpd]), - AC_DEFINE_UNQUOTED([PRIVSEP_CHROOT], "$withval", [Chroot directory]), - AC_DEFINE_UNQUOTED([PRIVSEP_CHROOT], "/var/run/lldpd", [Chroot directory])) -# Checks for header files. -AC_CHECK_DECLS([TAILQ_FIRST, TAILQ_NEXT, TAILQ_FOREACH, TAILQ_EMPTY],[],[],[[#include ]]) -AC_CHECK_DECLS([SLIST_HEAD, SLIST_ENTRY, SLIST_INIT, SLIST_INSERT_HEAD],[],[],[[#include ]]) -AC_CHECK_DECLS([SLIST_FIRST, SLIST_NEXT, SLIST_REMOVE_HEAD, SLIST_EMPTY],[],[],[[#include ]]) -AC_CHECK_DECLS([PACKET_ORIGDEV],[],[],[[#include ]]) -AC_CHECK_DECLS([ADVERTISED_2500baseX_Full, ADVERTISED_Pause, ADVERTISED_Asym_Pause, ADVERTISED_10000baseT_Full, SPEED_10000], - [],[],[[#include ]]) -AC_CHECK_DECLS([ETHERTYPE_VLAN],[],[],[[#include ]]) +# Check for sys/queue.h completeness, missing bits will be in compat.h +AC_CHECK_DECLS([ \ +TAILQ_FIRST, \ +TAILQ_NEXT, \ +TAILQ_FOREACH, \ +TAILQ_EMPTY, \ +SLIST_HEAD, \ +SLIST_ENTRY, \ +SLIST_INIT, \ +SLIST_INSERT_HEAD, \ +SLIST_FIRST, \ +SLIST_NEXT, \ +SLIST_REMOVE_HEAD, \ +SLIST_EMPTY \ +],[],[],[[@%:@include ]]) + +# Do we have PACKET_ORIGDEV (it can be present at runtime, put it in compat.h) +AC_CHECK_DECLS([PACKET_ORIGDEV],[],[],[[@%:@include ]]) + +# Check for ethtool stuff +lldp_CHECK_HEADER_ETHTOOL +AC_CHECK_DECLS([ \ +ADVERTISED_2500baseX_Full, \ +ADVERTISED_Pause, \ +ADVERTISED_Asym_Pause, \ +ADVERTISED_10000baseT_Full, \ +SPEED_10000 \ +],[],[],[[@%:@include ]]) + +# Check for ETHERTYPE_VLAN, put it in compat.h if not defined +AC_CHECK_DECLS([ETHERTYPE_VLAN],[],[],[[@%:@include ]]) + +# Check some stuff in linux/if_vlan.h +AC_CHECK_DECLS([ \ +GET_VLAN_REALDEV_NAME_CMD, \ +GET_VLAN_VID_CMD \ +],[],[],[[@%:@include ]]) # Checks for typedefs, structures, and compiler characteristics. -AC_C_CONST -AC_CHECK_TYPES([int16_t, u_int16_t, int8_t, u_int8_t, int32_t, u_int32_t],[],[AC_MSG_ERROR([mandatory type not found])]) -AC_CHECK_MEMBERS([netsnmp_tdomain.f_create_from_tstring_new],,, - [ -#include -#include -#include -]) +AC_TYPE_UID_T +AC_C_INLINE +AC_TYPE_INT16_T +AC_TYPE_INT32_T +AC_TYPE_PID_T +AC_TYPE_SIZE_T +AC_TYPE_SSIZE_T +AC_TYPE_UINT16_T +AC_TYPE_UINT32_T +AC_TYPE_UINT8_T # Checks for library functions. +AC_FUNC_CHOWN +AC_FUNC_FORK +AC_FUNC_MALLOC +AC_FUNC_REALLOC +AC_CHECK_FUNCS([ \ + atexit \ + gethostbyname \ + inet_ntoa memset \ + regcomp \ + select \ + setenv \ + socket \ + strchr \ + strdup \ + strerror \ + strndup \ + tzset \ + uname \ +],,[AC_MSG_ERROR(Required function not found.)]) + AC_REPLACE_FUNCS([strlcpy]) AC_REPLACE_FUNCS([getifaddrs]) -AC_PROG_GCC_TRADITIONAL +## Unit tests wich check +PKG_CHECK_MODULES([CHECK], [check >= 0.9.4], [have_check=yes], [have_check=no]) -## NetSNMP -NETSNMP_CONFIG=No -if test "${with_snmp}" != "no"; then - AC_PATH_TOOL([NETSNMP_CONFIG], [net-snmp-config], No) -fi -if test x"${NETSNMP_CONFIG}" != xNo; then - NETSNMP_libs=`${NETSNMP_CONFIG} --agent-libs` - - AC_CHECK_LIB([netsnmp], [snmp_register_callback], - AC_DEFINE_UNQUOTED([HAVE_NETSNMP], 1, [Define to indicate the Net-SNMP library]) - AC_DEFINE_UNQUOTED([USE_SNMP], 1, [Define to indicate to enable SNMP support]), - [], ${NETSNMP_libs}) - - if test "${ac_cv_lib_netsnmp_snmp_register_callback}" = "yes"; then - AC_SUBST([NETSNMP_LIB],"${NETSNMP_libs}") - fi -fi -if test "${with_snmp}" != "no"; then - if test "${ac_cv_lib_netsnmp_snmp_register_callback}" != "yes"; then - AC_MSG_NOTICE([***]) - AC_MSG_NOTICE([*** net-snmp libraries not found]) - AC_MSG_NOTICE([*** Either correct the installation, or run configure]) - AC_MSG_NOTICE([*** including --without-snmp]) - exit 1 - fi -fi +####################### +### Options -# Options -# CDP -AC_ARG_ENABLE(cdp, AC_HELP_STRING([--enable-cdp], - [Enable Cisco Discovery Protocol]), - [enable_cdp=$enableval],[enable_cdp=yes]) -AC_MSG_CHECKING(whether to enable CDP) -if test x$enable_cdp = xyes; then - AC_MSG_RESULT(yes) - AC_DEFINE([ENABLE_CDP],, [Enable Cisco Discovery Protocol]) -else - AC_MSG_RESULT(no) -fi - -# FDP -AC_ARG_ENABLE(fdp, AC_HELP_STRING([--enable-fdp], - [Enable Foundry Discovery Protocol]), - [enable_fdp=$enableval],[enable_fdp=yes]) -AC_MSG_CHECKING(whether to enable FDP) -if test x$enable_fdp = xyes; then - AC_MSG_RESULT(yes) - AC_DEFINE([ENABLE_FDP],, [Enable Foundry Discovery Protocol]) -else - AC_MSG_RESULT(no) -fi - -# EDP -AC_ARG_ENABLE(edp, AC_HELP_STRING([--enable-edp], - [Enable Extreme Discovery Protocol]), - [enable_edp=$enableval],[enable_edp=yes]) -AC_MSG_CHECKING(whether to enable EDP) -if test x$enable_edp = xyes; then - AC_MSG_RESULT(yes) - AC_DEFINE([ENABLE_EDP],, [Enable Extreme Discovery Protocol]) -else - AC_MSG_RESULT(no) -fi - -# SONMP -AC_ARG_ENABLE(sonmp, AC_HELP_STRING([--enable-sonmp], - [Enable SynOptics Network Management Protocol]), - [enable_sonmp=$enableval],[enable_sonmp=yes]) -AC_MSG_CHECKING(whether to enable SONMP) -if test x$enable_sonmp = xyes; then - AC_MSG_RESULT(yes) - AC_DEFINE([ENABLE_SONMP],, [Enable SynOptics Network Management Protocol]) -else - AC_MSG_RESULT(no) +# SNMP +AC_ARG_WITH([snmp], + AS_HELP_STRING( + [--with-snmp], + [Enable the use of SNMP @<:@default=no@:>@] + )) +if test x"$with_snmp" = x"yes"; then + lldp_CHECK_SNMP fi -#LLDPMED -AC_ARG_ENABLE(lldpmed, AC_HELP_STRING([--enable-lldpmed], - [Enable LLDP-MED extension]), - [enable_lldpmed=$enableval],[enable_lldpmed=yes]) -AC_MSG_CHECKING(whether to enable LLDP-MED) -if test x$enable_lldpmed = xyes; then - AC_MSG_RESULT(yes) - AC_DEFINE([ENABLE_LLDPMED],, [Enable LLDP-MED extension]) -else - AC_MSG_RESULT(no) -fi +# Privsep settings +lldp_ARG_WITH([privsep-user], [Which user to use for privilege separation], [_lldpd]) +lldp_ARG_WITH([privsep-group], [Which group to use for privilege separation], [_lldpd]) +lldp_ARG_WITH([privsep-chroot], [Which directory to use to chroot lldpd], [/var/run/lldpd]) -#Dot1 -AC_ARG_ENABLE(dot1, AC_HELP_STRING([--enable-dot1], - [Enable LLDP Dot1 extension]), - [enable_dot1=$enableval],[enable_dot1=yes]) -AC_MSG_CHECKING(whether to enable Dot1) -if test x$enable_dot1 = xyes; then - AC_MSG_RESULT(yes) - AC_DEFINE([ENABLE_DOT1],, [Enable LLDP Dot1 extension]) -else - AC_MSG_RESULT(no) -fi +# CDP/FDP/EDP/SONMP +lldp_ARG_ENABLE([cdp], [Cisco Discovery Protocol], [yes]) +lldp_ARG_ENABLE([fdp], [Foundry Discovery Protocol], [yes]) +lldp_ARG_ENABLE([edp], [Extreme Discovery Protocol], [yes]) +lldp_ARG_ENABLE([sonmp], [SynOptics Network Management Protocol], [yes]) -#Dot3 -AC_ARG_ENABLE(dot3, AC_HELP_STRING([--enable-dot3], - [Enable LLDP Dot3 extension]), - [enable_dot3=$enableval],[enable_dot3=yes]) -AC_MSG_CHECKING(whether to enable Dot3) -if test x$enable_dot3 = xyes; then - AC_MSG_RESULT(yes) - AC_DEFINE([ENABLE_DOT3],, [Enable LLDP Dot3 extension]) -else - AC_MSG_RESULT(no) -fi +# LLDPMED/Dot1/Dot3 +lldp_ARG_ENABLE([lldpmed], [LLDP-MED extension], [yes]) +lldp_ARG_ENABLE([dot1], [Dot1 extension (VLAN stuff)], [yes]) +lldp_ARG_ENABLE([dot3], [Dot3 extension (PHY stuff)], [yes]) #Listen on vlan -AC_ARG_ENABLE(listenvlan, AC_HELP_STRING([--enable-listenvlan], - [Allow to listen on VLAN]), - [enable_listenvlan=$enableval],[enable_listenvlan=no]) -AC_MSG_CHECKING(whether to allow to listen on VLAN) -if test x$enable_listenvlan = xyes; then - AC_MSG_RESULT(yes) - AC_DEFINE([ENABLE_LISTENVLAN],, [Allow to listen on VLAN]) -else - AC_MSG_RESULT(no) -fi +lldp_ARG_ENABLE([listenvlan], [listen on any VLAN], [no]) +####################### +# Output results +AM_CONDITIONAL([HAVE_CHECK], [test x"$have_check" = x"yes"]) +AM_CONDITIONAL([USE_SNMP], [test x"$with_snmp" = x"yes"]) AC_OUTPUT + +cat <@]), + AC_DEFINE_UNQUOTED(AS_TR_CPP([$1]), ["$withval"], [$2]), + AC_DEFINE_UNQUOTED(AS_TR_CPP([$1]), ["$3"], [$2])) +]) + +dnl lldp_ARG_ENABLE(name, help1, default) + +AC_DEFUN([lldp_ARG_ENABLE],[ + AC_ARG_ENABLE([$1], + AS_HELP_STRING([--enable-$1], + [Enable $2 @<:@default=$3@:>@]), + [enable_$1=$enableval], [enable_$1=$3]) + AC_MSG_CHECKING(whether to enable $2) + if test x"$enable_$1" = x"yes"; then + AC_MSG_RESULT(yes) + AC_DEFINE([ENABLE_]AS_TR_CPP([$1]),, [$2]) + else + AC_MSG_RESULT(no) + fi +]) diff --git a/m4/ethtool.m4 b/m4/ethtool.m4 new file mode 100644 index 00000000..f3efa9d1 --- /dev/null +++ b/m4/ethtool.m4 @@ -0,0 +1,48 @@ +# +# lldp_CHECK_HEADER_ETHTOOL +# +AC_DEFUN([lldp_CHECK_HEADER_ETHTOOL], [ + AC_CACHE_CHECK([for linux/ethtool.h], mac_cv_header_ethtool_h, [ + AC_COMPILE_IFELSE([ + AC_LANG_SOURCE([ +AC_INCLUDES_DEFAULT +@%:@include + ]) + ], [mac_cv_header_ethtool_h=yes], [mac_cv_header_ethtool_h=no] + ) + if test "$mac_cv_header_ethtool_h" = no; then + AC_COMPILE_IFELSE([ + AC_LANG_SOURCE([ +AC_INCLUDES_DEFAULT +@%:@define u8 uint8_t +@%:@define s8 int8_t +@%:@define u16 uint16_t +@%:@define s16 int16_t +@%:@define u32 uint32_t +@%:@define s32 int32_t +@%:@define u64 uint64_t +@%:@define s64 int64_t +@%:@include + ]) + ], + [mac_cv_header_ethtool_h="yes (with type munging)"], + [mac_cv_header_ethtool_h=no] + ) + ]) + fi + if test "$mac_cv_header_ethtool_h" = "yes (with type munging)"; then + AC_DEFINE(u8, uint8_t, [Define to the type u8 should expand to.]) + AC_DEFINE(s8, int8_t, [Define to the type u8 should expand to.]) + AC_DEFINE(u16, uint16_t, [Define to the type u16 should expand to.]) + AC_DEFINE(s16, int16_t, [Define to the type u16 should expand to.]) + AC_DEFINE(u32, uint32_t, [Define to the type u32 should expand to.]) + AC_DEFINE(s32, int32_t, [Define to the type u32 should expand to.]) + AC_DEFINE(u64, uint64_t, [Define to the type u64 should expand to.]) + AC_DEFINE(s64, int64_t, [Define to the type u64 should expand to.]) + fi + if test "$mac_cv_header_ethtool_h" = no; then + : + else + AC_DEFINE(HAVE_ETHTOOL_H, 1, [Define to 1 if you have the header file.]) + fi +]) diff --git a/m4/snmp.m4 b/m4/snmp.m4 new file mode 100644 index 00000000..f3295bc2 --- /dev/null +++ b/m4/snmp.m4 @@ -0,0 +1,40 @@ +# +# lldp_CHECK_SNMP +# + + +AC_DEFUN([lldp_CHECK_SNMP], [ + AC_PATH_TOOL([NETSNMP_CONFIG], [net-snmp-config], [no]) + if test x"$NETSNMP_CONFIG" = x"no"; then + AC_MSG_ERROR([*** unable to find net-snmp-config]) + fi + NETSNMP_LIBS=`${NETSNMP_CONFIG} --agent-libs` + NETSNMP_CFLAGS=`${NETSNMP_CONFIG} --base-cflags` + + _save_flags="$CFLAGS" + CFLAGS="$CFLAGS ${NETSNMP_CFLAGS}" + AC_MSG_CHECKING([whether C compiler supports flag "${NETSNMP_CFLAGS}" from Net-SNMP]) + AC_LINK_IFELSE([AC_LANG_PROGRAM([ +int main(void); +], +[ +{ + return 0; +} +])],[AC_MSG_RESULT(yes)],[ +AC_MSG_RESULT(no) +AC_MSG_ERROR([*** incorrect CFLAGS from net-snmp-config])]) + AC_CHECK_LIB([netsnmp], [snmp_register_callback], [], + [AC_MSG_ERROR([*** unable to use net-snmp])], ${NETSNMP_LIBS}) + AC_SUBST([NETSNMP_LIBS]) + AC_SUBST([NETSNMP_CFLAGS]) + AC_DEFINE_UNQUOTED([USE_SNMP], 1, [Define to indicate to enable SNMP support]) + AC_CHECK_MEMBERS([netsnmp_tdomain.f_create_from_tstring_new],,, + [ +@%:@include +@%:@include +@%:@include +]) + + CFLAGS="$_save_flags" +]) diff --git a/src/Makefile.am b/src/Makefile.am index ac988ee2..65d7b6a4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -21,5 +21,6 @@ lldpctl_LDADD = libcommon.la ## With SNMP... if USE_SNMP liblldpd_la_SOURCES += agent.c agent_priv.c -lldpd_LDADD += @NETSNMP_LIB@ +liblldpd_la_CFLAGS = @NETSNMP_CFLAGS@ +lldpd_LDADD += @NETSNMP_LIBS@ endif diff --git a/src/compat.h b/src/compat.h index 4458a4ae..3f5823de 100644 --- a/src/compat.h +++ b/src/compat.h @@ -121,6 +121,16 @@ struct { \ #define ETHERTYPE_VLAN 0x8100 #endif +#if !HAVE_DECL_GET_VLAN_REALDEV_NAME_CMD +#include +#define GET_VLAN_REALDEV_NAME_CMD (SET_VLAN_FLAG_CMD + 1) +#endif + +#if !HAVE_DECL_GET_VLAN_VID_CMD +#include +#define GET_VLAN_VID_CMD (GET_VLAN_REALDEV_NAME_CMD + 1) +#endif + #if !HAVE_GETIFADDRS struct ifaddrs { struct ifaddrs *ifa_next; /* Next item in list */ @@ -154,3 +164,11 @@ void freeifaddrs(struct ifaddrs *ifa); #if !HAVE_STRLCPY size_t strlcpy(char *, const char *, size_t); #endif + +#if !HAVE_MALLOC +void *malloc(size_t size); +#endif + +#if !HAVE_REALLOC +void *realloc(void *ptr, size_t size); +#endif diff --git a/src/lldpd.h b/src/lldpd.h index f0af0341..7ec53642 100644 --- a/src/lldpd.h +++ b/src/lldpd.h @@ -18,22 +18,24 @@ #define _LLDPD_H #if HAVE_CONFIG_H - #include +# include #endif #define _GNU_SOURCE 1 #include #include #include +#ifdef HAVE_SYS_TYPES_H +# include +#endif #ifndef INCLUDE_LINUX_IF_H -#include +# include #else -#include -#include -#include +# include +# include #endif #if HAVE_GETIFADDRS -#include +# include #endif #include #include @@ -43,13 +45,13 @@ #include "compat.h" #include "lldp.h" #if defined (ENABLE_CDP) || defined (ENABLE_FDP) -#include "cdp.h" +# include "cdp.h" #endif #ifdef ENABLE_SONMP -#include "sonmp.h" +# include "sonmp.h" #endif #ifdef ENABLE_EDP -#include "edp.h" +# include "edp.h" #endif #define SYSFS_CLASS_NET "/sys/class/net/" diff --git a/src/malloc.c b/src/malloc.c new file mode 100644 index 00000000..8ff490aa --- /dev/null +++ b/src/malloc.c @@ -0,0 +1,14 @@ +/* malloc replacement that can allocate 0 byte */ + +#undef malloc +#include +#include + +/* Allocate an N-byte block of memory from the heap. + If N is zero, allocate a 1-byte block. */ +void * +rpl_malloc(size_t n) +{ + if (n == 0) n = 1; + return malloc (n); +} diff --git a/src/priv.c b/src/priv.c index 3ab45d5d..1129e375 100644 --- a/src/priv.c +++ b/src/priv.c @@ -24,10 +24,8 @@ #include #include #include -#include #include #include -#include #include #include #include @@ -39,8 +37,20 @@ #include #include #include -#include -#include + +/* Use resolv.h */ +#ifdef HAVE_SYS_TYPES_H +# include +#endif +#ifdef HAVE_NETINET_IN_H +# include +#endif +#ifdef HAVE_ARPA_NAMESER_H +# include /* DNS HEADER struct */ +#endif +#ifdef HAVE_NETDB_H +# include +#endif #include enum { diff --git a/src/realloc.c b/src/realloc.c new file mode 100644 index 00000000..8a89d4b3 --- /dev/null +++ b/src/realloc.c @@ -0,0 +1,15 @@ +/* realloc replacement that can reallocate 0 byte or NULL pointers*/ + +#undef realloc +#include +#include + +/* Reallocate an N-byte block of memory from the heap. + If N is zero, allocate a 1-byte block. */ +void * +rpl_realloc(void *ptr, size_t n) +{ + if (!ptr) return malloc(n); + if (n == 0) n = 1; + return realloc(ptr, n); +} diff --git a/tests/Makefile.am b/tests/Makefile.am index 683dfe95..6feece40 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -40,12 +40,12 @@ check_ifaddrs_CFLAGS = @CHECK_CFLAGS@ check_ifaddrs_LDADD = $(top_builddir)/src/liblldpd.la @CHECK_LIBS@ if USE_SNMP -check_pack_LDADD += @NETSNMP_LIB@ -check_lldp_LDADD += @NETSNMP_LIB@ -check_cdp_LDADD += @NETSNMP_LIB@ -check_sonmp_LDADD += @NETSNMP_LIB@ -check_edp_LDADD += @NETSNMP_LIB@ -check_ifaddrs_LDADD += @NETSNMP_LIB@ +check_pack_LDADD += @NETSNMP_LIBS@ +check_lldp_LDADD += @NETSNMP_LIBS@ +check_cdp_LDADD += @NETSNMP_LIBS@ +check_sonmp_LDADD += @NETSNMP_LIBS@ +check_edp_LDADD += @NETSNMP_LIBS@ +check_ifaddrs_LDADD += @NETSNMP_LIBS@ endif endif -- 2.39.5