Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tcpip

userspace tcp/ip stack

build

cargo build

run

cargo run -p cli -- [--tap] <name>
  • linux: <name> is a tun interface name like tcpip0
  • windows: <name> is a wintun adapter name like tcpip

linux

create a tun interface by running the cli (needs root):

sudo cargo run -p cli -- tcpip0

in another terminal, bring it up and assign an address:

sudo ip link set tcpip0 up
sudo ip addr add 10.0.0.1/24 dev tcpip0

test:

ping 10.0.0.2

udp echo (port 9000):

python3 - <<'PY'
import socket

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.settimeout(1)
s.sendto(b"hi", ("10.0.0.2", 9000))
print(s.recvfrom(2048))
PY

tap

run (needs root):

sudo cargo run -p cli -- --tap tcpip0

in another terminal, bring it up and assign an address:

sudo ip link set tcpip0 up
sudo ip addr add 10.0.0.1/24 dev tcpip0

test:

ping 10.0.0.2

tcp echo (port 9001):

python3 - <<'PY'
import socket

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(2)
s.connect(("10.0.0.2", 9001))
s.sendall(b"hi")
print(s.recv(2048))
s.close()
PY

windows

this uses wintun

requirements:

  • install wireguard (it installs the driver)
  • put wintun.dll next to the built exe, or in path

run as admin:

cargo run -p cli -- tcpip

assign ip:

netsh interface ipv4 set address name="tcpip" static 10.0.0.1 255.255.255.0

test:

ping 10.0.0.2

ipv6 (ndp + ping)

the stack responds to fd00::2 on the tap interface

assign ipv6 to the host (note: the prefix must be /64, not /128):

New-NetIPAddress -InterfaceAlias "tcpip-tap" -IPAddress "fd00::1" -PrefixLength 64

verify:

Get-NetIPAddress -InterfaceAlias "tcpip-tap" -AddressFamily IPv6 | Select IPAddress, PrefixLength

run the stack (admin):

cargo run -p cli -- --tap tcpip-tap

in another terminal:

ping -6 fd00::2

optional neighbor cache check:

Get-NetNeighbor -InterfaceAlias "tcpip-tap" -AddressFamily IPv6 |
  Where-Object { $_.IPAddress -eq "fd00::2" } |
  Select IPAddress, LinkLayerAddress, State

udp echo (port 9000):

$udp = New-Object System.Net.Sockets.UdpClient
$udp.Client.ReceiveTimeout = 1000
$udp.Connect("10.0.0.2", 9000)
$buf = [System.Text.Encoding]::ASCII.GetBytes("hi")
$udp.Send($buf, $buf.Length) | Out-Null
$rem = New-Object System.Net.IPEndPoint([System.Net.IPAddress]::Any, 0)
$out = $udp.Receive([ref]$rem)
[System.Text.Encoding]::ASCII.GetString($out)

tcp echo (port 9001):

$tcp = New-Object System.Net.Sockets.TcpClient
$tcp.ReceiveTimeout = 2000
$tcp.SendTimeout = 2000
$tcp.Connect("10.0.0.2", 9001)
$st = $tcp.GetStream()
$buf = [System.Text.Encoding]::ASCII.GetBytes("hi")
$st.Write($buf, 0, $buf.Length)
$out = New-Object byte[] 2048
$n = $st.Read($out, 0, $out.Length)
[System.Text.Encoding]::ASCII.GetString($out, 0, $n)
$tcp.Close()

tap

this uses tap-windows6

requirements:

  • install a package that actually installs the tap-windows6 network adapter
  • openvpn community (msi) works, or a standalone tap-windows6 installer
  • create a tap adapter and name it (example name: tcpip-tap)

verify you have it:

  • ncpa.cpl (network connections) should show something like TAP-Windows Adapter V9
  • or powershell: Get-NetAdapter | Select Name, InterfaceDescription

run as admin:

cargo run -p cli -- --tap tcpip-tap

assign ip:

netsh interface ipv4 set address name="tcpip-tap" static 10.0.0.1 255.255.255.0

test:

ping 10.0.0.2

About

userspace tcp/ip stack

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages