From 71ca9abc2e05de9cf61b135a4699ed3bb97a8969 Mon Sep 17 00:00:00 2001 From: lohhiiccc <96543753+lohhiiccc@users.noreply.github.com> Date: Thu, 23 Apr 2026 13:53:35 +0200 Subject: [PATCH] feat: set TOS --- includes/icmp.h | 1 + sources.mk | 1 + src/socket/set_tos.c | 25 +++++++++++++++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 src/socket/set_tos.c diff --git a/includes/icmp.h b/includes/icmp.h index 2a11fe9..5c13ff2 100644 --- a/includes/icmp.h +++ b/includes/icmp.h @@ -76,6 +76,7 @@ int icmp_error_extract_offending(const icmp_reply_t *reply, /* Socket options */ int icmp_set_dont_fragment(icmp_handle_t *h); +int icmp_set_tos(icmp_handle_t *h, uint8_t tos); /* Error handling */ const char *icmp_strerror(const icmp_handle_t *h); diff --git a/sources.mk b/sources.mk index a1c402b..d745d49 100644 --- a/sources.mk +++ b/sources.mk @@ -9,6 +9,7 @@ SRCS += $(SRC_DIR)/error/should_retry.c SRCS += $(SRC_DIR)/socket/create.c SRCS += $(SRC_DIR)/socket/configure.c SRCS += $(SRC_DIR)/socket/set_dont_fragment.c +SRCS += $(SRC_DIR)/socket/set_tos.c SRCS += $(SRC_DIR)/handle/create.c SRCS += $(SRC_DIR)/handle/destroy.c SRCS += $(SRC_DIR)/handle/get_fd.c diff --git a/src/socket/set_tos.c b/src/socket/set_tos.c new file mode 100644 index 0000000..767016c --- /dev/null +++ b/src/socket/set_tos.c @@ -0,0 +1,25 @@ +#include +#include +#include +#include + +#include "internal/icmp_internal.h" + +int +icmp_set_tos(struct icmp_handle *h, uint8_t tos) +{ + int val; + int saved_errno; + + if (NULL == h) + return -1; + val = (int)tos; + if (0 > setsockopt(h->fd, IPPROTO_IP, IP_TOS, &val, sizeof(val))) + { + saved_errno = errno; + icmp_set_error_fmt(h, ICMP_ERR_SOCKET, + "Failed to set TOS: %s", strerror(saved_errno)); + return -1; + } + return 0; +}