Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(696)

Unified Diff: proxy/socks5.go

Issue 7220047: code review 7220047: go.net/proxy: fix desired destination address in SOCKS5... (Closed)
Patch Set: diff -r f0a629bb85a7 https://code.google.com/p/go.net Created 12 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « proxy/proxy_test.go ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: proxy/socks5.go
===================================================================
--- a/proxy/socks5.go
+++ b/proxy/socks5.go
@@ -64,7 +64,6 @@
func (s *socks5) Dial(network, addr string) (net.Conn, error) {
switch network {
case "tcp", "tcp6", "tcp4":
- break
default:
return nil, errors.New("proxy: no support for SOCKS5 proxy connections of type " + network)
}
@@ -103,11 +102,11 @@
buf = append(buf, 1 /* num auth methods */, socks5AuthNone)
}
- if _, err = conn.Write(buf); err != nil {
+ if _, err := conn.Write(buf); err != nil {
return nil, errors.New("proxy: failed to write greeting to SOCKS5 proxy at " + s.addr + ": " + err.Error())
}
- if _, err = io.ReadFull(conn, buf[:2]); err != nil {
+ if _, err := io.ReadFull(conn, buf[:2]); err != nil {
return nil, errors.New("proxy: failed to read greeting from SOCKS5 proxy at " + s.addr + ": " + err.Error())
}
if buf[0] != 5 {
@@ -125,11 +124,11 @@
buf = append(buf, uint8(len(s.password)))
buf = append(buf, s.password...)
- if _, err = conn.Write(buf); err != nil {
+ if _, err := conn.Write(buf); err != nil {
return nil, errors.New("proxy: failed to write authentication request to SOCKS5 proxy at " + s.addr + ": " + err.Error())
}
- if _, err = io.ReadFull(conn, buf[:2]); err != nil {
+ if _, err := io.ReadFull(conn, buf[:2]); err != nil {
return nil, errors.New("proxy: failed to read authentication reply from SOCKS5 proxy at " + s.addr + ": " + err.Error())
}
@@ -142,12 +141,13 @@
buf = append(buf, socks5Version, socks5Connect, 0 /* reserved */)
if ip := net.ParseIP(host); ip != nil {
- if ip.To4() != nil {
+ if ip4 := ip.To4(); ip4 != nil {
buf = append(buf, socks5IP4)
+ ip = ip4
} else {
buf = append(buf, socks5IP6)
}
- buf = append(buf, []byte(ip)...)
+ buf = append(buf, ip...)
} else {
buf = append(buf, socks5Domain)
buf = append(buf, byte(len(host)))
@@ -155,11 +155,11 @@
}
buf = append(buf, byte(port>>8), byte(port))
- if _, err = conn.Write(buf); err != nil {
+ if _, err := conn.Write(buf); err != nil {
return nil, errors.New("proxy: failed to write connect request to SOCKS5 proxy at " + s.addr + ": " + err.Error())
}
- if _, err = io.ReadFull(conn, buf[:4]); err != nil {
+ if _, err := io.ReadFull(conn, buf[:4]); err != nil {
return nil, errors.New("proxy: failed to read connect reply from SOCKS5 proxy at " + s.addr + ": " + err.Error())
}
@@ -193,12 +193,12 @@
} else {
buf = buf[:bytesToDiscard]
}
- if _, err = io.ReadFull(conn, buf); err != nil {
+ if _, err := io.ReadFull(conn, buf); err != nil {
return nil, errors.New("proxy: failed to read address from SOCKS5 proxy at " + s.addr + ": " + err.Error())
}
// Also need to discard the port number
- if _, err = io.ReadFull(conn, buf[:2]); err != nil {
+ if _, err := io.ReadFull(conn, buf[:2]); err != nil {
return nil, errors.New("proxy: failed to read port from SOCKS5 proxy at " + s.addr + ": " + err.Error())
}
« no previous file with comments | « proxy/proxy_test.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b