From ab4a49ae71f3d6281bd537232eb4af4b68c897e0 Mon Sep 17 00:00:00 2001 From: Chen Yufei Date: Thu, 27 Dec 2012 21:59:27 +0800 Subject: [PATCH] Use binary.BigEndian to generate port in rawAddr. --- shadowsocks/conn.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shadowsocks/conn.go b/shadowsocks/conn.go index 13b67cd..80f6c8d 100644 --- a/shadowsocks/conn.go +++ b/shadowsocks/conn.go @@ -2,6 +2,7 @@ package shadowsocks import ( "errors" + "encoding/binary" "fmt" "net" "strconv" @@ -36,8 +37,7 @@ func rawAddr(addr string) (buf []byte, err error) { buf[0] = 3 // 3 means the address is domain name buf[1] = byte(hostLen) // host address length followed by host address copy(buf[2:], host) - buf[2+hostLen] = byte(port >> 8 & 0xFF) // the next 2 bytes are port - buf[2+hostLen+1] = byte(port) & 0xFF + binary.BigEndian.PutUint16(buf[2+hostLen:2+hostLen+2], uint16(port)) return }