diff options
author | Valery Ivanov <ivalery111@gmail.com> | 2023-04-16 13:11:44 +0300 |
---|---|---|
committer | Valery Ivanov <ivalery111@gmail.com> | 2023-05-02 10:14:44 +0300 |
commit | b19e727ab52d4cd1c54f725c7d30e0c3db669c36 (patch) | |
tree | c3ef7dd1dc74a1eeed615732e04379198f0a5ed4 | |
parent | 19979c4541ddcc817c64ea911a309ee71a8cc250 (diff) | |
download | libnet-b19e727ab52d4cd1c54f725c7d30e0c3db669c36.tar.gz |
tests: fetch header/packet without advanced mode
Sometimes it's necessary to obtain a header or packet for unit testing. This
possible only in advanced mode. The advanced mode requires sudo. This
limitation is not necessary for unit testing.
Signed-off-by: Valery Ivanov <ivalery111@gmail.com>
-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) |