linux – 網路設備 ioctl 命令參數範圍:SIOCDEVPRIVATE(0-15)

struct iwreq iwr;
s = socket(AF_INET, SOCK_DGRAM, 0);

ioctl(s, (SIOCDEVPRIVATE+15), &iwr) 正常调用
ioctl(s, (SIOCDEVPRIVATE+16), &iwr) 返回错误,应为内核代码只分配了0-15的空间为用户私有可用的。

见代码:
linux/net/code/dev.c

 /*
   * Unknown or private ioctl.
   */
  default:
   if (cmd == SIOCWANDEV ||
       (cmd >= SIOCDEVPRIVATE &&
        cmd <= SIOCDEVPRIVATE + 15)) {
    dev_load(net, ifr.ifr_name);
    rtnl_lock();
    ret = dev_ifsioc(net, &ifr, cmd);
    rtnl_unlock();
    if (!ret && copy_to_user(arg, &ifr,
        sizeof(struct ifreq)))
     ret = -EFAULT;
    return ret;
   }
   /* Take care of Wireless Extensions */
   if (cmd >= SIOCIWFIRST && cmd <= SIOCIWLAST)
    return wext_handle_ioctl(net, &ifr, cmd, arg);
   return -EINVAL;

------------------------------
其中
(cmd >= SIOCDEVPRIVATE && cmd <= SIOCDEVPRIVATE + 15)) 为用户私有,所以在ioctl调用时,只能使用(SIOCDEVPRIVATE+0)到 (SIOCDEVPRIVATE+15),

發表迴響