mirror of
https://github.com/SagerNet/sing.git
synced 2025-04-03 20:07:38 +03:00
Fix socks4 request (#7)
This commit is contained in:
parent
f3d346256d
commit
62c4ebdbcb
1 changed files with 12 additions and 7 deletions
|
@ -58,7 +58,7 @@ func ReadRequest0(reader io.Reader) (request Request, err error) {
|
|||
return
|
||||
}
|
||||
var readHostName bool
|
||||
if dstIP[0] == 0 && dstIP[1] == 0 && dstIP[2] == 0 {
|
||||
if dstIP[0] == 0 && dstIP[1] == 0 && dstIP[2] == 0 && dstIP[3] != 0 {
|
||||
readHostName = true
|
||||
} else {
|
||||
request.Destination.Addr = netip.AddrFrom4(dstIP)
|
||||
|
@ -77,11 +77,12 @@ func WriteRequest(writer io.Writer, request Request) error {
|
|||
requestLen += 1 // command
|
||||
requestLen += 2 // port
|
||||
requestLen += 4 // ip
|
||||
requestLen += 1 // NUL
|
||||
if !request.Destination.IsIPv4() {
|
||||
requestLen += len(request.Destination.AddrString()) + 1
|
||||
}
|
||||
if request.Username != "" {
|
||||
requestLen += len(request.Username) + 1
|
||||
requestLen += len(request.Username)
|
||||
}
|
||||
|
||||
_buffer := buf.StackNewSize(requestLen)
|
||||
|
@ -97,14 +98,18 @@ func WriteRequest(writer io.Writer, request Request) error {
|
|||
if request.Destination.IsIPv4() {
|
||||
common.Must1(buffer.Write(request.Destination.Unwrap().Addr.AsSlice()))
|
||||
} else {
|
||||
common.Must(buffer.WriteZeroN(4))
|
||||
// 0.0.0.X
|
||||
common.Must(buffer.WriteZeroN(3))
|
||||
common.Must(buffer.WriteByte(1))
|
||||
}
|
||||
if request.Username != "" {
|
||||
common.Must1(buffer.WriteString(request.Username))
|
||||
}
|
||||
common.Must(buffer.WriteZero())
|
||||
if !request.Destination.IsIPv4() {
|
||||
common.Must1(buffer.WriteString(request.Destination.AddrString()))
|
||||
common.Must(buffer.WriteZero())
|
||||
}
|
||||
if request.Username != "" {
|
||||
common.Must1(buffer.WriteString(request.Destination.AddrString()))
|
||||
}
|
||||
common.Must(buffer.WriteZero())
|
||||
return rw.WriteBytes(writer, buffer.Bytes())
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue