Implement IPV6_MULTICAST_HOPS socket option

Implements the IPV6_MULTICAST_HOPS socket option, which sets
the hop limit for outgoing multicast packets.

Also fixes debug message in getsockopt for IP_MULTICAST_TTL.

Based on work from https://savannah.nongnu.org/patch/?9554

Co-authored-by: Christina Schoenrogge <christina.schoenrogge@garmin.com>
Co-authored-by: Chee Bin Hoh <hohcheebin@gmail.com>
Co-authored-by: hanhui <hanhui03@163.com>
This commit is contained in:
Nate Karstens 2023-05-10 09:58:30 -05:00
parent e27013aec3
commit 545a57ce60
2 changed files with 12 additions and 1 deletions

View File

@ -3083,7 +3083,7 @@ lwip_getsockopt_impl(int s, int level, int optname, void *optval, socklen_t *opt
LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB_TYPE(sock, *optlen, u8_t, NETCONN_UDP);
*(u8_t *)optval = udp_get_multicast_ttl(sock->conn->pcb.udp);
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_IP, IP_MULTICAST_TTL) = %d\n",
s, *(int *)optval));
s, *(u8_t *)optval));
break;
case IP_MULTICAST_IF:
LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB_TYPE(sock, *optlen, struct in_addr, NETCONN_UDP);
@ -3180,6 +3180,12 @@ lwip_getsockopt_impl(int s, int level, int optname, void *optval, socklen_t *opt
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_IPV6, IPV6_MULTICAST_IF) = %d\n",
s, *(int *)optval));
break;
case IPV6_MULTICAST_HOPS:
LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB_TYPE(sock, *optlen, u8_t, NETCONN_UDP);
*(u8_t *)optval = udp_get_multicast_ttl(sock->conn->pcb.udp);
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_IPV6, IPV6_MULTICAST_HOPS) = %d\n",
s, *(u8_t *)optval));
break;
#endif /* LWIP_MULTICAST_TX_OPTIONS && LWIP_UDP */
default:
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_IPV6, UNIMPL: optname=0x%x, ..)\n",
@ -3675,6 +3681,10 @@ lwip_setsockopt_impl(int s, int level, int optname, const void *optval, socklen_
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_IPV6, IPV6_MULTICAST_IF, ..) -> %d\n",
s, *(int *)optval));
break;
case IPV6_MULTICAST_HOPS:
LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB_TYPE(sock, optlen, u8_t, NETCONN_UDP);
udp_set_multicast_ttl(sock->conn->pcb.udp, (u8_t)(*(const u8_t *)optval));
break;
#endif /* LWIP_MULTICAST_TX_OPTIONS && LWIP_UDP */
#if LWIP_IPV6_MLD
case IPV6_JOIN_GROUP:

View File

@ -319,6 +319,7 @@ struct linger {
#define IP_MULTICAST_LOOP 7
#define IPV6_MULTICAST_IF 17 /* RFC3493: interface for outgoing multicast packets */
#define IPV6_MULTICAST_HOPS 18 /* RFC3493: hop limit for outgoing multicast packets */
#endif /* LWIP_MULTICAST_TX_OPTIONS */
#if LWIP_IGMP