You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2022/09/07 03:00:02 UTC

[GitHub] [incubator-nuttx] anchao commented on a diff in pull request #7020: net/netdev: simplify handling of netdev ifr ioctl()

anchao commented on code in PR #7020:
URL: https://github.com/apache/incubator-nuttx/pull/7020#discussion_r964336747


##########
net/netdev/netdev_ioctl.c:
##########
@@ -636,235 +636,204 @@ static FAR struct net_driver_s *netdev_ifr_dev(FAR struct ifreq *req)
 static int netdev_ifr_ioctl(FAR struct socket *psock, int cmd,
                             FAR struct ifreq *req)
 {
-  FAR struct net_driver_s *dev;
-  int ret = -EINVAL;
+  FAR struct net_driver_s *dev = NULL;
+  FAR struct net_driver_s *tmpdev;
+  ssize_t arglen;
+  int ret;
 
   ninfo("cmd: %d\n", cmd);
 
   net_lock();
 
-  /* Execute the command */
+  /* Execute the command without ifr_name or lifr_name */

Review Comment:
   Thank you, done!



##########
net/netdev/netdev_ioctl.c:
##########
@@ -636,235 +636,204 @@ static FAR struct net_driver_s *netdev_ifr_dev(FAR struct ifreq *req)
 static int netdev_ifr_ioctl(FAR struct socket *psock, int cmd,
                             FAR struct ifreq *req)
 {
-  FAR struct net_driver_s *dev;
-  int ret = -EINVAL;
+  FAR struct net_driver_s *dev = NULL;
+  FAR struct net_driver_s *tmpdev;
+  ssize_t arglen;
+  int ret;
 
   ninfo("cmd: %d\n", cmd);
 
   net_lock();
 
-  /* Execute the command */
+  /* Execute the command without ifr_name or lifr_name */
 
   switch (cmd)
     {
+      case SIOCGIFCOUNT:  /* Get number of devices */
+        {
+          req->ifr_count = netdev_count();
+          ret = OK;
+        }
+        break;
+
 #ifdef CONFIG_NET_IPv4
-      case SIOCGIFADDR:  /* Get IP address */
+      case SIOCGIFCONF:  /* Return an interface list (IPv4) */
         {
-          dev = netdev_ifr_dev(req);
-          if (dev)
-            {
-              ioctl_get_ipv4addr(&req->ifr_addr, dev->d_ipaddr);
-              ret = OK;
-            }
+          ret = netdev_ipv4_ifconf((FAR struct ifconf *)req);
         }
         break;
 #endif
 
-#ifdef CONFIG_NET_IPv4
-      case SIOCSIFADDR:  /* Set IP address */
+#ifdef CONFIG_NET_IPv6
+      case SIOCGLIFCONF:  /* Return an interface list (IPv6) */
         {
-          dev = netdev_ifr_dev(req);
-          if (dev)
-            {
-              ioctl_set_ipv4addr(&dev->d_ipaddr, &req->ifr_addr);
-              ret = OK;
-            }
+          ret = netdev_ipv6_ifconf((FAR struct lifconf *)req);
         }
         break;
 #endif
 
-#ifdef CONFIG_NET_IPv4
-      case SIOCGIFDSTADDR:  /* Get P-to-P address */
+#ifdef CONFIG_NETDEV_IFINDEX
+      case SIOCGIFNAME:  /* Get interface name */
         {
-          dev = netdev_ifr_dev(req);
-          if (dev)
+          tmpdev = netdev_findbyindex(req->ifr_ifindex);
+          if (tmpdev != NULL)
             {
-              ioctl_get_ipv4addr(&req->ifr_dstaddr, dev->d_draddr);
+              strlcpy(req->ifr_name, tmpdev->d_ifname, IFNAMSIZ);
               ret = OK;
             }
+          else
+            {
+              ret = -ENODEV;
+            }
         }
         break;
 #endif
-
-#ifdef CONFIG_NET_IPv4
-      case SIOCSIFDSTADDR:  /* Set P-to-P address */
+      default:
         {
-          dev = netdev_ifr_dev(req);
-          if (dev)
+          arglen = net_ioctl_arglen(cmd);
+
+          if (arglen == sizeof(struct ifreq) ||
+              arglen == sizeof(struct lifreq))
             {
-              ioctl_set_ipv4addr(&dev->d_draddr, &req->ifr_dstaddr);
-              ret = OK;
+              dev = netdev_ifr_dev(req);
+              ret = (dev == NULL) ? -ENODEV : OK;
+            }
+          else
+            {
+              ret = -ENOTTY;
             }
         }
         break;
-#endif
+    }
 
+  if (dev == NULL)
+    {
+      return ret;
+    }
+
+  /* Execute the command with ifr_name or lifr_name */

Review Comment:
   Done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org