title: Sending IOCTL Call to Network Driver using Python
body: <p>I would like to send an IOCTL call from a Python application to a fake network interface I have running in Ubuntu 12.04. I know that I can open a socket and bind it to the network that the fake network interface is governing, and then use <code>fcntl.ioctl(socket, IOC_COMMAND_NUM, some_struct)</code> to send an IOCTL call. But, this seems to use a different network interface than I need it to. So, my question is, how can I ensure that a specific network interface is used? And, it seems like a lot of trouble to open a socket just to send an IOCTL call, so is there anyway to bypass that step? Below is some sample Python code that behaves as mentioned above.</p>
  
  <pre><code>&gt;&gt;&gt; sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  &gt;&gt;&gt; sock.bind(("192.168.0.1",0))
  &gt;&gt;&gt; fcntl.ioctl(sock,IOC_COMMAND_NUM,some_struct)
  Traceback (most recent call last):
      File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  IOError: [Errno 25] Inappropriate ioctl for device
  
  # This proves that it is sending the IOCTL to a different interface because my
  # interface automatically returns success for any IOCTL call. 
  </code></pre>
  
  <p>Below is the output of <code>ifconfig myDummyNetInter</code>.</p>
  
  <pre><code>myDummyNetInter0 Link encap:Ethernet  HWaddr e2:44:46:d5:79:3e  
        inet addr:192.168.0.1  Bcast:192.168.0.255  Mask:255.255.255.0
        inet6 addr: fe80::e044:46ff:fed5:793e/64 Scope:Link
        UP BROADCAST RUNNING NOARP  MTU:1500  Metric:1
        RX packets:0 errors:0 dropped:0 overruns:0 frame:0
        TX packets:24 errors:0 dropped:0 overruns:0 carrier:0
        collisions:0 txqueuelen:0 
        RX bytes:0 (0.0 B)  TX bytes:2682 (2.6 KB)
  </code></pre>
  
  <p>If it helps, I do have another application written in C++ using this network interface without any problems. (Including IOCTL calls.)</p>
  
  <p>Thanks, I appreciate any and all help.</p>