diff options
-rw-r--r-- | configure.ac | 3 | ||||
-rw-r--r-- | src/libnet_advanced.c | 12 |
2 files changed, 15 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac index f1c592e..4f54428 100644 --- a/configure.ac +++ b/configure.ac @@ -185,6 +185,9 @@ AC_ARG_ENABLE([tests], ) AC_MSG_RESULT([$enable_tests]) AM_CONDITIONAL([ENABLE_TESTS], [test "$enable_tests" = "yes"]) +AS_IF([test "$enable_tests" = "yes"], [ + AC_DEFINE(LIBNET_ENABLE_TESTS, 1, [Useful define for testing purposes.]) +]) # what (not) to do if the user disables shared libraries AM_CONDITIONAL([COND_SHARED], [test "x$enable_shared" != xno]) diff --git a/src/libnet_advanced.c b/src/libnet_advanced.c index fb22ec6..5a3a610 100644 --- a/src/libnet_advanced.c +++ b/src/libnet_advanced.c @@ -38,12 +38,18 @@ libnet_adv_cull_packet(libnet_t *l, uint8_t **packet, uint32_t *packet_s) *packet = NULL; *packet_s = 0; +#ifdef LIBNET_ENABLE_TESTS + /* + * Allow to fetch the packet without advanced mode. Useful for unit tests. + */ +#else if (l->injection_type != LIBNET_LINK_ADV) { snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, "%s(): advanced link mode not enabled", __func__); return (-1); } +#endif /* checksums will be written in */ return (libnet_pblock_coalesce(l, packet, packet_s)); @@ -58,12 +64,18 @@ libnet_adv_cull_header(libnet_t *l, libnet_ptag_t ptag, uint8_t **header, *header = NULL; *header_s = 0; +#ifdef LIBNET_ENABLE_TESTS + /* + * Allow to fetch the packet's header without advanced mode. Useful for unit tests. + */ +#else if (l->injection_type != LIBNET_LINK_ADV) { snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, "%s(): advanced link mode not enabled", __func__); return (-1); } +#endif p = libnet_pblock_find(l, ptag); if (p == NULL) |