Reputation: 111
is there a way to set ttl from application? Using c++ rh, not using boost. In /etc/sysctl.conf file value net.ipv4.ip_default_ttl is not present, in /proc/sys/net/ipv4/ip_default_ttl written 64. I am sending traffic to multicast group and see TTL=1. Would like to increase it to 3. Thanks.
Upvotes: 1
Views: 1811
Reputation: 26332
You can configure it per socket, using the IP_MULTICAST_TTL setsockopt() flag. Take a look at the man pages for ip and setsockopt.
Something like the following:
void setttl(int sock, uint8_t ttl)
{
int ret = setsockopt(sock, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof(uint8_t));
if (ret != 0)
printf("Failed to setsockopt(): %s\n", strerror(errno));
}
Upvotes: 3