如何使用命令 SIOCGIFFLAGS 和 SIOCSIFFLAGS 以原子方式调用 ioctl
有没有办法以原子方式使用命令 SIOCGIFFLAGS
和 SIOCSIFFLAGS
调用 ioctl(该问题对所有系统调用也有效)?例如,如果我将 IFF_PROMISC 标志添加到接口:
...
struct ifreq ifr;
memset(&ifr, 0, sizeof(ifr));
strcpy(ifr.ifr_name, "eth0");
if (ioctl(sk, SIOCGIFFLAGS, &ifr) < 0)
...
ifr.ifr_flags |= IFF_PROMISC;
if (ioctl(sk, SIOCSIFFLAGS, &ifr) < 0)
...
如何确保这两个调用以原子方式进行?
谢谢大家!
Is there a way to call ioctl (the question is also valid for all sys calls) with commands SIOCGIFFLAGS
and SIOCSIFFLAGS
in an atomic manner? For example if i would add the IFF_PROMISC
flag to an interface:
...
struct ifreq ifr;
memset(&ifr, 0, sizeof(ifr));
strcpy(ifr.ifr_name, "eth0");
if (ioctl(sk, SIOCGIFFLAGS, &ifr) < 0)
...
ifr.ifr_flags |= IFF_PROMISC;
if (ioctl(sk, SIOCSIFFLAGS, &ifr) < 0)
...
how can i ensure that these two calls are made atomically?
Thank you all!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
简单的答案是你不能 - 没有办法保证另一个进程没有更改这些调用之间的标志。
The simple answer is that you can't - there is no way to guarantee that another process hasn't changed the flags in between those calls.