mirror of
https://github.com/cedar2025/hysteria.git
synced 2025-08-29 04:31:50 +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:
@@ -6,6 +6,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/apernet/hysteria/extras/correctnet"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/httputil"
|
||||
@@ -219,7 +220,7 @@ func (c *serverConfig) fillConn(hyConfig *server.Config) error {
|
||||
if err != nil {
|
||||
return configError{Field: "listen", Err: err}
|
||||
}
|
||||
conn, err := net.ListenUDP("udp", uAddr)
|
||||
conn, err := correctnet.ListenUDP("udp", uAddr)
|
||||
if err != nil {
|
||||
return configError{Field: "listen", Err: err}
|
||||
}
|
||||
@@ -752,7 +753,7 @@ func runServer(cmd *cobra.Command, args []string) {
|
||||
|
||||
func runTrafficStatsServer(listen string, handler http.Handler) {
|
||||
logger.Info("traffic stats server up and running", zap.String("listen", listen))
|
||||
if err := http.ListenAndServe(listen, handler); err != nil {
|
||||
if err := correctnet.HTTPListenAndServe(listen, handler); err != nil {
|
||||
logger.Fatal("failed to serve traffic stats", zap.Error(err))
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user