anchao commented on code in PR #7020: URL: https://github.com/apache/incubator-nuttx/pull/7020#discussion_r964337633
########## 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) || Review Comment: I will split the part "struct ifreq" commands out of net_ioctl_arglen() to ensure the consistency of parameter -- 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-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org