seqs
1.0.0
seqs
就是通常所说的用户空间 IP 实现。它处理:
stacks/tcpconn.go
httpx
包 // stack works by having access to Ethernet packet sending
// and processing. NIC is our physical link to the internet.
var NIC NetworkInterfaceCard = getNIC ()
stack := stacks . NewPortStack (stacks. PortStackConfig {
MAC : MAC ,
MaxOpenPortsTCP : 1 ,
MaxOpenPortsUDP : 1 ,
MTU : 2048 ,
})
// stack.RecvEth should be called on receiving an ethernet packet. It should NOT block.
NIC . SetRecvEthHandle ( stack . RecvEth )
// Static IP setting.
ip := netip . AddrFrom4 ([ 4 ] byte { 192 , 168 , 1 , 45 })
stack . SetAddr ( ip )
// Or can request an address via DHCP.
dhcpClient := stacks . NewDHCPClient ( stack , dhcp . DefaultClientPort )
err = dhcpClient . BeginRequest (stacks. DHCPRequestConfig {
RequestedAddr : netip . AddrFrom4 ([ 4 ] byte { 192 , 168 , 1 , 69 }),
Xid : 0x12345678 ,
Hostname : "tinygo-pico" ,
})
if err != nil {
panic ( err )
}
fmt . Println ( "Start DHCP..." )
for ! dhcpClient . Done () {
doNICPoll ( NIC )
time . Sleep ( time . Second / 10 )
}
offeredIP := dhcpClient . Offer ()
fmt . Println ( "got offer:" , offeredIP )
stack . SetAddr ( offeredIP )
如何使用seqs
go mod download github.com/soypat/seqs@latest
在seqs
之前有:
ether-swtch
- 大约 2021 年 6 月,在嵌入式系统上工作的 Go 中(勉强)工作的 TCP/IP 堆栈的第一个已知实例。可以通过 HTTP 使 Arduino UNO 的 LED 闪烁(!)。众所周知的糟糕的设计、代码、性能、可读性。dgrams
- 为 Pico W 的 wifi 芯片准备的库。已经显示出与seqs
的相似之处。大约 2023 年 5 月。