feat: set TOS
This commit is contained in:
parent
e6693c97cc
commit
71ca9abc2e
3 changed files with 27 additions and 0 deletions
|
|
@ -76,6 +76,7 @@ int icmp_error_extract_offending(const icmp_reply_t *reply,
|
||||||
|
|
||||||
/* Socket options */
|
/* Socket options */
|
||||||
int icmp_set_dont_fragment(icmp_handle_t *h);
|
int icmp_set_dont_fragment(icmp_handle_t *h);
|
||||||
|
int icmp_set_tos(icmp_handle_t *h, uint8_t tos);
|
||||||
|
|
||||||
/* Error handling */
|
/* Error handling */
|
||||||
const char *icmp_strerror(const icmp_handle_t *h);
|
const char *icmp_strerror(const icmp_handle_t *h);
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ SRCS += $(SRC_DIR)/error/should_retry.c
|
||||||
SRCS += $(SRC_DIR)/socket/create.c
|
SRCS += $(SRC_DIR)/socket/create.c
|
||||||
SRCS += $(SRC_DIR)/socket/configure.c
|
SRCS += $(SRC_DIR)/socket/configure.c
|
||||||
SRCS += $(SRC_DIR)/socket/set_dont_fragment.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/create.c
|
||||||
SRCS += $(SRC_DIR)/handle/destroy.c
|
SRCS += $(SRC_DIR)/handle/destroy.c
|
||||||
SRCS += $(SRC_DIR)/handle/get_fd.c
|
SRCS += $(SRC_DIR)/handle/get_fd.c
|
||||||
|
|
|
||||||
25
src/socket/set_tos.c
Normal file
25
src/socket/set_tos.c
Normal 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;
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue