From 46df08ba31a8ce602ff09d2cd57cc123576e88d7 Mon Sep 17 00:00:00 2001 From: "chao.an" Date: Sat, 5 Dec 2020 17:33:29 +0800 Subject: [PATCH] net/setsockopt/IP_MULTICAST_TTL: add handles of different prototypes Reference here: https://github.com/torvalds/linux/blob/b3298500b23f0b53a8d81e0d5ad98a29db71f4f0/net/ipv4/ip_sockglue.c#L923-L932 Change-Id: Iad67c756eb549d969bd7a8ffe965d9b1dcc56988 Signed-off-by: chao.an --- net/inet/ipv4_setsockopt.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/net/inet/ipv4_setsockopt.c b/net/inet/ipv4_setsockopt.c index 995b750b113..7d08910c838 100644 --- a/net/inet/ipv4_setsockopt.c +++ b/net/inet/ipv4_setsockopt.c @@ -192,38 +192,40 @@ int ipv4_setsockopt(FAR struct socket *psock, int option, case IP_MULTICAST_TTL: /* Set/read the time-to-live value of * outgoing multicast packets */ { + FAR struct udp_conn_s *conn; + int ttl; + if (psock->s_type != SOCK_DGRAM || - value_len != sizeof(int)) + value == NULL || value_len == 0) + { + ret = -EINVAL; + break; + } + + ttl = (value_len >= sizeof(int)) ? + *(FAR int *)value : (int)*(FAR unsigned char *)value; + + if (ttl <= 0 || ttl > 255) { 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; - } + 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_LOOP: /* Set/read boolean that determines * whether sent multicast packets * should be looped back to local * sockets. */ - case IP_MULTICAST_IF: /* Set local device for a multicast - * socket */ case IP_UNBLOCK_SOURCE: /* Unblock previously blocked multicast * source */ case IP_BLOCK_SOURCE: /* Stop receiving multicast data from