mirror of
https://github.com/cmz0228/hysteria-dev.git
synced 2025-08-20 16:21:46 +00:00
fix: ipv{4,6}-only listen on wildcard address
fix: #797 when listening on a wildcard address like "0.0.0.0" or "[::]", hysteria actually listened on both IPv4 and IPv6. this is a well-known bug of the golang net package. this commit introduces a fix for that, the intended behavior will be: 0.0.0.0:443 => listen on IPv4 only [::]:443 => listen on IPv6 only :443 => listen on both IPv4 and IPv6
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"crypto/x509"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"github.com/apernet/hysteria/extras/correctnet"
|
||||
"net"
|
||||
"os"
|
||||
"strconv"
|
||||
@@ -504,7 +505,7 @@ func clientSOCKS5(config socks5Config, c client.Client) error {
|
||||
if config.Listen == "" {
|
||||
return configError{Field: "listen", Err: errors.New("listen address is empty")}
|
||||
}
|
||||
l, err := net.Listen("tcp", config.Listen)
|
||||
l, err := correctnet.Listen("tcp", config.Listen)
|
||||
if err != nil {
|
||||
return configError{Field: "listen", Err: err}
|
||||
}
|
||||
@@ -529,7 +530,7 @@ func clientHTTP(config httpConfig, c client.Client) error {
|
||||
if config.Listen == "" {
|
||||
return configError{Field: "listen", Err: errors.New("listen address is empty")}
|
||||
}
|
||||
l, err := net.Listen("tcp", config.Listen)
|
||||
l, err := correctnet.Listen("tcp", config.Listen)
|
||||
if err != nil {
|
||||
return configError{Field: "listen", Err: err}
|
||||
}
|
||||
@@ -562,7 +563,7 @@ func clientTCPForwarding(entries []tcpForwardingEntry, c client.Client) error {
|
||||
if e.Remote == "" {
|
||||
return configError{Field: "remote", Err: errors.New("remote address is empty")}
|
||||
}
|
||||
l, err := net.Listen("tcp", e.Listen)
|
||||
l, err := correctnet.Listen("tcp", e.Listen)
|
||||
if err != nil {
|
||||
return configError{Field: "listen", Err: err}
|
||||
}
|
||||
@@ -589,7 +590,7 @@ func clientUDPForwarding(entries []udpForwardingEntry, c client.Client) error {
|
||||
if e.Remote == "" {
|
||||
return configError{Field: "remote", Err: errors.New("remote address is empty")}
|
||||
}
|
||||
l, err := net.ListenPacket("udp", e.Listen)
|
||||
l, err := correctnet.ListenPacket("udp", e.Listen)
|
||||
if err != nil {
|
||||
return configError{Field: "listen", Err: err}
|
||||
}
|
||||
|
Reference in New Issue
Block a user