feat: set TOS

This commit is contained in:
lohhiiccc 2026-04-23 13:53:35 +02:00 committed by lohhiiccc
parent 812e3a0ed5
commit ac9ca93d9f
3 changed files with 27 additions and 0 deletions

View file

@ -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);

View file

@ -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

25
src/socket/set_tos.c Normal file
View file

@ -0,0 +1,25 @@
#include <sys/socket.h>
#include <netinet/in.h>
#include <errno.h>
#include <string.h>
#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;
}