21 lines
434 B
C
21 lines
434 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;
|
|
|
|
if (setsockopt(h->fd, IPPROTO_IP, IP_TTL, &ttl_val, sizeof(ttl_val)) < 0)
|
|
{
|
|
int saved_errno = errno;
|
|
icmp_set_error_fmt(h, ICMP_ERR_SOCKET, "Failed to set TTL: %s",
|
|
strerror(saved_errno));
|
|
return -1;
|
|
}
|
|
|
|
return 0;
|
|
}
|