Home > Software engineering >  Address family not supported by protocol While using Scapy L3socket with WSL
Address family not supported by protocol While using Scapy L3socket with WSL

Time:06-15

I tried to use Scapy to configure L3 socket like :

from scapy.all import *
soc = conf.L3socket(iface="eth1")

When I use this code in Ubuntu VM everything is OK , but when I used this code with WSL I got that error:

/usr/local/lib/python3.10/dist-packages/scapy/layers/ipsec.py:471: CryptographyDeprecationWarning: Blowfish has been deprecated
  cipher=algorithms.Blowfish,
/usr/local/lib/python3.10/dist-packages/scapy/layers/ipsec.py:485: CryptographyDeprecationWarning: CAST5 has been deprecated
  cipher=algorithms.CAST5,
Traceback (most recent call last):
  File "........./python/test.py", line 2, in <module>
    soc = conf.L3socket(iface="eth1")
  File "/usr/local/lib/python3.10/dist-packages/scapy/arch/linux.py", line 486, in __init__
    self.ins = socket.socket(
  File "/usr/lib/python3.10/socket.py", line 232, in __init__
    _socket.socket.__init__(self, family, type, proto, fileno)
OSError: [Errno 97] Address family not supported by protocol

How can I fix that ?

CodePudding user response:

First, I have a strong hunch you are actually using a WSL1 instance. Start by double-checking that with wsl.exe -l -v.

It's quite common to have WSL2 installed/enabled but still have WSL1 instances that were never converted to WSL2.

A couple of things indicate this is WSL1:

  • You have an eth1 interface -- WSL2 typically doesn't, since it only sets up one virtual ethernet device for use by the Linux kernel.

    WSL1, on the other hand, uses the Windows API (through a syscall translation layer) to enumerate the actual network interfaces available to Windows.

  • The error message OSError: [Errno 97] Address family not supported by protocol is only seen on WSL1. The syscall translation layer does not provide full implementation of all Linux APIs, and network interface configuration is one area that isn't fully implemented.

So at the least, you'll need to convert to WSL2 for this to work. Assuming that WSL2 is actually installed and available on your system, you can do this by:

  • Exiting WSL
  • From PowerShell:
    • Confirm the name of the instance/distro with wsl -l -v.
    • (Optionally) back up the existing instance with wsl --export distro_name path/to/backup.tar
    • wsl --set-version <distro_name> 2

You should still understand that, under WSL2, the network interface does run under a normal Linux kernel with all capabilities. However, it is a virtualized NIC running behind a NAT'd virtual switch. There's not much control over that switch at the moment, although that's changing to some degree. That said, layer 3 should work just fine in WSL2, although you need to make sure you appropriate permissions, of course. The sample code in your question, for instance, will need sudo/root.

Regardless, however, you'll have more control over the networking in a true virtual machine. If you run into too many roadblocks with scapy in WSL2, then I'd consider switching for this particular use-case.

  • Related