mirror of
https://github.com/bluenviron/mediamtx
synced 2024-12-17 20:24:38 +00:00
parent
67741d16dd
commit
34757620b8
@ -134,7 +134,7 @@ func newAPI(
|
|||||||
webRTCServer apiWebRTCServer,
|
webRTCServer apiWebRTCServer,
|
||||||
parent apiParent,
|
parent apiParent,
|
||||||
) (*api, error) {
|
) (*api, error) {
|
||||||
ln, err := net.Listen("tcp", address)
|
ln, err := net.Listen(restrictNetwork("tcp", address))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -106,7 +106,7 @@ func newHLSServer(
|
|||||||
metrics *metrics,
|
metrics *metrics,
|
||||||
parent hlsServerParent,
|
parent hlsServerParent,
|
||||||
) (*hlsServer, error) {
|
) (*hlsServer, error) {
|
||||||
ln, err := net.Listen("tcp", address)
|
ln, err := net.Listen(restrictNetwork("tcp", address))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ func newMetrics(
|
|||||||
address string,
|
address string,
|
||||||
parent metricsParent,
|
parent metricsParent,
|
||||||
) (*metrics, error) {
|
) (*metrics, error) {
|
||||||
ln, err := net.Listen("tcp", address)
|
ln, err := net.Listen(restrictNetwork(restrictNetwork("tcp", address)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ func newPPROF(
|
|||||||
address string,
|
address string,
|
||||||
parent pprofParent,
|
parent pprofParent,
|
||||||
) (*pprof, error) {
|
) (*pprof, error) {
|
||||||
ln, err := net.Listen("tcp", address)
|
ln, err := net.Listen(restrictNetwork("tcp", address))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
17
internal/core/restrict_network.go
Normal file
17
internal/core/restrict_network.go
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package core
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net"
|
||||||
|
)
|
||||||
|
|
||||||
|
// do not listen on IPv6 when address is 0.0.0.0.
|
||||||
|
func restrictNetwork(network string, address string) (string, string) {
|
||||||
|
host, _, err := net.SplitHostPort(address)
|
||||||
|
if err == nil {
|
||||||
|
if host == "0.0.0.0" {
|
||||||
|
return network + "4", address
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return network, address
|
||||||
|
}
|
@ -93,7 +93,7 @@ func newRTMPServer(
|
|||||||
) (*rtmpServer, error) {
|
) (*rtmpServer, error) {
|
||||||
ln, err := func() (net.Listener, error) {
|
ln, err := func() (net.Listener, error) {
|
||||||
if !isTLS {
|
if !isTLS {
|
||||||
return net.Listen("tcp", address)
|
return net.Listen(restrictNetwork("tcp", address))
|
||||||
}
|
}
|
||||||
|
|
||||||
cert, err := tls.LoadX509KeyPair(serverCert, serverKey)
|
cert, err := tls.LoadX509KeyPair(serverCert, serverKey)
|
||||||
@ -101,7 +101,8 @@ func newRTMPServer(
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return tls.Listen("tcp", address, &tls.Config{Certificates: []tls.Certificate{cert}})
|
network, address := restrictNetwork("tcp", address)
|
||||||
|
return tls.Listen(network, address, &tls.Config{Certificates: []tls.Certificate{cert}})
|
||||||
}()
|
}()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -98,7 +98,7 @@ func (s *udpSource) run(ctx context.Context, cnf *conf.PathConf, reloadConf chan
|
|||||||
|
|
||||||
hostPort := cnf.Source[len("udp://"):]
|
hostPort := cnf.Source[len("udp://"):]
|
||||||
|
|
||||||
pc, err := net.ListenPacket("udp", hostPort)
|
pc, err := net.ListenPacket(restrictNetwork("udp", hostPort))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -116,7 +116,7 @@ func newWebRTCServer(
|
|||||||
iceUDPMuxAddress string,
|
iceUDPMuxAddress string,
|
||||||
iceTCPMuxAddress string,
|
iceTCPMuxAddress string,
|
||||||
) (*webRTCServer, error) {
|
) (*webRTCServer, error) {
|
||||||
ln, err := net.Listen("tcp", address)
|
ln, err := net.Listen(restrictNetwork("tcp", address))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -137,7 +137,7 @@ func newWebRTCServer(
|
|||||||
var iceUDPMux ice.UDPMux
|
var iceUDPMux ice.UDPMux
|
||||||
var udpMuxLn net.PacketConn
|
var udpMuxLn net.PacketConn
|
||||||
if iceUDPMuxAddress != "" {
|
if iceUDPMuxAddress != "" {
|
||||||
udpMuxLn, err = net.ListenPacket("udp", iceUDPMuxAddress)
|
udpMuxLn, err = net.ListenPacket(restrictNetwork("udp", iceUDPMuxAddress))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -147,7 +147,7 @@ func newWebRTCServer(
|
|||||||
var iceTCPMux ice.TCPMux
|
var iceTCPMux ice.TCPMux
|
||||||
var tcpMuxLn net.Listener
|
var tcpMuxLn net.Listener
|
||||||
if iceTCPMuxAddress != "" {
|
if iceTCPMuxAddress != "" {
|
||||||
tcpMuxLn, err = net.Listen("tcp", iceTCPMuxAddress)
|
tcpMuxLn, err = net.Listen(restrictNetwork("tcp", iceTCPMuxAddress))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user