fix UDP proxy failed

This commit is contained in:
Jason
2019-08-14 13:54:35 +08:00
parent fa311d6599
commit 5c8160ab42
3 changed files with 20 additions and 15 deletions

View File

@@ -235,12 +235,11 @@ func DecodeUDPPacket(packet []byte) (addr Addr, payload []byte, err error) {
return
}
func EncodeUDPPacket(addr string, payload []byte) (packet []byte, err error) {
rAddr := ParseAddr(addr)
if rAddr == nil {
err = errors.New("cannot parse addr")
func EncodeUDPPacket(addr Addr, payload []byte) (packet []byte, err error) {
if addr == nil {
err = errors.New("address is invalid")
return
}
packet = bytes.Join([][]byte{{0, 0, 0}, rAddr, payload}, []byte{})
packet = bytes.Join([][]byte{{0, 0, 0}, addr, payload}, []byte{})
return
}