IP_RECVTTL socket option.

Reviewed by:	Stuart Cheshire <cheshire@apple.com>
This commit is contained in:
Matthew N. Dodd 2003-04-29 21:36:18 +00:00
parent 2d5d213f82
commit 4957466b8e
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=114258
5 changed files with 42 additions and 1 deletions

View File

@ -164,6 +164,28 @@ control message from
can be used directly as a control message for
.Xr sendmsg 2 .
.Pp
If the
.Dv IP_RECVTTL
option is enabled on a
.Dv SOCK_DGRAM
socket, the
.Xr recvmsg 2
call will return the
.Tn IP
.Tn TTL
(time to live) field for a
.Tn UDP
datagram.
The msg_control field in the msghdr structure points to a buffer
that contains a cmsghdr structure followed by the
.Tn TTL .
The cmsghdr fields have the following values:
.Bd -literal
cmsg_len = sizeof(u_char)
cmsg_level = IPPROTO_IP
cmsg_type = IP_RECVTTL
.Ed
.Pp
If the
.Dv IP_RECVIF
option is enabled on a

View File

@ -399,6 +399,8 @@ __END_DECLS
#define IP_DUMMYNET_FLUSH 62 /* flush dummynet */
#define IP_DUMMYNET_GET 64 /* get entire dummynet pipes */
#define IP_RECVTTL 65 /* bool; receive IP TTL w/dgram */
/*
* Defaults and limits for options
*/

View File

@ -276,6 +276,7 @@ struct inpcbinfo { /* XXX documentation, prefixes */
#define INP_RECVIF 0x80 /* receive incoming interface */
#define INP_MTUDISC 0x100 /* user can do MTU discovery */
#define INP_FAITH 0x200 /* accept FAITH'ed connections */
#define INP_RECVTTL 0x400 /* receive incoming IP TTL */
#define IN6P_IPV6_V6ONLY 0x008000 /* restrict AF_INET6 socket for v6 */
@ -288,7 +289,7 @@ struct inpcbinfo { /* XXX documentation, prefixes */
#define IN6P_AUTOFLOWLABEL 0x800000 /* attach flowlabel automatically */
#define INP_CONTROLOPTS (INP_RECVOPTS|INP_RECVRETOPTS|INP_RECVDSTADDR|\
INP_RECVIF|\
INP_RECVIF|INP_RECVTTL|\
IN6P_PKTINFO|IN6P_HOPLIMIT|IN6P_HOPOPTS|\
IN6P_DSTOPTS|IN6P_RTHDR|IN6P_RTHDRDSTOPTS|\
IN6P_AUTOFLOWLABEL)

View File

@ -2052,6 +2052,12 @@ ip_savecontrol(inp, mp, ip, m)
if (*mp)
mp = &(*mp)->m_next;
}
if (inp->inp_flags & INP_RECVTTL) {
*mp = sbcreatecontrol((caddr_t) &ip->ip_ttl,
sizeof(u_char), IP_RECVTTL, IPPROTO_IP);
if (*mp)
mp = &(*mp)->m_next;
}
#ifdef notyet
/* XXX
* Moving these out of udp_input() made them even more broken

View File

@ -1424,6 +1424,7 @@ ip_ctloutput(so, sopt)
case IP_RECVOPTS:
case IP_RECVRETOPTS:
case IP_RECVDSTADDR:
case IP_RECVTTL:
case IP_RECVIF:
case IP_FAITH:
error = sooptcopyin(sopt, &optval, sizeof optval,
@ -1457,6 +1458,10 @@ ip_ctloutput(so, sopt)
OPTSET(INP_RECVDSTADDR);
break;
case IP_RECVTTL:
OPTSET(INP_RECVTTL);
break;
case IP_RECVIF:
OPTSET(INP_RECVIF);
break;
@ -1553,6 +1558,7 @@ ip_ctloutput(so, sopt)
case IP_RECVOPTS:
case IP_RECVRETOPTS:
case IP_RECVDSTADDR:
case IP_RECVTTL:
case IP_RECVIF:
case IP_PORTRANGE:
case IP_FAITH:
@ -1580,6 +1586,10 @@ ip_ctloutput(so, sopt)
optval = OPTBIT(INP_RECVDSTADDR);
break;
case IP_RECVTTL:
optval = OPTBIT(INP_RECVTTL);
break;
case IP_RECVIF:
optval = OPTBIT(INP_RECVIF);
break;