1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-30 05:56:54 -05:00

add IPv4 packet addr encoding test

This commit is contained in:
Shelikhoo 2021-11-04 21:58:59 +00:00 committed by Xiaokang Wang (Shelikhoo)
parent fd763c9bab
commit 16bff33858

View 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)
}