diff --git a/net/inet/ipv4_setsockopt.c b/net/inet/ipv4_setsockopt.c index e1e21eb7ac..b5bb7bcc21 100644 --- a/net/inet/ipv4_setsockopt.c +++ b/net/inet/ipv4_setsockopt.c @@ -51,6 +51,7 @@ #include "netdev/netdev.h" #include "igmp/igmp.h" #include "inet/inet.h" +#include "udp/udp.h" #ifdef CONFIG_NET_IPv4 @@ -184,12 +185,37 @@ int ipv4_setsockopt(FAR struct socket *psock, int option, } break; + case IP_MULTICAST_TTL: /* Set/read the time-to-live value of + * outgoing multicast packets */ + { + if (psock->s_type != SOCK_DGRAM || + value_len != sizeof(int)) + { + ret = -EINVAL; + } + else + { + FAR struct udp_conn_s *conn; + int ttl = *(FAR int *)value; + + if (ttl <= 0 || ttl > 255) + { + ret = -EINVAL; + } + else + { + conn = (FAR struct udp_conn_s *)psock->s_conn; + conn->ttl = ttl; + ret = OK; + } + } + } + break; + /* The following IPv4 socket options are defined, but not implemented */ case IP_MULTICAST_IF: /* Set local device for a multicast * socket */ - case IP_MULTICAST_TTL: /* Set/read the time-to-live value of - * outgoing multicast packets */ case IP_MULTICAST_LOOP: /* Set/read boolean that determines * whether sent multicast packets * should be looped back to local