Skip to content

Commit

Permalink
Use binary.BigEndian to read port directly.
Browse files Browse the repository at this point in the history
  • Loading branch information
cyfdecyf committed Dec 27, 2012
1 parent 7383f2a commit efec84e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
5 changes: 1 addition & 4 deletions cmd/shadowsocks-local/local.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"bytes"
"encoding/binary"
"errors"
"flag"
Expand Down Expand Up @@ -127,9 +126,7 @@ func getRequest(conn net.Conn) (rawaddr []byte, host string, err error) {
copy(addrIp, buf[idIP0:idIP0+4])
host = addrIp.String()
}
var port int16
sb := bytes.NewBuffer(buf[reqLen-2 : reqLen])
binary.Read(sb, binary.BigEndian, &port)
port := binary.BigEndian.Uint16(buf[reqLen-2 : reqLen])
host += ":" + strconv.Itoa(int(port))
}

Expand Down
8 changes: 2 additions & 6 deletions cmd/shadowsocks-server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"bufio"
"bytes"
"encoding/binary"
"encoding/gob"
"errors"
Expand Down Expand Up @@ -76,10 +75,7 @@ func getRequest(conn *ss.Conn) (host string, extra []byte, err error) {
host = addrIp.String()
}
// parse port
var port int16
sb := bytes.NewBuffer(buf[reqLen-2 : reqLen])
binary.Read(sb, binary.BigEndian, &port)

port := binary.BigEndian.Uint16(buf[reqLen-2 : reqLen])
host += ":" + strconv.Itoa(int(port))
return
}
Expand Down Expand Up @@ -354,7 +350,7 @@ var config *ss.Config

func main() {
log.SetOutput(os.Stdout)

var cmdConfig ss.Config
var printVer bool

Expand Down

0 comments on commit efec84e

Please sign in to comment.