libicmp/src/send/helpers/set_socket_ttl.c

22 lines
448 B
C

#include "internal/icmp_send.h"
#include <sys/socket.h>
#include <netinet/in.h>
#include <errno.h>
#include <string.h>
int
send_set_socket_ttl(struct icmp_handle *h, uint8_t ttl)
{
int ttl_val = ttl;
int saved_errno;
if (setsockopt(h->fd, IPPROTO_IP, IP_TTL, &ttl_val, sizeof(ttl_val)) < 0)
{
saved_errno = errno;
icmp_set_error_fmt(h, ICMP_ERR_SOCKET, "Failed to set TTL: %s",
strerror(saved_errno));
return -1;
}
return 0;
}