Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically enable/disable UNIX network interface

There are a lot of very similar questions posted, but they are all for windows - I want to know how (if it is possible) I can have my C program (run as root, on linux) disable the network interface so that it is no longer receiving any packets.

If someone can tell me what functions I need to do this, that would be great, but even better if you can link me to an example script or tutorial somewhere that (exempli gratia) turns the network interface off and on again.

like image 553
Benubird Avatar asked Feb 23 '11 17:02

Benubird


1 Answers

Don't have a complete example, but the following key words should get you started (on Linux at least, not sure about other flavours of Unix):

ioctl, SIOCSIFFLAGS, IFF_UP

The following might be of use as far as showing the relevant APIs: http://www.google.com/codesearch/p?hl=en#2--Ws53NXRc/src/ifdown.c

like image 187
NPE Avatar answered Oct 09 '22 16:10

NPE