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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
/* * Unknown or private ioctl. */ default: if (cmd == SIOCWANDEV || <strong> (cmd >= SIOCDEVPRIVATE && cmd <= SIOCDEVPRIVATE + 15)</strong>) { 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),