2

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!

MirkoBanchi
  • 2,173
  • 5
  • 35
  • 52

1 Answers1

2

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.

TomH
  • 8,900
  • 2
  • 32
  • 30