]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
libnet: work around older libnet type difference 2143/head
authorVictor Julien <victor@inliniac.net>
Wed, 8 Jun 2016 14:58:55 +0000 (16:58 +0200)
committerVictor Julien <victor@inliniac.net>
Wed, 8 Jun 2016 14:58:55 +0000 (16:58 +0200)
Older libnet 1.1.x have a non-const type for libnet_init's dev
argument.

configure.ac
src/respond-reject-libnet11.c

index 91bb331aef5298ad21790d1cb9e2efc6351b7ef9..d553ff3532e74580c021efb12858619b497ad44e 100644 (file)
                 [],
                 [AC_DEFINE([HAVE_LIBNET_CAPABILITIES],[1], (libnet_have_capabilities_patch))],
                 [AC_DEFINE([HAVE_LIBNET_CAPABILITIES],[1], (libnet_have_capabilities_patch))])
+
+
+            # check if the argument to libnet_init is char* or const char*
+            AC_MSG_CHECKING([libnet_init dev type])
+            STORECFLAGS="${CFLAGS}"
+            if test `basename $CC` = "clang"; then
+                CFLAGS="${CFLAGS} -Werror=incompatible-pointer-types"
+            else
+                CFLAGS="${CFLAGS} -Werror"
+            fi
+            AC_COMPILE_IFELSE(
+                [AC_LANG_PROGRAM(
+                    [
+                    #include <stdio.h>
+                    #include <libnet.h>
+                    ],
+                    [[
+                    const char dev[32] = "";
+                    char ebuf[LIBNET_ERRBUF_SIZE];
+                    (void)libnet_init(LIBNET_LINK, dev, ebuf);
+                    ]])],
+                [libnet_init_const="yes"],
+                [libnet_init_const="no"])
+            AC_MSG_RESULT($libnet_init_const)
+            if test "x$libnet_init_const" = "xyes"; then
+                AC_DEFINE([HAVE_LIBNET_INIT_CONST], [1], [libnet_init takes const argument])
+            fi
+            CFLAGS="${STORECFLAGS}"
         fi
     else
         AC_MSG_RESULT(no)
index c52e340c5b65306a275b880fed4faf2a1dfb3abf..ae238db873ddba37b375378a640faacf4c9bd7ca 100644 (file)
 
 #ifdef HAVE_LIBNET11
 
+#ifndef HAVE_LIBNET_INIT_CONST
+#define LIBNET_INIT_CAST (char *)
+#else
+#define LIBNET_INIT_CAST
+#endif
+
 /** set to true in main if we're setting caps. We need it here if we're using
   * reject rules as libnet 1.1 is not compatible with caps. */
 extern int sc_set_caps;
@@ -91,7 +97,7 @@ int RejectSendLibnet11L3IPv4TCP(ThreadVars *tv, Packet *p, void *data, int dir)
         devname = p->livedev->dev;
         SCLogDebug("Will emit reject packet on dev %s", devname);
     }
-    if ((c = libnet_init(LIBNET_RAW4, devname, ebuf)) == NULL) {
+    if ((c = libnet_init(LIBNET_RAW4, LIBNET_INIT_CAST devname, ebuf)) == NULL) {
         SCLogError(SC_ERR_LIBNET_INIT,"libnet_init failed: %s", ebuf);
         return 1;
     }
@@ -216,7 +222,7 @@ int RejectSendLibnet11L3IPv4ICMP(ThreadVars *tv, Packet *p, void *data, int dir)
     if (IS_SURI_HOST_MODE_SNIFFER_ONLY(host_mode) && (p->livedev)) {
         devname = p->livedev->dev;
     }
-    if ((c = libnet_init(LIBNET_RAW4, devname, ebuf)) == NULL) {
+    if ((c = libnet_init(LIBNET_RAW4, LIBNET_INIT_CAST devname, ebuf)) == NULL) {
         SCLogError(SC_ERR_LIBNET_INIT,"libnet_inint failed: %s", ebuf);
         return 1;
     }
@@ -302,7 +308,7 @@ int RejectSendLibnet11L3IPv6TCP(ThreadVars *tv, Packet *p, void *data, int dir)
     if (IS_SURI_HOST_MODE_SNIFFER_ONLY(host_mode) && (p->livedev)) {
         devname = p->livedev->dev;
     }
-    if ((c = libnet_init(LIBNET_RAW6, devname, ebuf)) == NULL) {
+    if ((c = libnet_init(LIBNET_RAW6, LIBNET_INIT_CAST devname, ebuf)) == NULL) {
         SCLogError(SC_ERR_LIBNET_INIT,"libnet_init failed: %s", ebuf);
         return 1;
     }
@@ -428,7 +434,7 @@ int RejectSendLibnet11L3IPv6ICMP(ThreadVars *tv, Packet *p, void *data, int dir)
     if (IS_SURI_HOST_MODE_SNIFFER_ONLY(host_mode) && (p->livedev)) {
         devname = p->livedev->dev;
     }
-    if ((c = libnet_init(LIBNET_RAW6, devname, ebuf)) == NULL) {
+    if ((c = libnet_init(LIBNET_RAW6, LIBNET_INIT_CAST devname, ebuf)) == NULL) {
         SCLogError(SC_ERR_LIBNET_INIT,"libnet_inint failed: %s", ebuf);
         return 1;
     }