Compare commits
15 commits
feat/trace
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
93857f1ab0 | ||
|
|
b75f2964e5 | ||
|
|
dccdca8114 | ||
|
|
0502b9a291 | ||
|
|
75cfaa1f43 | ||
|
|
259b898324 | ||
|
|
825bc1e3c0 | ||
|
|
459b5ac959 | ||
|
|
13cc7071ee | ||
|
|
c26de0b725 | ||
|
|
381f3bd159 | ||
|
|
7a76ff8d2a | ||
|
|
606069df82 | ||
|
|
4b4750cb59 | ||
|
|
ce8883d6cd |
39 changed files with 675 additions and 520 deletions
2
LICENSE
2
LICENSE
|
|
@ -652,7 +652,7 @@ Also add information on how to contact you by electronic and paper mail.
|
||||||
If the program does terminal interaction, make it output a short
|
If the program does terminal interaction, make it output a short
|
||||||
notice like this when it starts in an interactive mode:
|
notice like this when it starts in an interactive mode:
|
||||||
|
|
||||||
<program> Copyright (C) <year> <name of author>
|
net-tools Copyright (C) 2026 lohhiiccc
|
||||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||||
This is free software, and you are welcome to redistribute it
|
This is free software, and you are welcome to redistribute it
|
||||||
under certain conditions; type `show c' for details.
|
under certain conditions; type `show c' for details.
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,10 @@
|
||||||
ACLOCAL_AMFLAGS = -I m4
|
ACLOCAL_AMFLAGS = -I m4
|
||||||
|
|
||||||
|
if BUILD_BUNDLED_LIBCLI
|
||||||
SUBDIRS = libcli src
|
SUBDIRS = libcli src
|
||||||
|
else
|
||||||
|
SUBDIRS = src
|
||||||
|
endif
|
||||||
|
|
||||||
if BUILD_TESTS
|
if BUILD_TESTS
|
||||||
SUBDIRS += tests
|
SUBDIRS += tests
|
||||||
|
|
|
||||||
36
README.md
36
README.md
|
|
@ -41,18 +41,21 @@ ft_ping - Send ICMP ECHO_REQUEST to network hosts
|
||||||
Usage: ft_ping [options] <destination>
|
Usage: ft_ping [options] <destination>
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
-h, --help Display this help and exit
|
-h, --help Display this help and exit
|
||||||
-V, --version Display version information and exit
|
-V, --version Display version information and exit
|
||||||
-v, --verbose Verbose output
|
-v, --verbose Verbose output
|
||||||
-q, --quiet Quiet mode (only show summary)
|
-q, --quiet Quiet mode (only show summary)
|
||||||
-c, --count <NUM> Stop after sending N packets
|
-c, --count <NUM> Stop after sending N packets
|
||||||
-i, --interval <SEC> Wait N seconds between packets
|
-i, --interval <SEC> Wait N seconds between packets
|
||||||
-t, --ttl <TTL> Set Time To Live
|
-T, --tos <NUM> Set Type of Service (TOS)
|
||||||
-s, --size <SIZE> Packet size in bytes
|
-t, --ttl <TTL> Set Time To Live
|
||||||
-W, --timeout <SEC> Timeout for replies in seconds
|
-s, --size <SIZE> Packet size in bytes
|
||||||
-w, --deadline <SEC> Exit after N seconds regardless of packets sent/received
|
-W, --linger <SEC> Timeout for replies in seconds
|
||||||
-f, --flood Flood mode
|
-w, --timeout <SEC> Exit after N seconds regardless of packets sent/received
|
||||||
-M, --dont-fragment Set the Don't Fragment bit
|
-f, --flood Flood mode
|
||||||
|
-M, --dont-fragment Set the Don't Fragment bit
|
||||||
|
-l, --preload <NUM> Send N packets in burst before normal loop
|
||||||
|
-p, --pattern <HEX> Fill packet payload with hex pattern
|
||||||
```
|
```
|
||||||
|
|
||||||
## Modules
|
## Modules
|
||||||
|
|
@ -62,7 +65,7 @@ Handles everything ICMP at the socket level: open a raw socket, build and
|
||||||
send echo requests, receive and parse replies. No loop, no display. Just a
|
send echo requests, receive and parse replies. No loop, no display. Just a
|
||||||
clean interface over the kernel socket.
|
clean interface over the kernel socket.
|
||||||
|
|
||||||
### src/cli
|
### libcli
|
||||||
Shared CLI parsing layer used by all binaries. Provides a generic getopt
|
Shared CLI parsing layer used by all binaries. Provides a generic getopt
|
||||||
wrapper and primitive parsers (int, float) that each binary plugs into.
|
wrapper and primitive parsers (int, float) that each binary plugs into.
|
||||||
|
|
||||||
|
|
@ -83,9 +86,10 @@ Manages timing and signals. Installs SIGALRM (triggers send) and SIGINT
|
||||||
Signal handlers only write a flag -- the loop does the actual work.
|
Signal handlers only write a flag -- the loop does the actual work.
|
||||||
|
|
||||||
### src/ping/tracker
|
### src/ping/tracker
|
||||||
A 128-slot circular buffer indexed by (seq % 128). Records when each
|
A bitmap over the full 16-bit sequence space (UINT16_MAX bits). Marks
|
||||||
packet was sent and marks it when a reply arrives. Used to compute RTT
|
each sequence number when a reply arrives and detects duplicates. Send
|
||||||
and detect duplicates.
|
timestamps are not stored here — RTT is computed from a timestamp
|
||||||
|
embedded at the start of the payload.
|
||||||
|
|
||||||
### src/ping/stats
|
### src/ping/stats
|
||||||
Accumulates RTT samples (min, max, sum, sum of squares) in nanoseconds.
|
Accumulates RTT samples (min, max, sum, sum of squares) in nanoseconds.
|
||||||
|
|
|
||||||
13
autogen.sh
13
autogen.sh
|
|
@ -2,14 +2,5 @@
|
||||||
# autogen.sh - Generate Autotools build files
|
# autogen.sh - Generate Autotools build files
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
mkdir -pv m4 build-aux
|
||||||
# Generate libcli configure first (it's an Autotools submodule)
|
autoreconf -f --install --verbose
|
||||||
if [ -f libcli/autogen.sh ]; then
|
|
||||||
echo "[autogen] Configuring libcli submodule..."
|
|
||||||
(cd libcli && ./autogen.sh)
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "[autogen] Running autoreconf..."
|
|
||||||
autoreconf -fiv
|
|
||||||
|
|
||||||
echo "[autogen] Done. Now run: ./configure && make"
|
|
||||||
|
|
|
||||||
116
configure.ac
116
configure.ac
|
|
@ -2,7 +2,7 @@ AC_PREREQ([2.69])
|
||||||
AC_INIT([net-tools], [0.0.1], [])
|
AC_INIT([net-tools], [0.0.1], [])
|
||||||
AC_CONFIG_AUX_DIR([build-aux])
|
AC_CONFIG_AUX_DIR([build-aux])
|
||||||
AC_CONFIG_MACRO_DIRS([m4])
|
AC_CONFIG_MACRO_DIRS([m4])
|
||||||
AM_INIT_AUTOMAKE([foreign -Wall subdir-objects])
|
AM_INIT_AUTOMAKE([foreign -Wall -Werror subdir-objects])
|
||||||
|
|
||||||
# Compiler: prefer clang
|
# Compiler: prefer clang
|
||||||
AC_PROG_CC
|
AC_PROG_CC
|
||||||
|
|
@ -13,48 +13,78 @@ if test "x$GCC" = "xyes" && test "x$CC" = "xgcc"; then
|
||||||
AC_MSG_NOTICE([Using clang])
|
AC_MSG_NOTICE([Using clang])
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
if test "x$ac_cv_env_CFLAGS_set" != "xset"; then
|
||||||
|
CFLAGS=""
|
||||||
|
fi
|
||||||
|
|
||||||
|
STRICT_CFLAGS="-Wall -Wextra -Werror -pipe -Wpedantic -Wconversion -Wshadow -Wvla"
|
||||||
|
AC_SUBST([STRICT_CFLAGS])
|
||||||
|
|
||||||
AM_PROG_AR
|
AM_PROG_AR
|
||||||
LT_PREREQ([2.2])
|
LT_PREREQ([2.2])
|
||||||
LT_INIT
|
LT_INIT
|
||||||
|
|
||||||
# Strict flags — always enabled, not optional
|
PKG_PROG_PKG_CONFIG
|
||||||
STRICT_CFLAGS="-Wall -Wextra -Werror -Wpedantic -Wconversion -Wshadow"
|
|
||||||
AC_SUBST([STRICT_CFLAGS])
|
|
||||||
|
|
||||||
# libcli: Autotools submodule — configure automatically
|
|
||||||
AC_CONFIG_SUBDIRS([libcli])
|
|
||||||
|
|
||||||
# --enable-tests
|
|
||||||
AC_ARG_ENABLE([tests],
|
|
||||||
[AS_HELP_STRING([--enable-tests], [Build Criterion unit tests (default: no)])],
|
|
||||||
[enable_tests=$enableval],
|
|
||||||
[enable_tests=no])
|
|
||||||
AM_CONDITIONAL([BUILD_TESTS], [test "x$enable_tests" = "xyes"])
|
|
||||||
AS_IF([test "x$enable_tests" = "xyes"], [
|
|
||||||
PKG_CHECK_MODULES([CRITERION], [criterion], [], [
|
|
||||||
AC_MSG_NOTICE([pkg-config could not find criterion -- trying manual detection])
|
|
||||||
AC_CHECK_HEADER([criterion/criterion.h], [], [
|
|
||||||
AC_MSG_ERROR([criterion/criterion.h not found])])
|
|
||||||
AC_CHECK_LIB([criterion], [main],
|
|
||||||
[CRITERION_LIBS="-lcriterion"],
|
|
||||||
[AC_MSG_ERROR([libcriterion not found])])
|
|
||||||
])
|
|
||||||
])
|
|
||||||
|
|
||||||
# --enable-debug
|
# --enable-debug
|
||||||
AC_ARG_ENABLE([debug],
|
AC_ARG_ENABLE(
|
||||||
[AS_HELP_STRING([--enable-debug], [Enable debug build: -g -O0 (default: no)])],
|
[debug],
|
||||||
[enable_debug=$enableval],
|
[AS_HELP_STRING([--enable-debug], [Enable debug build: -g -O0 (default: no)])],
|
||||||
[enable_debug=no])
|
[enable_debug=$enableval],
|
||||||
|
[enable_debug=no]
|
||||||
|
)
|
||||||
AM_CONDITIONAL([ENABLE_DEBUG], [test "x$enable_debug" = "xyes"])
|
AM_CONDITIONAL([ENABLE_DEBUG], [test "x$enable_debug" = "xyes"])
|
||||||
|
AS_IF([test "x$enable_debug" = "xyes"],
|
||||||
|
[CFLAGS="-g -O0"],
|
||||||
|
[CFLAGS="-O2"],
|
||||||
|
)
|
||||||
|
|
||||||
# --enable-sanitizers
|
AC_SUBST([DEBUG_CFLAGS])
|
||||||
AC_ARG_ENABLE([sanitizers],
|
|
||||||
[AS_HELP_STRING([--enable-sanitizers],
|
|
||||||
[Enable AddressSanitizer and UndefinedBehaviorSanitizer (default: no)])],
|
# --with-bundled-libcli
|
||||||
[enable_sanitizers=$enableval],
|
AC_ARG_WITH(
|
||||||
[enable_sanitizers=no])
|
[bundled-libcli],
|
||||||
AM_CONDITIONAL([ENABLE_SANITIZERS], [test "x$enable_sanitizers" = "xyes"])
|
AS_HELP_STRING([--with-bundled-libcli], [force using bundled ./libcli (ignore system)]),
|
||||||
|
[with_bundled_libcli=yes],
|
||||||
|
[with_bundled_libcli=no]
|
||||||
|
)
|
||||||
|
have_system_libcli=no
|
||||||
|
|
||||||
|
AS_IF([test "x$with_bundled_libcli" != "xyes"], [
|
||||||
|
PKG_CHECK_MODULES(
|
||||||
|
[LIBCLI], [libcli >= 0.1.0],
|
||||||
|
[have_system_libcli=yes],
|
||||||
|
[have_system_libcli=no]
|
||||||
|
)
|
||||||
|
])
|
||||||
|
|
||||||
|
AM_CONDITIONAL([USE_SYSTEM_LIBCLI], [test "x$have_system_libcli" = "xyes"])
|
||||||
|
AM_CONDITIONAL([BUILD_BUNDLED_LIBCLI], [test "x$have_system_libcli" != "xyes"])
|
||||||
|
|
||||||
|
AC_SUBST([LIBCLI_CFLAGS])
|
||||||
|
AC_SUBST([LIBCLI_LIBS])
|
||||||
|
|
||||||
|
AS_IF([test "x$have_system_libcli" != "xyes"], [AC_CONFIG_SUBDIRS([libcli])])
|
||||||
|
|
||||||
|
|
||||||
|
# --enable-tests
|
||||||
|
AC_ARG_ENABLE(
|
||||||
|
[tests],
|
||||||
|
[AS_HELP_STRING([--enable-tests], [Build Criterion unit tests (default: no)])],
|
||||||
|
[enable_tests=$enableval],
|
||||||
|
[enable_tests=no]
|
||||||
|
)
|
||||||
|
AM_CONDITIONAL([BUILD_TESTS], [test "x$enable_tests" = "xyes"])
|
||||||
|
AS_IF([test "x$enable_tests" = "xyes"], [
|
||||||
|
PKG_CHECK_MODULES([CRITERION], [criterion], [], [
|
||||||
|
AC_MSG_NOTICE([pkg-config could not find criterion -- trying manual detection])
|
||||||
|
AC_CHECK_HEADER([criterion/criterion.h], [], [AC_MSG_ERROR([criterion/criterion.h not found])])
|
||||||
|
AC_CHECK_LIB([criterion], [main],
|
||||||
|
[CRITERION_LIBS="-lcriterion"],
|
||||||
|
[AC_MSG_ERROR([libcriterion not found])])
|
||||||
|
])
|
||||||
|
])
|
||||||
|
|
||||||
AC_CONFIG_FILES([
|
AC_CONFIG_FILES([
|
||||||
Makefile
|
Makefile
|
||||||
|
|
@ -62,15 +92,17 @@ AC_CONFIG_FILES([
|
||||||
src/ping/Makefile
|
src/ping/Makefile
|
||||||
tests/Makefile
|
tests/Makefile
|
||||||
])
|
])
|
||||||
|
|
||||||
AC_OUTPUT
|
AC_OUTPUT
|
||||||
|
|
||||||
AC_MSG_NOTICE([
|
AC_MSG_NOTICE([
|
||||||
|
|
||||||
net-tools $VERSION
|
net-tools $VERSION
|
||||||
------------------
|
------------------
|
||||||
CC : $CC
|
PREFIX : $prefix
|
||||||
CFLAGS : $STRICT_CFLAGS
|
CC : $CC
|
||||||
tests : $enable_tests
|
CFLAGS : $STRICT_CFLAGS $CFLAGS
|
||||||
debug : $enable_debug
|
tests : $enable_tests
|
||||||
sanitizers : $enable_sanitizers
|
debug : $enable_debug
|
||||||
|
libcli : system=$have_system_libcli (forced bundled=$with_bundled_libcli)
|
||||||
])
|
])
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ enum {
|
||||||
OPT_ARG_SECONDS = OPT_ARG_STRING + 1,
|
OPT_ARG_SECONDS = OPT_ARG_STRING + 1,
|
||||||
OPT_ARG_BYTES,
|
OPT_ARG_BYTES,
|
||||||
OPT_ARG_TTL,
|
OPT_ARG_TTL,
|
||||||
|
OPT_ARG_PATTERN,
|
||||||
};
|
};
|
||||||
|
|
||||||
#define PING_OPTIONS_LIST \
|
#define PING_OPTIONS_LIST \
|
||||||
|
|
@ -60,6 +61,14 @@ enum {
|
||||||
OPT_ARG_SECONDS, \
|
OPT_ARG_SECONDS, \
|
||||||
"Wait N seconds between packets" \
|
"Wait N seconds between packets" \
|
||||||
) \
|
) \
|
||||||
|
X( \
|
||||||
|
'T', \
|
||||||
|
"tos", \
|
||||||
|
required_argument, \
|
||||||
|
cli_handle_tos, \
|
||||||
|
OPT_ARG_UINT, \
|
||||||
|
"Set Type of Service (TOS)" \
|
||||||
|
) \
|
||||||
X( \
|
X( \
|
||||||
't', \
|
't', \
|
||||||
"ttl", \
|
"ttl", \
|
||||||
|
|
@ -78,17 +87,17 @@ enum {
|
||||||
) \
|
) \
|
||||||
X( \
|
X( \
|
||||||
'W', \
|
'W', \
|
||||||
"timeout", \
|
"linger", \
|
||||||
required_argument, \
|
required_argument, \
|
||||||
cli_handle_timeout, \
|
cli_handle_linger, \
|
||||||
OPT_ARG_SECONDS, \
|
OPT_ARG_SECONDS, \
|
||||||
"Timeout for replies in seconds" \
|
"Timeout for replies in seconds" \
|
||||||
) \
|
) \
|
||||||
X( \
|
X( \
|
||||||
'w', \
|
'w', \
|
||||||
"deadline", \
|
"timeout", \
|
||||||
required_argument, \
|
required_argument, \
|
||||||
cli_handle_deadline, \
|
cli_handle_timeout, \
|
||||||
OPT_ARG_SECONDS, \
|
OPT_ARG_SECONDS, \
|
||||||
"Exit after N seconds regardless of packets sent/received" \
|
"Exit after N seconds regardless of packets sent/received" \
|
||||||
) \
|
) \
|
||||||
|
|
@ -107,6 +116,22 @@ enum {
|
||||||
cli_handle_dont_fragment, \
|
cli_handle_dont_fragment, \
|
||||||
OPT_ARG_NONE, \
|
OPT_ARG_NONE, \
|
||||||
"Set the Don't Fragment bit" \
|
"Set the Don't Fragment bit" \
|
||||||
|
) \
|
||||||
|
X( \
|
||||||
|
'l', \
|
||||||
|
"preload", \
|
||||||
|
required_argument, \
|
||||||
|
cli_handle_preload, \
|
||||||
|
OPT_ARG_UINT, \
|
||||||
|
"Send N packets in burst before normal loop" \
|
||||||
|
) \
|
||||||
|
X( \
|
||||||
|
'p', \
|
||||||
|
"pattern", \
|
||||||
|
required_argument, \
|
||||||
|
cli_handle_pattern, \
|
||||||
|
OPT_ARG_PATTERN, \
|
||||||
|
"Fill packet payload with hex pattern" \
|
||||||
)
|
)
|
||||||
|
|
||||||
#undef X
|
#undef X
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,13 @@
|
||||||
#ifndef CLI_INTERNAL_PARSE_UTILS
|
#ifndef CLI_INTERNAL_PARSE_UTILS
|
||||||
#define CLI_INTERNAL_PARSE_UTILS
|
#define CLI_INTERNAL_PARSE_UTILS
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
int cli_parse_uint64(const char *s, uint64_t *out);
|
int cli_parse_uint64(const char *s, uint64_t *out);
|
||||||
int cli_parse_float(const char *s, float *out);
|
int cli_parse_float(const char *s, float *out);
|
||||||
int cli_parse_ufloat(const char *s, float *out);
|
int cli_parse_ufloat(const char *s, float *out);
|
||||||
|
int cli_parse_hex(const char *str, uint8_t *out, size_t max_len, size_t
|
||||||
|
*out_len);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -6,14 +6,17 @@
|
||||||
extern const struct option_descriptor g_options[];
|
extern const struct option_descriptor g_options[];
|
||||||
|
|
||||||
int cli_handle_count(const char *arg, void *config);
|
int cli_handle_count(const char *arg, void *config);
|
||||||
|
int cli_handle_preload(const char *arg, void *config);
|
||||||
|
int cli_handle_pattern(const char *arg, void *config);
|
||||||
int cli_handle_dont_fragment(const char *arg, void *config);
|
int cli_handle_dont_fragment(const char *arg, void *config);
|
||||||
int cli_handle_deadline(const char *arg, void *config);
|
|
||||||
int cli_handle_flood(const char *arg, void *config);
|
int cli_handle_flood(const char *arg, void *config);
|
||||||
int cli_handle_help(const char *arg, void *config);
|
int cli_handle_help(const char *arg, void *config);
|
||||||
int cli_handle_interval(const char *arg, void *config);
|
int cli_handle_interval(const char *arg, void *config);
|
||||||
int cli_handle_quiet(const char *arg, void *config);
|
int cli_handle_quiet(const char *arg, void *config);
|
||||||
int cli_handle_size(const char *arg, void *config);
|
int cli_handle_size(const char *arg, void *config);
|
||||||
|
int cli_handle_linger(const char *arg, void *config);
|
||||||
int cli_handle_timeout(const char *arg, void *config);
|
int cli_handle_timeout(const char *arg, void *config);
|
||||||
|
int cli_handle_tos(const char *arg, void *config);
|
||||||
int cli_handle_ttl(const char *arg, void *config);
|
int cli_handle_ttl(const char *arg, void *config);
|
||||||
int cli_handle_verbose(const char *arg, void *config);
|
int cli_handle_verbose(const char *arg, void *config);
|
||||||
int cli_handle_version(const char *arg, void *config);
|
int cli_handle_version(const char *arg, void *config);
|
||||||
|
|
|
||||||
12
includes/internal/ping/handlers.h
Normal file
12
includes/internal/ping/handlers.h
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
#ifndef PING_HANDLERS_H
|
||||||
|
#define PING_HANDLERS_H
|
||||||
|
|
||||||
|
#include "icmp.h"
|
||||||
|
#include "internal/ping/ping_state.h"
|
||||||
|
|
||||||
|
void ping_handle_echo_reply(struct ping_state *state,
|
||||||
|
const icmp_reply_t *reply);
|
||||||
|
void ping_handle_icmp_error(struct ping_state *state,
|
||||||
|
const icmp_reply_t *reply);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -10,7 +10,8 @@
|
||||||
void ping_output_start(const struct ping_config *config,
|
void ping_output_start(const struct ping_config *config,
|
||||||
struct destinations *dest, size_t payload_bytes);
|
struct destinations *dest, size_t payload_bytes);
|
||||||
void ping_output_packet(const icmp_reply_t *reply, uint16_t seq,
|
void ping_output_packet(const icmp_reply_t *reply, uint16_t seq,
|
||||||
int64_t rtt_ns, size_t payload_bytes, const struct ping_config *config);
|
int64_t rtt_ns, size_t payload_bytes, const struct ping_config *config,
|
||||||
|
int is_dup);
|
||||||
void ping_output_error(const icmp_reply_t *reply,
|
void ping_output_error(const icmp_reply_t *reply,
|
||||||
const icmp_offending_packet_t *offending,
|
const icmp_offending_packet_t *offending,
|
||||||
uint16_t seq, const struct ping_config *config);
|
uint16_t seq, const struct ping_config *config);
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ struct ping_state {
|
||||||
volatile sig_atomic_t send_flag;
|
volatile sig_atomic_t send_flag;
|
||||||
volatile sig_atomic_t stop_flag;
|
volatile sig_atomic_t stop_flag;
|
||||||
size_t nb_errors;
|
size_t nb_errors;
|
||||||
|
int ts_in_payload;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -3,28 +3,16 @@
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <time.h>
|
|
||||||
|
|
||||||
#include "internal/ping/tracker_flags.h"
|
|
||||||
|
|
||||||
#define PING_TRACKER_SLOTS 128
|
|
||||||
|
|
||||||
struct ping_tracker_slot {
|
|
||||||
struct timespec ts;
|
|
||||||
uint8_t flags;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ping_tracker {
|
struct ping_tracker {
|
||||||
struct ping_tracker_slot slots[PING_TRACKER_SLOTS];
|
uint8_t rcvd[UINT16_MAX / 8];
|
||||||
size_t nb_sent;
|
size_t nb_sent;
|
||||||
size_t nb_recv;
|
size_t nb_recv;
|
||||||
|
size_t nb_dup;
|
||||||
};
|
};
|
||||||
|
|
||||||
void ping_tracker_init(struct ping_tracker *t);
|
void ping_tracker_init(struct ping_tracker *t);
|
||||||
void ping_tracker_record_send(struct ping_tracker *t, uint16_t seq, const
|
void ping_tracker_record_send(struct ping_tracker *t, uint16_t seq);
|
||||||
struct timespec *ts);
|
int ping_tracker_record_recv(struct ping_tracker *t, uint16_t seq);
|
||||||
int64_t ping_tracker_record_recv(struct ping_tracker *t, uint16_t seq,
|
|
||||||
const struct timespec *ts);
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,21 @@
|
||||||
#ifndef FT_PING_CONST
|
#ifndef FT_PING_CONST
|
||||||
#define FT_PING_CONST
|
#define FT_PING_CONST
|
||||||
|
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
/* Default configuration values */
|
/* Default configuration values */
|
||||||
#define DEFAULT_COUNT 0
|
#define DEFAULT_COUNT 0
|
||||||
|
#define DEFAULT_PRELOAD 1
|
||||||
#define DEFAULT_INTERVAL 1.0
|
#define DEFAULT_INTERVAL 1.0
|
||||||
#define DEFAULT_TTL 64
|
#define DEFAULT_TTL 64
|
||||||
#define DEFAULT_PACKET_SIZE 56
|
#define DEFAULT_PACKET_SIZE 56
|
||||||
#define DEFAULT_TIMEOUT 1.0
|
#define DEFAULT_LINGER 1.0
|
||||||
|
|
||||||
/* Maximum values */
|
/* Maximum values */
|
||||||
#define MAX_PACKET_SIZE 65507
|
#define MAX_PACKET_SIZE 65507
|
||||||
#define MAX_TTL 255
|
#define MAX_TTL 255
|
||||||
|
|
||||||
|
/* Minimum payload size to embed a send timestamp */
|
||||||
|
#define PING_TIMESTAMP_SIZE ((size_t)sizeof(struct timespec))
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -16,11 +16,17 @@ struct ping_config
|
||||||
|
|
||||||
/* Options */
|
/* Options */
|
||||||
uint64_t count;
|
uint64_t count;
|
||||||
|
uint64_t preload;
|
||||||
double interval;
|
double interval;
|
||||||
uint8_t ttl;
|
uint8_t ttl;
|
||||||
|
uint8_t tos;
|
||||||
size_t packet_size;
|
size_t packet_size;
|
||||||
|
double linger;
|
||||||
double timeout;
|
double timeout;
|
||||||
double deadline;
|
|
||||||
|
/* Pattern (-p) */
|
||||||
|
uint8_t pattern[16];
|
||||||
|
uint8_t pattern_len;
|
||||||
|
|
||||||
/* Flags */
|
/* Flags */
|
||||||
uint8_t flags;
|
uint8_t flags;
|
||||||
|
|
|
||||||
2
libcli
2
libcli
|
|
@ -1 +1 @@
|
||||||
Subproject commit ae7fdf2f94a7c3c759d449ee1c4d3439473c6e42
|
Subproject commit 9f179fa596b1f50007d4995256f47cf5edb4f5dc
|
||||||
2
libicmp
2
libicmp
|
|
@ -1 +1 @@
|
||||||
Subproject commit a9bdaf33f22b60b8643871b2522721cd041ac885
|
Subproject commit 75c5766f00f85d57171bc6c88e4dbe7c4ad6bdd0
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
bin_PROGRAMS = ft_ping
|
bin_PROGRAMS = ft_ping
|
||||||
noinst_LTLIBRARIES = libping_core.la
|
noinst_LTLIBRARIES = libping_core.la
|
||||||
|
|
||||||
PING_VERSION = 0.0.1
|
PING_VERSION = 0.0.1
|
||||||
VERSION_HEADER = $(top_srcdir)/includes/version_gen.h
|
VERSION_HEADER = $(top_srcdir)/includes/version_gen.h
|
||||||
|
|
||||||
# Version header: generated at build time (embeds git hash + date)
|
# Version header: generated at build time (embeds git hash + date)
|
||||||
BUILT_SOURCES = $(VERSION_HEADER)
|
BUILT_SOURCES = $(VERSION_HEADER)
|
||||||
CLEANFILES = $(VERSION_HEADER)
|
CLEANFILES = $(VERSION_HEADER)
|
||||||
|
|
||||||
$(VERSION_HEADER): FORCE
|
$(VERSION_HEADER): FORCE
|
||||||
@NEW_HEADER=$$(mktemp); \
|
@NEW_HEADER=$$(mktemp); \
|
||||||
|
|
@ -41,80 +41,79 @@ $(VERSION_HEADER): FORCE
|
||||||
FORCE:
|
FORCE:
|
||||||
.PHONY: FORCE
|
.PHONY: FORCE
|
||||||
|
|
||||||
libping_core_la_SOURCES = \
|
libping_core_la_SOURCES = \
|
||||||
cli/parse.c \
|
cli/parse.c \
|
||||||
cli/handlers/handle_count.c \
|
cli/handlers/handle_count.c \
|
||||||
cli/handlers/handle_dont_fragment.c \
|
cli/handlers/handle_preload.c \
|
||||||
cli/handlers/handle_deadline.c \
|
cli/handlers/handle_pattern.c \
|
||||||
cli/handlers/handle_flood.c \
|
cli/handlers/handle_dont_fragment.c \
|
||||||
cli/handlers/handle_help.c \
|
cli/handlers/handle_linger.c \
|
||||||
cli/handlers/handle_interval.c \
|
cli/handlers/handle_flood.c \
|
||||||
cli/handlers/handle_quiet.c \
|
cli/handlers/handle_help.c \
|
||||||
cli/handlers/option_map.c \
|
cli/handlers/handle_interval.c \
|
||||||
cli/handlers/handle_size.c \
|
cli/handlers/handle_quiet.c \
|
||||||
cli/handlers/handle_timeout.c \
|
cli/handlers/option_map.c \
|
||||||
cli/handlers/handle_ttl.c \
|
cli/handlers/handle_size.c \
|
||||||
cli/handlers/handle_version.c \
|
cli/handlers/handle_timeout.c \
|
||||||
cli/handlers/handle_verbose.c \
|
cli/handlers/handle_tos.c \
|
||||||
cli/parse_utils/parse_inet_addr.c \
|
cli/handlers/handle_ttl.c \
|
||||||
cli/parse_utils/parse_destinations.c \
|
cli/handlers/handle_version.c \
|
||||||
cli/config_free.c \
|
cli/handlers/handle_verbose.c \
|
||||||
cli/messages/help.c \
|
cli/parse_utils/parse_inet_addr.c \
|
||||||
cli/messages/version.c \
|
cli/parse_utils/parse_destinations.c \
|
||||||
cli/messages/error.c \
|
cli/config_free.c \
|
||||||
core/ping.c \
|
cli/messages/version.c \
|
||||||
core/loop.c \
|
cli/messages/error.c \
|
||||||
core/send.c \
|
core/ping.c \
|
||||||
core/callback.c \
|
core/loop.c \
|
||||||
tracker/init.c \
|
core/send.c \
|
||||||
tracker/record_send.c \
|
core/callback.c \
|
||||||
tracker/record_recv.c \
|
core/reply.c \
|
||||||
output/start.c \
|
core/error.c \
|
||||||
output/packet.c \
|
tracker/init.c \
|
||||||
output/error.c \
|
tracker/record_send.c \
|
||||||
output/summary.c \
|
tracker/record_recv.c \
|
||||||
output/flood.c \
|
output/start.c \
|
||||||
scheduler/scheduler_arm.c \
|
output/packet.c \
|
||||||
scheduler/scheduler_select_tv.c \
|
output/error.c \
|
||||||
scheduler/scheduler_init.c \
|
output/summary.c \
|
||||||
stats/stats_get.c \
|
output/flood.c \
|
||||||
stats/stats_init.c \
|
scheduler/scheduler_arm.c \
|
||||||
stats/stats_update.c
|
scheduler/scheduler_select_tv.c \
|
||||||
|
scheduler/scheduler_init.c \
|
||||||
|
stats/stats_get.c \
|
||||||
|
stats/stats_init.c \
|
||||||
|
stats/stats_update.c
|
||||||
|
|
||||||
BASE_CFLAGS = -std=c99 $(STRICT_CFLAGS)
|
BASE_CFLAGS = -std=c99 $(STRICT_CFLAGS)
|
||||||
|
|
||||||
if ENABLE_DEBUG
|
if ENABLE_DEBUG
|
||||||
EXTRA_CFLAGS = -g -O0
|
EXTRA_CFLAGS = -g -O0
|
||||||
else
|
else
|
||||||
EXTRA_CFLAGS =
|
EXTRA_CFLAGS =
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if ENABLE_SANITIZERS
|
|
||||||
SANITIZER_FLAGS = -fsanitize=address,undefined
|
|
||||||
else
|
|
||||||
SANITIZER_FLAGS =
|
|
||||||
endif
|
|
||||||
|
|
||||||
PING_CPPFLAGS = \
|
PING_CPPFLAGS = \
|
||||||
-I $(top_srcdir)/includes \
|
-I $(top_srcdir)/includes \
|
||||||
-I $(top_srcdir)/libicmp/includes \
|
-I $(top_srcdir)/libicmp/includes \
|
||||||
-I $(top_srcdir)/libcli/include \
|
-I $(top_srcdir)/libcli/include \
|
||||||
-D_GNU_SOURCE
|
-D_GNU_SOURCE
|
||||||
|
|
||||||
PING_CFLAGS = $(BASE_CFLAGS) $(EXTRA_CFLAGS) $(SANITIZER_FLAGS)
|
PING_CFLAGS = $(BASE_CFLAGS) $(EXTRA_CFLAGS)
|
||||||
|
|
||||||
libping_core_la_CPPFLAGS = $(PING_CPPFLAGS)
|
libping_core_la_CPPFLAGS = $(PING_CPPFLAGS)
|
||||||
libping_core_la_CFLAGS = $(PING_CFLAGS)
|
libping_core_la_CFLAGS = $(PING_CFLAGS)
|
||||||
|
|
||||||
ft_ping_SOURCES = main.c
|
ft_ping_SOURCES = main.c
|
||||||
ft_ping_CPPFLAGS = $(PING_CPPFLAGS)
|
ft_ping_CPPFLAGS = $(PING_CPPFLAGS)
|
||||||
ft_ping_CFLAGS = $(PING_CFLAGS)
|
ft_ping_CFLAGS = $(PING_CFLAGS)
|
||||||
ft_ping_LDFLAGS = $(SANITIZER_FLAGS)
|
ft_ping_LDFLAGS =
|
||||||
ft_ping_LDADD = \
|
ft_ping_LDADD = \
|
||||||
libping_core.la \
|
libping_core.la \
|
||||||
$(top_srcdir)/libicmp/libicmp.a \
|
$(top_srcdir)/libicmp/libicmp.a \
|
||||||
$(top_builddir)/libcli/src/libcli.la \
|
$(top_builddir)/libcli/src/libcli.la \
|
||||||
-lm
|
-lm
|
||||||
|
|
||||||
# Build libicmp (simple Makefile) before linking
|
# Build libicmp (simple Makefile) before linking
|
||||||
$(top_srcdir)/libicmp/libicmp.a: FORCE
|
$(top_srcdir)/libicmp/libicmp.a: FORCE
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,37 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "cli.h"
|
||||||
#include "compiler.h"
|
#include "compiler.h"
|
||||||
|
#include "internal/cli/options.h"
|
||||||
|
#include "internal/ping/cli_handlers.h"
|
||||||
#include "ping/cli.h"
|
#include "ping/cli.h"
|
||||||
#include "internal/cli/messages.h"
|
|
||||||
|
/* Forward declarations */
|
||||||
|
static inline const char * option_arg_type_to_str(int type);
|
||||||
|
/* -------------------- */
|
||||||
|
|
||||||
int
|
int
|
||||||
cli_handle_help(__unused const char *arg, __unused void *config_void)
|
cli_handle_help(__unused const char *arg, __unused void *config_void)
|
||||||
{
|
{
|
||||||
print_help();
|
printf("ft_ping - Send ICMP ECHO_REQUEST to network hosts\n");
|
||||||
|
printf("Usage: ft_ping [options] <destination>\n\n");
|
||||||
|
cli_print_options(g_options, PING_OPT_LEN, option_arg_type_to_str);
|
||||||
|
|
||||||
return CLI_EXIT_SUCCESS;
|
return CLI_EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline const char *
|
||||||
|
option_arg_type_to_str(int type)
|
||||||
|
{
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case OPT_ARG_NONE: return "";
|
||||||
|
case OPT_ARG_INT: return "<NUM>";
|
||||||
|
case OPT_ARG_UINT: return "<NUM>";
|
||||||
|
case OPT_ARG_SECONDS: return "<SEC>";
|
||||||
|
case OPT_ARG_BYTES: return "<SIZE>";
|
||||||
|
case OPT_ARG_TTL: return "<TTL>";
|
||||||
|
case OPT_ARG_PATTERN: return "<HEX>";
|
||||||
|
case OPT_ARG_STRING: return "<STR>";
|
||||||
|
default: return "<ARG>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
14
src/ping/cli/handlers/handle_linger.c
Normal file
14
src/ping/cli/handlers/handle_linger.c
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
#include "ping/cli.h"
|
||||||
|
#include "internal/cli/parse_utils.h"
|
||||||
|
|
||||||
|
int
|
||||||
|
cli_handle_linger(const char *arg, void *config_void)
|
||||||
|
{
|
||||||
|
struct ping_config *config = (struct ping_config *)config_void;
|
||||||
|
float linger;
|
||||||
|
|
||||||
|
if (0 != cli_parse_ufloat(arg, &linger))
|
||||||
|
return CLI_ERROR;
|
||||||
|
config->linger = linger;
|
||||||
|
return CLI_SUCCESS;
|
||||||
|
}
|
||||||
14
src/ping/cli/handlers/handle_pattern.c
Normal file
14
src/ping/cli/handlers/handle_pattern.c
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
#include "ping/cli.h"
|
||||||
|
#include "internal/cli/parse_utils.h"
|
||||||
|
|
||||||
|
int
|
||||||
|
cli_handle_pattern(const char *arg, void *config_void)
|
||||||
|
{
|
||||||
|
struct ping_config *config = (struct ping_config *)config_void;
|
||||||
|
size_t pattern_len;
|
||||||
|
|
||||||
|
if (0 != cli_parse_hex(arg, config->pattern, 16, &pattern_len))
|
||||||
|
return CLI_ERROR;
|
||||||
|
config->pattern_len = (uint8_t)pattern_len;
|
||||||
|
return CLI_SUCCESS;
|
||||||
|
}
|
||||||
14
src/ping/cli/handlers/handle_preload.c
Normal file
14
src/ping/cli/handlers/handle_preload.c
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
#include "ping/cli.h"
|
||||||
|
#include "internal/cli/parse_utils.h"
|
||||||
|
|
||||||
|
int
|
||||||
|
cli_handle_preload(const char *arg, void *config_void)
|
||||||
|
{
|
||||||
|
struct ping_config *config = (struct ping_config *)config_void;
|
||||||
|
uint64_t preload;
|
||||||
|
|
||||||
|
if (0 != cli_parse_uint64(arg, &preload))
|
||||||
|
return CLI_ERROR;
|
||||||
|
config->preload = preload;
|
||||||
|
return CLI_SUCCESS;
|
||||||
|
}
|
||||||
|
|
@ -5,11 +5,10 @@ int
|
||||||
cli_handle_timeout(const char *arg, void *config_void)
|
cli_handle_timeout(const char *arg, void *config_void)
|
||||||
{
|
{
|
||||||
struct ping_config *config = (struct ping_config *)config_void;
|
struct ping_config *config = (struct ping_config *)config_void;
|
||||||
float TO;
|
float timeout;
|
||||||
|
|
||||||
if (0 != cli_parse_ufloat(arg, &TO))
|
if (0 != cli_parse_ufloat(arg, &timeout))
|
||||||
return CLI_ERROR;
|
return CLI_ERROR;
|
||||||
|
config->timeout = timeout;
|
||||||
config->timeout = TO;
|
|
||||||
return CLI_SUCCESS;
|
return CLI_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
14
src/ping/cli/handlers/handle_tos.c
Normal file
14
src/ping/cli/handlers/handle_tos.c
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
#include "ping/cli.h"
|
||||||
|
#include "internal/cli/parse_utils.h"
|
||||||
|
|
||||||
|
int
|
||||||
|
cli_handle_tos(const char *arg, void *config_void)
|
||||||
|
{
|
||||||
|
struct ping_config *config = (struct ping_config *)config_void;
|
||||||
|
uint64_t tos;
|
||||||
|
|
||||||
|
if (0 != cli_parse_uint64(arg, &tos) || tos > 255)
|
||||||
|
return CLI_ERROR;
|
||||||
|
config->tos = (uint8_t)tos;
|
||||||
|
return CLI_SUCCESS;
|
||||||
|
}
|
||||||
|
|
@ -1,45 +0,0 @@
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#include "internal/ping/cli_handlers.h"
|
|
||||||
#include "internal/cli/options.h"
|
|
||||||
|
|
||||||
/* Forward declarations */
|
|
||||||
static inline const char * option_arg_type_to_str(int type);
|
|
||||||
/* -------------------- */
|
|
||||||
|
|
||||||
void
|
|
||||||
print_help(void)
|
|
||||||
{
|
|
||||||
printf("ft_ping - Send ICMP ECHO_REQUEST to network hosts\n");
|
|
||||||
printf("Usage: ft_ping [options] <destination>\n\n");
|
|
||||||
printf("Options:\n");
|
|
||||||
|
|
||||||
for (size_t i = 0; i < PING_OPT_LEN; ++i)
|
|
||||||
{
|
|
||||||
const struct option_descriptor *opt = &g_options[i];
|
|
||||||
const char *argstr = option_arg_type_to_str(opt->arg_type);
|
|
||||||
|
|
||||||
printf(" -%c, --%-10s %-8s %s\n",
|
|
||||||
opt->short_opt,
|
|
||||||
opt->long_opt,
|
|
||||||
argstr[0] ? argstr : "",
|
|
||||||
opt->description
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline const char *
|
|
||||||
option_arg_type_to_str(int type)
|
|
||||||
{
|
|
||||||
switch (type)
|
|
||||||
{
|
|
||||||
case OPT_ARG_NONE: return "";
|
|
||||||
case OPT_ARG_INT: return "<NUM>";
|
|
||||||
case OPT_ARG_UINT: return "<NUM>";
|
|
||||||
case OPT_ARG_SECONDS: return "<SEC>";
|
|
||||||
case OPT_ARG_BYTES: return "<SIZE>";
|
|
||||||
case OPT_ARG_TTL: return "<TTL>";
|
|
||||||
case OPT_ARG_STRING: return "<STR>";
|
|
||||||
default: return "<ARG>";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -31,8 +31,9 @@ init_config(struct ping_config *config)
|
||||||
{
|
{
|
||||||
memset(config, 0, sizeof(struct ping_config));
|
memset(config, 0, sizeof(struct ping_config));
|
||||||
config->count = DEFAULT_COUNT;
|
config->count = DEFAULT_COUNT;
|
||||||
|
config->preload = DEFAULT_PRELOAD;
|
||||||
config->interval = DEFAULT_INTERVAL;
|
config->interval = DEFAULT_INTERVAL;
|
||||||
config->ttl = DEFAULT_TTL;
|
config->ttl = DEFAULT_TTL;
|
||||||
config->packet_size = DEFAULT_PACKET_SIZE;
|
config->packet_size = DEFAULT_PACKET_SIZE;
|
||||||
config->timeout = DEFAULT_TIMEOUT;
|
config->linger = DEFAULT_LINGER;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,5 @@
|
||||||
#include "icmp_types.h"
|
#include "icmp_types.h"
|
||||||
#include "ping/ft_ping_flags.h"
|
#include "internal/ping/handlers.h"
|
||||||
#include "internal/ping/output.h"
|
|
||||||
|
|
||||||
/* Forward declarations */
|
|
||||||
static int extract_our_echo(const icmp_reply_t *reply, uint16_t our_id,
|
|
||||||
struct in_addr dest, uint16_t *seq_out);
|
|
||||||
static void handle_echo_reply(struct ping_state *state,
|
|
||||||
const icmp_reply_t *reply);
|
|
||||||
static int extract_our_error(const icmp_reply_t *reply, uint16_t our_id,
|
|
||||||
struct in_addr dest, icmp_offending_packet_t *out, uint16_t *seq_out);
|
|
||||||
static void handle_icmp_error(struct ping_state *state,
|
|
||||||
const icmp_reply_t *reply);
|
|
||||||
/* -------------------- */
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ping_callback(const icmp_reply_t *reply, void *userdata)
|
ping_callback(const icmp_reply_t *reply, void *userdata)
|
||||||
|
|
@ -20,69 +8,8 @@ ping_callback(const icmp_reply_t *reply, void *userdata)
|
||||||
|
|
||||||
state = (struct ping_state *)userdata;
|
state = (struct ping_state *)userdata;
|
||||||
if (ICMP_TYPE_ECHO_REPLY == reply->type)
|
if (ICMP_TYPE_ECHO_REPLY == reply->type)
|
||||||
handle_echo_reply(state, reply);
|
ping_handle_echo_reply(state, reply);
|
||||||
else if (ICMP_TYPE_TIME_EXCEEDED == reply->type
|
else if (ICMP_TYPE_TIME_EXCEEDED == reply->type
|
||||||
|| ICMP_TYPE_DEST_UNREACHABLE == reply->type)
|
|| ICMP_TYPE_DEST_UNREACHABLE == reply->type)
|
||||||
handle_icmp_error(state, reply);
|
ping_handle_icmp_error(state, reply);
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
extract_our_echo(const icmp_reply_t *reply, uint16_t our_id,
|
|
||||||
struct in_addr dest, uint16_t *seq_out)
|
|
||||||
{
|
|
||||||
uint16_t id;
|
|
||||||
uint16_t seq;
|
|
||||||
|
|
||||||
if (0 > icmp_reply_id_seq(reply, &id, &seq))
|
|
||||||
return 0;
|
|
||||||
if (our_id != id || reply->from.s_addr != dest.s_addr)
|
|
||||||
return 0;
|
|
||||||
*seq_out = seq;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
handle_echo_reply(struct ping_state *state, const icmp_reply_t *reply)
|
|
||||||
{
|
|
||||||
uint16_t seq;
|
|
||||||
int64_t rtt;
|
|
||||||
|
|
||||||
if (0 == extract_our_echo(reply, state->id, state->dest, &seq))
|
|
||||||
return;
|
|
||||||
rtt = ping_tracker_record_recv(state->tracker, seq, &reply->timestamp);
|
|
||||||
if (0 > rtt)
|
|
||||||
return;
|
|
||||||
ping_stats_update(state->stats, rtt);
|
|
||||||
if (HAS_FLAG(state->config->flags, FLAG_FLOOD))
|
|
||||||
ping_output_flood_erase();
|
|
||||||
else
|
|
||||||
ping_output_packet(reply, seq, rtt, state->config->packet_size,
|
|
||||||
state->config);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
extract_our_error(const icmp_reply_t *reply, uint16_t our_id,
|
|
||||||
struct in_addr dest, icmp_offending_packet_t *out, uint16_t *seq_out)
|
|
||||||
{
|
|
||||||
if ((0 > icmp_error_extract_offending(reply, out))
|
|
||||||
|| ICMP_TYPE_ECHO_REQUEST != out->icmp_type
|
|
||||||
|| our_id != out->rest.echo.id || out->dst.s_addr != dest.s_addr)
|
|
||||||
return 0;
|
|
||||||
*seq_out = out->rest.echo.seq;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
handle_icmp_error(struct ping_state *state, const icmp_reply_t *reply)
|
|
||||||
{
|
|
||||||
icmp_offending_packet_t offending;
|
|
||||||
uint16_t seq;
|
|
||||||
|
|
||||||
if (0 == extract_our_error(reply, state->id, state->dest, &offending, &seq))
|
|
||||||
return;
|
|
||||||
if (0 > ping_tracker_record_recv(state->tracker, seq, &reply->timestamp))
|
|
||||||
return;
|
|
||||||
state->nb_errors++;
|
|
||||||
if (!HAS_FLAG(state->config->flags, FLAG_QUIET))
|
|
||||||
ping_output_error(reply, &offending, seq, state->config);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
37
src/ping/core/error.c
Normal file
37
src/ping/core/error.c
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
#include "icmp.h"
|
||||||
|
#include "icmp_types.h"
|
||||||
|
#include "ping/ft_ping_flags.h"
|
||||||
|
#include "internal/ping/handlers.h"
|
||||||
|
#include "internal/ping/output.h"
|
||||||
|
|
||||||
|
/* Forward declarations */
|
||||||
|
static int extract_our_error(const icmp_reply_t *reply, uint16_t our_id,
|
||||||
|
struct in_addr dest, icmp_offending_packet_t *out, uint16_t *seq_out);
|
||||||
|
/* -------------------- */
|
||||||
|
|
||||||
|
void
|
||||||
|
ping_handle_icmp_error(struct ping_state *state, const icmp_reply_t *reply)
|
||||||
|
{
|
||||||
|
icmp_offending_packet_t offending;
|
||||||
|
uint16_t seq;
|
||||||
|
|
||||||
|
if (0 == extract_our_error(reply, state->id, state->dest, &offending, &seq))
|
||||||
|
return;
|
||||||
|
if (0 == ping_tracker_record_recv(state->tracker, seq))
|
||||||
|
return;
|
||||||
|
state->nb_errors++;
|
||||||
|
if (!HAS_FLAG(state->config->flags, FLAG_QUIET))
|
||||||
|
ping_output_error(reply, &offending, seq, state->config);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
extract_our_error(const icmp_reply_t *reply, uint16_t our_id,
|
||||||
|
struct in_addr dest, icmp_offending_packet_t *out, uint16_t *seq_out)
|
||||||
|
{
|
||||||
|
if ((0 > icmp_error_extract_offending(reply, out))
|
||||||
|
|| ICMP_TYPE_ECHO_REQUEST != out->icmp_type
|
||||||
|
|| our_id != out->rest.echo.id || out->dst.s_addr != dest.s_addr)
|
||||||
|
return 0;
|
||||||
|
*seq_out = out->rest.echo.seq;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
@ -7,12 +7,13 @@
|
||||||
#include "internal/ping/scheduler.h"
|
#include "internal/ping/scheduler.h"
|
||||||
|
|
||||||
/* Forward declarations */
|
/* Forward declarations */
|
||||||
static int deadline_expired(const struct ping_state *state);
|
static int timeout_expired(const struct ping_state *state);
|
||||||
static int linger_expired(const struct ping_state *state);
|
static int linger_expired(const struct ping_state *state);
|
||||||
static int should_stop(const struct ping_state *state);
|
static int should_stop(const struct ping_state *state);
|
||||||
static int can_send_more(const struct ping_state *state);
|
static inline int can_send_more(const struct ping_state *state);
|
||||||
static void try_recv(struct ping_state *state);
|
static void try_recv(struct ping_state *state);
|
||||||
static void handle_send_trigger(struct ping_state *state, size_t payload_len);
|
static void handle_send_trigger(struct ping_state *state, size_t
|
||||||
|
payload_len);
|
||||||
/* -------------------- */
|
/* -------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
@ -28,18 +29,18 @@ ping_loop(struct ping_state *state, size_t payload_len)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
deadline_expired(const struct ping_state *state)
|
timeout_expired(const struct ping_state *state)
|
||||||
{
|
{
|
||||||
struct timespec now;
|
struct timespec now;
|
||||||
double elapsed;
|
double elapsed;
|
||||||
|
|
||||||
if (0.0 == state->config->deadline)
|
if (0.0 == state->config->timeout)
|
||||||
return 0;
|
return 0;
|
||||||
if (0 != icmp_get_time(&now))
|
if (0 != icmp_get_time(&now))
|
||||||
return 0;
|
return 0;
|
||||||
elapsed = (double)(now.tv_sec - state->start_time.tv_sec)
|
elapsed = (double)(now.tv_sec - state->start_time.tv_sec)
|
||||||
+ (double)(now.tv_nsec - state->start_time.tv_nsec) / 1e9;
|
+ (double)(now.tv_nsec - state->start_time.tv_nsec) / 1e9;
|
||||||
return elapsed >= state->config->deadline;
|
return elapsed >= state->config->timeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
|
@ -48,13 +49,12 @@ linger_expired(const struct ping_state *state)
|
||||||
struct timespec now;
|
struct timespec now;
|
||||||
double elapsed;
|
double elapsed;
|
||||||
|
|
||||||
if (0 == state->linger_start.tv_sec && 0 == state->linger_start.tv_nsec)
|
if ((0 == state->linger_start.tv_sec && 0 == state->linger_start.tv_nsec)
|
||||||
return 0;
|
|| 0!= icmp_get_time(&now))
|
||||||
if (0 != icmp_get_time(&now))
|
|
||||||
return 0;
|
return 0;
|
||||||
elapsed = (double)(now.tv_sec - state->linger_start.tv_sec)
|
elapsed = (double)(now.tv_sec - state->linger_start.tv_sec)
|
||||||
+ (double)(now.tv_nsec - state->linger_start.tv_nsec) / 1e9;
|
+ (double)(now.tv_nsec - state->linger_start.tv_nsec) / 1e9;
|
||||||
return elapsed >= state->config->timeout;
|
return elapsed >= state->config->linger;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
|
@ -62,11 +62,9 @@ should_stop(const struct ping_state *state)
|
||||||
{
|
{
|
||||||
size_t count;
|
size_t count;
|
||||||
|
|
||||||
if (state->stop_flag)
|
if (state->stop_flag
|
||||||
return 1;
|
|| timeout_expired(state)
|
||||||
if (deadline_expired(state))
|
|| linger_expired(state))
|
||||||
return 1;
|
|
||||||
if (linger_expired(state))
|
|
||||||
return 1;
|
return 1;
|
||||||
count = state->config->count;
|
count = state->config->count;
|
||||||
if (0 != count && state->tracker->nb_recv >= count)
|
if (0 != count && state->tracker->nb_recv >= count)
|
||||||
|
|
@ -74,7 +72,7 @@ should_stop(const struct ping_state *state)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static inline int
|
||||||
can_send_more(const struct ping_state *state)
|
can_send_more(const struct ping_state *state)
|
||||||
{
|
{
|
||||||
size_t count;
|
size_t count;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
|
#include <errno.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "version_gen.h"
|
#include "version_gen.h"
|
||||||
|
#include "ping/ft_ping_const.h"
|
||||||
#include "ping/ft_ping_flags.h"
|
#include "ping/ft_ping_flags.h"
|
||||||
#include "internal/ping/output.h"
|
#include "internal/ping/output.h"
|
||||||
#include "internal/ping/scheduler.h"
|
#include "internal/ping/scheduler.h"
|
||||||
|
|
@ -9,47 +11,67 @@
|
||||||
#include "internal/ping/loop.h"
|
#include "internal/ping/loop.h"
|
||||||
|
|
||||||
/* Forward declarations */
|
/* Forward declarations */
|
||||||
static int ping_one(const struct ping_config *config,
|
static icmp_handle_t *ping_create_handle(const struct ping_config *config);
|
||||||
struct destinations *dest, icmp_handle_t *handle);
|
static int ping_one(const struct ping_config *config, struct destinations
|
||||||
|
*dest, icmp_handle_t *handle);
|
||||||
static void ping_init_state(struct ping_state *state, struct ping_stats *stats,
|
static void ping_init_state(struct ping_state *state, struct ping_stats *stats,
|
||||||
struct ping_tracker *tracker, const struct ping_config *config,
|
struct ping_tracker *tracker, const struct ping_config *config,
|
||||||
struct in_addr dest, icmp_handle_t *handle);
|
struct in_addr dest, icmp_handle_t *handle);
|
||||||
|
static int ping_preload(struct ping_state *state, size_t payload_len);
|
||||||
/* -------------------- */
|
/* -------------------- */
|
||||||
|
|
||||||
int
|
int
|
||||||
ping_run(const struct ping_config *config)
|
ping_run(const struct ping_config *config)
|
||||||
{
|
{
|
||||||
icmp_handle_t *handle;
|
icmp_handle_t *handle;
|
||||||
int ret = 0 ;
|
int ret = 0;
|
||||||
size_t i = 0 ;
|
size_t i = 0;
|
||||||
|
|
||||||
if (0 == config->nb_destinations)
|
if (0 == config->nb_destinations)
|
||||||
return 1;
|
return 1;
|
||||||
handle = icmp_create();
|
handle = ping_create_handle(config);
|
||||||
if (NULL == handle)
|
if (NULL == handle)
|
||||||
{
|
|
||||||
dprintf(STDERR_FILENO, "%s: requires CAP_NET_RAW or root privileges\n",
|
|
||||||
g_prog_name);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
|
||||||
if (HAS_FLAG(config->flags, FLAG_DONT_FRAGMENT)
|
|
||||||
&& 0 != icmp_set_dont_fragment(handle))
|
|
||||||
{
|
|
||||||
ret = 1;
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (i < config->nb_destinations)
|
while (i < config->nb_destinations)
|
||||||
{
|
{
|
||||||
if (0 != ping_one(config, &config->destinations[i], handle))
|
if (0 != ping_one(config, &config->destinations[i], handle))
|
||||||
ret = 1;
|
ret = 1;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
cleanup:
|
|
||||||
icmp_destroy(handle);
|
icmp_destroy(handle);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static icmp_handle_t *
|
||||||
|
ping_create_handle(const struct ping_config *config)
|
||||||
|
{
|
||||||
|
icmp_handle_t *handle;
|
||||||
|
|
||||||
|
handle = icmp_create();
|
||||||
|
if (NULL == handle)
|
||||||
|
{
|
||||||
|
dprintf(STDERR_FILENO, "%s: requires CAP_NET_RAW or root privileges\n",
|
||||||
|
g_prog_name);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
if (HAS_FLAG(config->flags, FLAG_DONT_FRAGMENT)
|
||||||
|
&& 0 != icmp_set_dont_fragment(handle))
|
||||||
|
{
|
||||||
|
dprintf(STDERR_FILENO, "%s: %s\n", g_prog_name, icmp_strerror(handle));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
if (0 != config->tos && 0 != icmp_set_tos(handle, config->tos))
|
||||||
|
{
|
||||||
|
dprintf(STDERR_FILENO, "%s: %s\n", g_prog_name, icmp_strerror(handle));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
return handle;
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
icmp_destroy(handle);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
ping_one(const struct ping_config *config, struct destinations *dest,
|
ping_one(const struct ping_config *config, struct destinations *dest,
|
||||||
icmp_handle_t *handle)
|
icmp_handle_t *handle)
|
||||||
|
|
@ -62,9 +84,14 @@ ping_one(const struct ping_config *config, struct destinations *dest,
|
||||||
ping_init_state(&state, &stats, &tracker, config, dest->ip, handle);
|
ping_init_state(&state, &stats, &tracker, config, dest->ip, handle);
|
||||||
payload_len = config->packet_size;
|
payload_len = config->packet_size;
|
||||||
if (0 != ping_scheduler_init(&state))
|
if (0 != ping_scheduler_init(&state))
|
||||||
|
{
|
||||||
|
dprintf(STDERR_FILENO, "%s: sigaction: %s\n",
|
||||||
|
g_prog_name, strerror(errno));
|
||||||
return 1;
|
return 1;
|
||||||
|
}
|
||||||
ping_output_start(config, dest, payload_len);
|
ping_output_start(config, dest, payload_len);
|
||||||
do_send(&state, payload_len);
|
if (0 != ping_preload(&state, payload_len))
|
||||||
|
return 1;
|
||||||
ping_loop(&state, payload_len);
|
ping_loop(&state, payload_len);
|
||||||
ping_output_summary(&state, dest);
|
ping_output_summary(&state, dest);
|
||||||
return tracker.nb_recv <= state.nb_errors;
|
return tracker.nb_recv <= state.nb_errors;
|
||||||
|
|
@ -84,5 +111,27 @@ ping_init_state(struct ping_state *state, struct ping_stats *stats,
|
||||||
state->tracker = tracker;
|
state->tracker = tracker;
|
||||||
state->stats = stats;
|
state->stats = stats;
|
||||||
state->handle = handle;
|
state->handle = handle;
|
||||||
|
state->ts_in_payload = (config->packet_size >= PING_TIMESTAMP_SIZE);
|
||||||
icmp_get_time(&state->start_time);
|
icmp_get_time(&state->start_time);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
ping_preload(struct ping_state *state, size_t payload_len)
|
||||||
|
{
|
||||||
|
const struct ping_config *config = state->config;
|
||||||
|
uint64_t i = 0;
|
||||||
|
|
||||||
|
while (i < config->preload && (0 == config->count ||
|
||||||
|
state->tracker->nb_sent < config->count))
|
||||||
|
{
|
||||||
|
do_send(state, payload_len);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
if (0 == config->preload && 0 != ping_scheduler_arm(config))
|
||||||
|
{
|
||||||
|
dprintf(STDERR_FILENO, "%s: setitimer: %s\n",
|
||||||
|
g_prog_name, strerror(errno));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
|
||||||
55
src/ping/core/reply.c
Normal file
55
src/ping/core/reply.c
Normal file
|
|
@ -0,0 +1,55 @@
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "icmp.h"
|
||||||
|
#include "ping/ft_ping_const.h"
|
||||||
|
#include "ping/ft_ping_flags.h"
|
||||||
|
#include "internal/ping/handlers.h"
|
||||||
|
#include "internal/ping/output.h"
|
||||||
|
|
||||||
|
/* Forward declarations */
|
||||||
|
static int extract_our_echo(const icmp_reply_t *reply, uint16_t our_id,
|
||||||
|
struct in_addr dest, uint16_t *seq_out);
|
||||||
|
/* -------------------- */
|
||||||
|
|
||||||
|
void
|
||||||
|
ping_handle_echo_reply(struct ping_state *state, const icmp_reply_t *reply)
|
||||||
|
{
|
||||||
|
uint16_t seq;
|
||||||
|
int is_new;
|
||||||
|
int64_t rtt_ns;
|
||||||
|
struct timespec send_ts;
|
||||||
|
|
||||||
|
if (0 == extract_our_echo(reply, state->id, state->dest, &seq))
|
||||||
|
return;
|
||||||
|
is_new = ping_tracker_record_recv(state->tracker, seq);
|
||||||
|
rtt_ns = -1;
|
||||||
|
if (state->ts_in_payload && reply->payload_len >= PING_TIMESTAMP_SIZE)
|
||||||
|
{
|
||||||
|
memcpy(&send_ts, reply->payload, sizeof(send_ts));
|
||||||
|
rtt_ns = icmp_time_diff_ns(&send_ts, &reply->timestamp);
|
||||||
|
if (is_new)
|
||||||
|
ping_stats_update(state->stats, rtt_ns);
|
||||||
|
}
|
||||||
|
if (HAS_FLAG(state->config->flags, FLAG_FLOOD))
|
||||||
|
{
|
||||||
|
if (is_new)
|
||||||
|
ping_output_flood_erase();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ping_output_packet(reply, seq, rtt_ns, state->config->packet_size,
|
||||||
|
state->config, !is_new);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
extract_our_echo(const icmp_reply_t *reply, uint16_t our_id,
|
||||||
|
struct in_addr dest, uint16_t *seq_out)
|
||||||
|
{
|
||||||
|
uint16_t id;
|
||||||
|
uint16_t seq;
|
||||||
|
|
||||||
|
if ((0 > icmp_reply_id_seq(reply, &id, &seq))
|
||||||
|
|| ((our_id != id || reply->from.s_addr != dest.s_addr)))
|
||||||
|
return 0;
|
||||||
|
*seq_out = seq;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
@ -12,9 +12,10 @@
|
||||||
#include "ping/ft_ping_flags.h"
|
#include "ping/ft_ping_flags.h"
|
||||||
|
|
||||||
/* Forward declarations */
|
/* Forward declarations */
|
||||||
static inline void fill_payload(uint8_t *payload, size_t payload_len);
|
static inline void fill_payload(uint8_t *payload, size_t len,
|
||||||
|
const struct ping_config *config, int ts_in_payload);
|
||||||
static int ping_send_one(struct ping_state *state, uint16_t seq,
|
static int ping_send_one(struct ping_state *state, uint16_t seq,
|
||||||
const uint8_t *payload, size_t payload_len, struct timespec *ts);
|
uint8_t *payload, size_t payload_len, struct timespec *ts);
|
||||||
/* -------------------- */
|
/* -------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
@ -25,14 +26,14 @@ do_send(struct ping_state *state, size_t payload_len)
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
state->send_flag = 0;
|
state->send_flag = 0;
|
||||||
fill_payload(payload, payload_len);
|
fill_payload(payload, payload_len, state->config, state->ts_in_payload);
|
||||||
ret = ping_send_one(state, state->seq, payload, payload_len, &ts);
|
ret = ping_send_one(state, state->seq, payload, payload_len, &ts);
|
||||||
if (-1 == ret)
|
if (-1 == ret)
|
||||||
dprintf(STDERR_FILENO, "%s: %s\n",
|
dprintf(STDERR_FILENO, "%s: %s\n",
|
||||||
g_prog_name, icmp_strerror(state->handle));
|
g_prog_name, icmp_strerror(state->handle));
|
||||||
else if (0 == ret)
|
else if (0 == ret)
|
||||||
{
|
{
|
||||||
ping_tracker_record_send(state->tracker, state->seq, &ts);
|
ping_tracker_record_send(state->tracker, state->seq);
|
||||||
state->seq++;
|
state->seq++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -48,12 +49,14 @@ do_send(struct ping_state *state, size_t payload_len)
|
||||||
|
|
||||||
static int
|
static int
|
||||||
ping_send_one(struct ping_state *state, uint16_t seq,
|
ping_send_one(struct ping_state *state, uint16_t seq,
|
||||||
const uint8_t *payload, size_t payload_len, struct timespec *ts)
|
uint8_t *payload, size_t payload_len, struct timespec *ts)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (0 != icmp_get_time(ts))
|
if (0 != icmp_get_time(ts))
|
||||||
return -1;
|
return -1;
|
||||||
|
if (state->ts_in_payload)
|
||||||
|
memcpy(payload, ts, sizeof(*ts));
|
||||||
ret = icmp_send_echo(state->handle,
|
ret = icmp_send_echo(state->handle,
|
||||||
state->dest,
|
state->dest,
|
||||||
state->id,
|
state->id,
|
||||||
|
|
@ -68,8 +71,21 @@ ping_send_one(struct ping_state *state, uint16_t seq,
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
fill_payload(uint8_t *payload, size_t payload_len)
|
fill_payload(uint8_t *payload, size_t len, const struct ping_config *config,
|
||||||
|
int ts_in_payload)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < payload_len; ++i)
|
size_t offset;
|
||||||
payload[i] = (uint8_t)('a' + (i % 26));
|
size_t i;
|
||||||
|
|
||||||
|
offset = ts_in_payload ? PING_TIMESTAMP_SIZE : 0;
|
||||||
|
if (0 == config->pattern_len)
|
||||||
|
{
|
||||||
|
for (i = offset; i < len; ++i)
|
||||||
|
payload[i] = (uint8_t)((i - offset) & 0xFF);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (i = offset; i < len; ++i)
|
||||||
|
payload[i] = config->pattern[(i - offset) % config->pattern_len];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,17 +6,27 @@
|
||||||
|
|
||||||
void
|
void
|
||||||
ping_output_packet(const icmp_reply_t *reply, uint16_t seq,
|
ping_output_packet(const icmp_reply_t *reply, uint16_t seq,
|
||||||
int64_t rtt_ns, size_t payload_bytes, const struct ping_config *config)
|
int64_t rtt_ns, size_t payload_bytes, const struct ping_config *config,
|
||||||
|
int is_dup)
|
||||||
{
|
{
|
||||||
char from_str[INET_ADDRSTRLEN];
|
char from_str[INET_ADDRSTRLEN];
|
||||||
|
|
||||||
if (HAS_FLAG(config->flags, FLAG_QUIET | FLAG_FLOOD))
|
if (HAS_FLAG(config->flags, FLAG_QUIET | FLAG_FLOOD))
|
||||||
return;
|
return;
|
||||||
inet_ntop(AF_INET, &reply->from, from_str, sizeof(from_str));
|
inet_ntop(AF_INET, &reply->from, from_str, sizeof(from_str));
|
||||||
printf("%zu bytes from %s: icmp_seq=%u ttl=%u time=%.3f ms\n",
|
if (0 <= rtt_ns)
|
||||||
payload_bytes + 8,
|
printf("%zu bytes from %s: icmp_seq=%u ttl=%u time=%.3f ms%s\n",
|
||||||
from_str,
|
payload_bytes + 8,
|
||||||
(unsigned int)seq,
|
from_str,
|
||||||
(unsigned int)reply->ttl,
|
(unsigned int)seq,
|
||||||
(double)rtt_ns / 1e6);
|
(unsigned int)reply->ttl,
|
||||||
|
(double)rtt_ns / 1e6,
|
||||||
|
is_dup ? " (DUP!)" : "");
|
||||||
|
else
|
||||||
|
printf("%zu bytes from %s: icmp_seq=%u ttl=%u%s\n",
|
||||||
|
payload_bytes + 8,
|
||||||
|
from_str,
|
||||||
|
(unsigned int)seq,
|
||||||
|
(unsigned int)reply->ttl,
|
||||||
|
is_dup ? " (DUP!)" : "");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ ping_output_summary(const struct ping_state *state,
|
||||||
ok_recv = state->tracker->nb_recv - errors;
|
ok_recv = state->tracker->nb_recv - errors;
|
||||||
printf("--- %s ping statistics ---\n", dest->dom);
|
printf("--- %s ping statistics ---\n", dest->dom);
|
||||||
print_loss_line(sent, ok_recv, errors);
|
print_loss_line(sent, ok_recv, errors);
|
||||||
if (0 < ok_recv)
|
if (0 < state->stats->count)
|
||||||
print_rtt_line(state->stats);
|
print_rtt_line(state->stats);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,5 +5,5 @@ void
|
||||||
ping_scheduler_select_tv(const struct ping_config *config, struct timeval *tv)
|
ping_scheduler_select_tv(const struct ping_config *config, struct timeval *tv)
|
||||||
{
|
{
|
||||||
tv->tv_usec = 0;
|
tv->tv_usec = 0;
|
||||||
tv->tv_sec = (long)config->timeout * !HAS_FLAG(config->flags, FLAG_FLOOD);
|
tv->tv_sec = (long)config->linger * !HAS_FLAG(config->flags, FLAG_FLOOD);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,19 @@
|
||||||
#include "icmp.h"
|
|
||||||
#include "internal/ping/tracker.h"
|
#include "internal/ping/tracker.h"
|
||||||
|
|
||||||
int64_t
|
int
|
||||||
ping_tracker_record_recv(struct ping_tracker *t, uint16_t seq,
|
ping_tracker_record_recv(struct ping_tracker *t, uint16_t seq)
|
||||||
const struct timespec *ts)
|
|
||||||
{
|
{
|
||||||
struct ping_tracker_slot *slot;
|
uint8_t *byte;
|
||||||
|
uint8_t bit;
|
||||||
|
|
||||||
slot = &t->slots[seq % PING_TRACKER_SLOTS];
|
byte = &t->rcvd[seq >> 3];
|
||||||
if ((slot->flags & (TRACKER_SLOT_USED | TRACKER_SLOT_ACKED))
|
bit = (uint8_t)(1u << (seq & 7u)); /* 7 == 0b111 */
|
||||||
!= TRACKER_SLOT_USED)
|
if (*byte & bit)
|
||||||
return (-1);
|
{
|
||||||
slot->flags |= TRACKER_SLOT_ACKED;
|
t->nb_dup++;
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
*byte |= bit;
|
||||||
t->nb_recv++;
|
t->nb_recv++;
|
||||||
return (icmp_time_diff_ns(&slot->ts, ts));
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,8 @@
|
||||||
|
#include "compiler.h"
|
||||||
#include "internal/ping/tracker.h"
|
#include "internal/ping/tracker.h"
|
||||||
|
|
||||||
void
|
void
|
||||||
ping_tracker_record_send(struct ping_tracker *t, uint16_t seq,
|
ping_tracker_record_send(struct ping_tracker *t, uint16_t seq __unused)
|
||||||
const struct timespec *ts)
|
|
||||||
{
|
{
|
||||||
struct ping_tracker_slot *slot;
|
|
||||||
|
|
||||||
slot = &t->slots[seq % PING_TRACKER_SLOTS];
|
|
||||||
slot->ts = *ts;
|
|
||||||
slot->flags = TRACKER_SLOT_USED;
|
|
||||||
t->nb_sent++;
|
t->nb_sent++;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,59 +1,53 @@
|
||||||
check_PROGRAMS = test_tracker test_stats test_send
|
check_PROGRAMS = test_tracker test_stats test_send
|
||||||
|
|
||||||
test_tracker_SOURCES = test_support.c ping/tracker/test_tracker.c
|
test_tracker_SOURCES = test_support.c ping/tracker/test_tracker.c
|
||||||
test_stats_SOURCES = test_support.c ping/stats/test_stats.c
|
test_stats_SOURCES = test_support.c ping/stats/test_stats.c
|
||||||
test_send_SOURCES = test_support.c send/test_do_send.c
|
test_send_SOURCES = test_support.c send/test_do_send.c
|
||||||
|
|
||||||
BASE_CFLAGS = -std=c99 $(STRICT_CFLAGS)
|
BASE_CFLAGS = -std=c99 $(STRICT_CFLAGS)
|
||||||
|
|
||||||
if ENABLE_DEBUG
|
if ENABLE_DEBUG
|
||||||
EXTRA_CFLAGS = -g -O0
|
EXTRA_CFLAGS = -g -O0
|
||||||
else
|
else
|
||||||
EXTRA_CFLAGS =
|
EXTRA_CFLAGS =
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if ENABLE_SANITIZERS
|
TEST_CPPFLAGS = \
|
||||||
SANITIZER_FLAGS = -fsanitize=address,undefined
|
-I $(top_srcdir)/includes \
|
||||||
else
|
-I $(top_srcdir)/libicmp/includes \
|
||||||
SANITIZER_FLAGS =
|
-I $(top_srcdir)/libcli/include \
|
||||||
endif
|
-I $(top_srcdir)/tests \
|
||||||
|
-D_GNU_SOURCE
|
||||||
|
|
||||||
TEST_CPPFLAGS = \
|
TEST_CFLAGS = $(BASE_CFLAGS) $(EXTRA_CFLAGS)
|
||||||
-I $(top_srcdir)/includes \
|
|
||||||
-I $(top_srcdir)/libicmp/includes \
|
|
||||||
-I $(top_srcdir)/libcli/include \
|
|
||||||
-I $(top_srcdir)/tests \
|
|
||||||
-D_GNU_SOURCE
|
|
||||||
|
|
||||||
TEST_CFLAGS = $(BASE_CFLAGS) $(EXTRA_CFLAGS) $(SANITIZER_FLAGS)
|
TEST_LDADD = \
|
||||||
|
$(top_builddir)/src/ping/libping_core.la \
|
||||||
|
$(top_srcdir)/libicmp/libicmp.a \
|
||||||
|
$(top_builddir)/libcli/src/libcli.la \
|
||||||
|
$(CRITERION_LIBS) \
|
||||||
|
-lm
|
||||||
|
|
||||||
TEST_LDADD = \
|
test_tracker_CPPFLAGS = $(TEST_CPPFLAGS)
|
||||||
$(top_builddir)/src/ping/libping_core.la \
|
test_tracker_CFLAGS = $(TEST_CFLAGS)
|
||||||
$(top_srcdir)/libicmp/libicmp.a \
|
test_tracker_LDFLAGS =
|
||||||
$(top_builddir)/libcli/src/libcli.la \
|
test_tracker_LDADD = $(TEST_LDADD)
|
||||||
$(CRITERION_LIBS) \
|
|
||||||
-lm
|
|
||||||
|
|
||||||
test_tracker_CPPFLAGS = $(TEST_CPPFLAGS)
|
test_stats_CPPFLAGS = $(TEST_CPPFLAGS)
|
||||||
test_tracker_CFLAGS = $(TEST_CFLAGS)
|
test_stats_CFLAGS = $(TEST_CFLAGS)
|
||||||
test_tracker_LDFLAGS = $(SANITIZER_FLAGS)
|
test_stats_LDFLAGS =
|
||||||
test_tracker_LDADD = $(TEST_LDADD)
|
test_stats_LDADD = $(TEST_LDADD)
|
||||||
|
|
||||||
test_stats_CPPFLAGS = $(TEST_CPPFLAGS)
|
test_send_CPPFLAGS = $(TEST_CPPFLAGS)
|
||||||
test_stats_CFLAGS = $(TEST_CFLAGS)
|
test_send_CFLAGS = $(TEST_CFLAGS)
|
||||||
test_stats_LDFLAGS = $(SANITIZER_FLAGS)
|
test_send_LDFLAGS = \
|
||||||
test_stats_LDADD = $(TEST_LDADD)
|
-Wl,--wrap=icmp_send_echo \
|
||||||
|
-Wl,--wrap=icmp_should_retry \
|
||||||
|
-Wl,--wrap=icmp_strerror \
|
||||||
|
-Wl,--wrap=ping_scheduler_arm
|
||||||
|
test_send_LDADD = $(TEST_LDADD)
|
||||||
|
|
||||||
test_send_CPPFLAGS = $(TEST_CPPFLAGS)
|
TESTS = test_tracker test_stats test_send
|
||||||
test_send_CFLAGS = $(TEST_CFLAGS)
|
|
||||||
test_send_LDFLAGS = $(SANITIZER_FLAGS) \
|
|
||||||
-Wl,--wrap=icmp_send_echo \
|
|
||||||
-Wl,--wrap=icmp_should_retry \
|
|
||||||
-Wl,--wrap=icmp_strerror \
|
|
||||||
-Wl,--wrap=ping_scheduler_arm
|
|
||||||
test_send_LDADD = $(TEST_LDADD)
|
|
||||||
|
|
||||||
TESTS = test_tracker test_stats test_send
|
|
||||||
|
|
||||||
# Version header needed by test_main.c
|
# Version header needed by test_main.c
|
||||||
BUILT_SOURCES = $(top_srcdir)/includes/version_gen.h
|
BUILT_SOURCES = $(top_srcdir)/includes/version_gen.h
|
||||||
|
|
|
||||||
|
|
@ -2,99 +2,65 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "internal/ping/tracker.h"
|
#include "internal/ping/tracker.h"
|
||||||
|
|
||||||
static struct timespec
|
|
||||||
make_ts(long sec, long nsec)
|
|
||||||
{
|
|
||||||
struct timespec ts;
|
|
||||||
|
|
||||||
ts.tv_sec = sec;
|
|
||||||
ts.tv_nsec = nsec;
|
|
||||||
return (ts);
|
|
||||||
}
|
|
||||||
|
|
||||||
Test(ping_tracker, init)
|
Test(ping_tracker, init)
|
||||||
{
|
{
|
||||||
struct ping_tracker t;
|
struct ping_tracker t;
|
||||||
|
|
||||||
ping_tracker_init(&t);
|
ping_tracker_init(&t);
|
||||||
cr_assert_eq(t.nb_sent, (size_t)0);
|
cr_assert_eq(t.nb_sent, (size_t)0);
|
||||||
cr_assert_eq(t.nb_recv, (size_t)0);
|
cr_assert_eq(t.nb_recv, (size_t)0);
|
||||||
|
cr_assert_eq(t.nb_dup, (size_t)0);
|
||||||
}
|
}
|
||||||
|
|
||||||
Test(ping_tracker, basic_send_recv)
|
Test(ping_tracker, basic_send_recv)
|
||||||
{
|
{
|
||||||
struct ping_tracker t;
|
struct ping_tracker t;
|
||||||
struct timespec ts_send;
|
int accepted;
|
||||||
struct timespec ts_recv;
|
|
||||||
int64_t rtt;
|
|
||||||
|
|
||||||
ping_tracker_init(&t);
|
ping_tracker_init(&t);
|
||||||
ts_send = make_ts(1, 0);
|
ping_tracker_record_send(&t, 1);
|
||||||
ts_recv = make_ts(1, 10000000); /* 10 ms later */
|
accepted = ping_tracker_record_recv(&t, 1);
|
||||||
ping_tracker_record_send(&t, 1, &ts_send);
|
cr_assert_eq(accepted, 1);
|
||||||
rtt = ping_tracker_record_recv(&t, 1, &ts_recv);
|
|
||||||
cr_assert_eq(rtt, (int64_t)10000000, "Expected RTT of 10ms in ns");
|
|
||||||
cr_assert_eq(t.nb_sent, (size_t)1);
|
cr_assert_eq(t.nb_sent, (size_t)1);
|
||||||
cr_assert_eq(t.nb_recv, (size_t)1);
|
cr_assert_eq(t.nb_recv, (size_t)1);
|
||||||
|
cr_assert_eq(t.nb_dup, (size_t)0);
|
||||||
}
|
}
|
||||||
|
|
||||||
Test(ping_tracker, double_recv_ignored)
|
Test(ping_tracker, double_recv_is_dup)
|
||||||
{
|
{
|
||||||
struct ping_tracker t;
|
struct ping_tracker t;
|
||||||
struct timespec ts_send;
|
int accepted;
|
||||||
struct timespec ts_recv;
|
|
||||||
int64_t rtt;
|
|
||||||
|
|
||||||
ping_tracker_init(&t);
|
ping_tracker_init(&t);
|
||||||
ts_send = make_ts(0, 0);
|
ping_tracker_record_send(&t, 5);
|
||||||
ts_recv = make_ts(0, 5000000);
|
accepted = ping_tracker_record_recv(&t, 5);
|
||||||
ping_tracker_record_send(&t, 5, &ts_send);
|
cr_assert_eq(accepted, 1, "First recv should be accepted");
|
||||||
rtt = ping_tracker_record_recv(&t, 5, &ts_recv);
|
accepted = ping_tracker_record_recv(&t, 5);
|
||||||
cr_assert(rtt >= 0, "First recv should succeed");
|
cr_assert_eq(accepted, 0, "Duplicate recv should return 0");
|
||||||
rtt = ping_tracker_record_recv(&t, 5, &ts_recv);
|
|
||||||
cr_assert_eq(rtt, (int64_t)-1, "Duplicate recv should return -1");
|
|
||||||
cr_assert_eq(t.nb_recv, (size_t)1);
|
cr_assert_eq(t.nb_recv, (size_t)1);
|
||||||
|
cr_assert_eq(t.nb_dup, (size_t)1);
|
||||||
}
|
}
|
||||||
|
|
||||||
Test(ping_tracker, unknown_seq_returns_minus_one)
|
Test(ping_tracker, unknown_seq_accepted)
|
||||||
{
|
{
|
||||||
struct ping_tracker t;
|
struct ping_tracker t;
|
||||||
struct timespec ts;
|
int accepted;
|
||||||
int64_t rtt;
|
|
||||||
|
|
||||||
ping_tracker_init(&t);
|
ping_tracker_init(&t);
|
||||||
ts = make_ts(0, 0);
|
accepted = ping_tracker_record_recv(&t, 42);
|
||||||
rtt = ping_tracker_record_recv(&t, 42, &ts);
|
cr_assert_eq(accepted, 1);
|
||||||
cr_assert_eq(rtt, (int64_t)-1);
|
cr_assert_eq(t.nb_recv, (size_t)1);
|
||||||
}
|
|
||||||
|
|
||||||
Test(ping_tracker, wraparound_seq)
|
|
||||||
{
|
|
||||||
struct ping_tracker t;
|
|
||||||
struct timespec ts_send;
|
|
||||||
struct timespec ts_recv;
|
|
||||||
int64_t rtt;
|
|
||||||
|
|
||||||
ping_tracker_init(&t);
|
|
||||||
ts_send = make_ts(0, 0);
|
|
||||||
ts_recv = make_ts(0, 1000000);
|
|
||||||
/* seq 128 maps to slot 0 */
|
|
||||||
ping_tracker_record_send(&t, 128, &ts_send);
|
|
||||||
rtt = ping_tracker_record_recv(&t, 128, &ts_recv);
|
|
||||||
cr_assert_eq(rtt, (int64_t)1000000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Test(ping_tracker, lost_count)
|
Test(ping_tracker, lost_count)
|
||||||
{
|
{
|
||||||
struct ping_tracker t;
|
struct ping_tracker t;
|
||||||
struct timespec ts;
|
|
||||||
|
|
||||||
ping_tracker_init(&t);
|
ping_tracker_init(&t);
|
||||||
ts = make_ts(0, 0);
|
ping_tracker_record_send(&t, 1);
|
||||||
ping_tracker_record_send(&t, 1, &ts);
|
ping_tracker_record_send(&t, 2);
|
||||||
ping_tracker_record_send(&t, 2, &ts);
|
ping_tracker_record_send(&t, 3);
|
||||||
ping_tracker_record_send(&t, 3, &ts);
|
ping_tracker_record_recv(&t, 2);
|
||||||
ping_tracker_record_recv(&t, 2, &ts);
|
|
||||||
cr_assert_eq(t.nb_sent, (size_t)3);
|
cr_assert_eq(t.nb_sent, (size_t)3);
|
||||||
cr_assert_eq(t.nb_recv, (size_t)1);
|
cr_assert_eq(t.nb_recv, (size_t)1);
|
||||||
cr_assert_eq(t.nb_sent - t.nb_recv, (size_t)2);
|
cr_assert_eq(t.nb_sent - t.nb_recv, (size_t)2);
|
||||||
|
|
@ -103,63 +69,36 @@ Test(ping_tracker, lost_count)
|
||||||
Test(ping_tracker, sent_count_increments)
|
Test(ping_tracker, sent_count_increments)
|
||||||
{
|
{
|
||||||
struct ping_tracker t;
|
struct ping_tracker t;
|
||||||
struct timespec ts;
|
|
||||||
|
|
||||||
ping_tracker_init(&t);
|
ping_tracker_init(&t);
|
||||||
ts = make_ts(0, 0);
|
ping_tracker_record_send(&t, 1);
|
||||||
ping_tracker_record_send(&t, 1, &ts);
|
ping_tracker_record_send(&t, 2);
|
||||||
ping_tracker_record_send(&t, 2, &ts);
|
ping_tracker_record_send(&t, 3);
|
||||||
ping_tracker_record_send(&t, 3, &ts);
|
|
||||||
cr_assert_eq(t.nb_sent, (size_t)3);
|
cr_assert_eq(t.nb_sent, (size_t)3);
|
||||||
}
|
}
|
||||||
|
|
||||||
Test(ping_tracker, recv_rtt_positive)
|
Test(ping_tracker, no_slot_collision_at_256)
|
||||||
{
|
{
|
||||||
struct ping_tracker t;
|
struct ping_tracker t;
|
||||||
struct timespec ts_send;
|
|
||||||
struct timespec ts_recv;
|
|
||||||
int64_t rtt;
|
|
||||||
|
|
||||||
ping_tracker_init(&t);
|
|
||||||
ts_send = make_ts(1, 0);
|
|
||||||
ts_recv = make_ts(1, 10000000); /* 10 ms later */
|
|
||||||
ping_tracker_record_send(&t, 7, &ts_send);
|
|
||||||
rtt = ping_tracker_record_recv(&t, 7, &ts_recv);
|
|
||||||
cr_assert(rtt > 0, "RTT should be positive");
|
|
||||||
}
|
|
||||||
|
|
||||||
Test(ping_tracker, slot_reuse_after_wraparound)
|
|
||||||
{
|
|
||||||
struct ping_tracker t;
|
|
||||||
struct timespec ts_send;
|
|
||||||
struct timespec ts_recv;
|
|
||||||
int64_t rtt;
|
|
||||||
|
|
||||||
ping_tracker_init(&t);
|
|
||||||
ts_send = make_ts(0, 0);
|
|
||||||
ts_recv = make_ts(0, 1000000);
|
|
||||||
/* seq=1 -> slot 1 */
|
|
||||||
ping_tracker_record_send(&t, 1, &ts_send);
|
|
||||||
rtt = ping_tracker_record_recv(&t, 1, &ts_recv);
|
|
||||||
cr_assert(rtt >= 0, "First round RTT should be >= 0");
|
|
||||||
/* seq=129 -> slot 129 % 128 = 1, same slot */
|
|
||||||
ping_tracker_record_send(&t, 129, &ts_send);
|
|
||||||
rtt = ping_tracker_record_recv(&t, 129, &ts_recv);
|
|
||||||
cr_assert(rtt >= 0, "Second round RTT should be >= 0");
|
|
||||||
cr_assert_eq(t.nb_sent, (size_t)2);
|
|
||||||
cr_assert_eq(t.nb_recv, (size_t)2);
|
|
||||||
}
|
|
||||||
|
|
||||||
Test(ping_tracker, full_buffer)
|
|
||||||
{
|
|
||||||
struct ping_tracker t;
|
|
||||||
struct timespec ts;
|
|
||||||
uint16_t seq;
|
uint16_t seq;
|
||||||
|
|
||||||
ping_tracker_init(&t);
|
ping_tracker_init(&t);
|
||||||
ts = make_ts(0, 0);
|
for (seq = 0; seq < 256; seq++)
|
||||||
for (seq = 1; seq <= 128; seq++)
|
{
|
||||||
ping_tracker_record_send(&t, seq, &ts);
|
ping_tracker_record_send(&t, seq);
|
||||||
cr_assert_eq(t.nb_sent, (size_t)128);
|
cr_assert_eq(ping_tracker_record_recv(&t, seq), 1,
|
||||||
cr_assert_eq(t.nb_recv, (size_t)0);
|
"seq %u should be accepted", (unsigned)seq);
|
||||||
|
}
|
||||||
|
cr_assert_eq(t.nb_recv, (size_t)256);
|
||||||
|
}
|
||||||
|
|
||||||
|
Test(ping_tracker, full_seq_space)
|
||||||
|
{
|
||||||
|
struct ping_tracker t;
|
||||||
|
uint32_t seq;
|
||||||
|
|
||||||
|
ping_tracker_init(&t);
|
||||||
|
for (seq = 0; seq < 65536; seq++)
|
||||||
|
ping_tracker_record_send(&t, (uint16_t)seq);
|
||||||
|
cr_assert_eq(t.nb_sent, (size_t)65536);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
#include "internal/ping/ping_state.h"
|
#include "internal/ping/ping_state.h"
|
||||||
#include "internal/ping/tracker.h"
|
#include "internal/ping/tracker.h"
|
||||||
#include "ping/ping.h"
|
#include "ping/ping.h"
|
||||||
|
#include "ping/ft_ping_const.h"
|
||||||
|
|
||||||
/* Controllable mock state */
|
/* Controllable mock state */
|
||||||
int g_mock_send_ret;
|
int g_mock_send_ret;
|
||||||
|
|
@ -104,3 +105,23 @@ Test(do_send, eagain_then_success_uses_same_seq, .init = setup)
|
||||||
cr_assert_eq(g_state.seq, (uint16_t)1);
|
cr_assert_eq(g_state.seq, (uint16_t)1);
|
||||||
cr_assert_eq(g_tracker.nb_sent, (size_t)1);
|
cr_assert_eq(g_tracker.nb_sent, (size_t)1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Test(do_send, ts_in_payload_increments_seq, .init = setup)
|
||||||
|
{
|
||||||
|
g_mock_send_ret = 0;
|
||||||
|
g_state.ts_in_payload = 1;
|
||||||
|
do_send(&g_state, PING_TIMESTAMP_SIZE);
|
||||||
|
cr_assert_eq(g_state.seq, (uint16_t)1);
|
||||||
|
cr_assert_eq(g_tracker.nb_sent, (size_t)1);
|
||||||
|
}
|
||||||
|
|
||||||
|
Test(do_send, ts_in_payload_multiple_sends, .init = setup)
|
||||||
|
{
|
||||||
|
g_mock_send_ret = 0;
|
||||||
|
g_state.ts_in_payload = 1;
|
||||||
|
do_send(&g_state, PING_TIMESTAMP_SIZE);
|
||||||
|
do_send(&g_state, PING_TIMESTAMP_SIZE);
|
||||||
|
do_send(&g_state, PING_TIMESTAMP_SIZE);
|
||||||
|
cr_assert_eq(g_state.seq, (uint16_t)3);
|
||||||
|
cr_assert_eq(g_tracker.nb_sent, (size_t)3);
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue