Skip to content

Commit

Permalink
toSocksAddr supports IPv6
Browse files Browse the repository at this point in the history
  • Loading branch information
koaiwu authored and ginuerzh committed Jan 19, 2023
1 parent 847ee05 commit b7beb17
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions socks.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"net"
"net/url"
"strconv"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -1630,17 +1631,21 @@ func (h *socks5Handler) muxBindOn(conn net.Conn, addr string) {
}
}

// TODO: support ipv6 and domain
// TODO: support domain
func toSocksAddr(addr net.Addr) *gosocks5.Addr {
host := "0.0.0.0"
port := 0
addrType := gosocks5.AddrIPv4
if addr != nil {
h, p, _ := net.SplitHostPort(addr.String())
host = h
port, _ = strconv.Atoi(p)
if strings.Count(host, ":") > 0 {
addrType = gosocks5.AddrIPv6
}
}
return &gosocks5.Addr{
Type: gosocks5.AddrIPv4,
Type: addrType,
Host: host,
Port: uint16(port),
}
Expand Down

0 comments on commit b7beb17

Please sign in to comment.