You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by bt...@apache.org on 2020/12/05 18:45:04 UTC

[incubator-nuttx] 01/03: net/igmp: add MULTICAST_TTL support

This is an automated email from the ASF dual-hosted git repository.

btashton pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit 4af687b8c23b6775eaf9660076d2054055219a1e
Author: chao.an <an...@xiaomi.com>
AuthorDate: Thu Dec 3 13:53:50 2020 +0800

    net/igmp: add MULTICAST_TTL support
    
    Signed-off-by: chao.an <an...@xiaomi.com>
---
 net/inet/ipv4_setsockopt.c | 30 ++++++++++++++++++++++++++++--
 1 file changed, 28 insertions(+), 2 deletions(-)

diff --git a/net/inet/ipv4_setsockopt.c b/net/inet/ipv4_setsockopt.c
index e1e21eb..b5bb7bc 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