From 2ca483cd4b3da0a7b2c775db69f812f6a1a6fa1c Mon Sep 17 00:00:00 2001 From: bert hubert Date: Sun, 24 Feb 2019 11:18:11 +0100 Subject: [PATCH] ip.7: IP_RECVTTL error fixed I need to get the TTL of UDP datagrams from userspace, so I set the IP_RECVTTL socket option. And as promised by ip.7, I then get IP_TTL messages from recvfrom. However, unlike what the manpage promises, the TTL field gets passed as a 32 bit integer. The following userspace code works: uint32_t ttl32; for (cmsg = CMSG_FIRSTHDR(msgh); cmsg != NULL; cmsg = CMSG_NXTHDR(msgh,cmsg)) { if ((cmsg->cmsg_level == IPPROTO_IP) && (cmsg->cmsg_type == IP_TTL) && CMSG_LEN(sizeof(ttl32)) == cmsg->cmsg_len) { memcpy(&ttl32, CMSG_DATA(cmsg), sizeof(ttl32)); *ttl=ttl32; return true; } else cerr<<"Saw something else "<<(cmsg->cmsg_type == IP_TTL) << ", "<<(int)cmsg->cmsg_level<<", "<cmsg_len<<", "<< CMSG_LEN(1)<ttl; put_cmsg(msg, SOL_IP, IP_TTL, sizeof(int), &ttl); } ]] Signed-off-by: Michael Kerrisk --- man7/ip.7 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/man7/ip.7 b/man7/ip.7 index 02dd47f2a..d664eddb1 100644 --- a/man7/ip.7 +++ b/man7/ip.7 @@ -874,7 +874,7 @@ Expects a boolean integer flag. When this flag is set, pass a .B IP_TTL control message with the time-to-live -field of the received packet as a byte. +field of the received packet as a 32 bit integer. Not supported for .B SOCK_STREAM sockets.