mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-20 00:07:06 -05:00
add IPv4 packet addr encoding test
This commit is contained in:
parent
fd763c9bab
commit
16bff33858
21
common/net/packetaddr/packetaddr_test.go
Normal file
21
common/net/packetaddr/packetaddr_test.go
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
package packetaddr
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
sysnet "net"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestPacketEncodingIPv4(t *testing.T) {
|
||||||
|
packetAddress := &sysnet.UDPAddr{
|
||||||
|
IP: sysnet.IPv4(1, 2, 3, 4).To4(),
|
||||||
|
Port: 1234,
|
||||||
|
}
|
||||||
|
var packetData [256]byte
|
||||||
|
wrapped := AttachAddressToPacket(packetData[:], packetAddress)
|
||||||
|
|
||||||
|
packetPayload, decodedAddress := ExtractAddressFromPacket(wrapped)
|
||||||
|
|
||||||
|
assert.Equal(t, packetPayload, packetData[:])
|
||||||
|
assert.Equal(t, packetAddress, decodedAddress)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user