mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-03-11 15:34:56 +00:00
lib/netutil: add -enableTCP6
command-line flag for enabling listening for IPv6 additionally to IPv4 TCP ports
This commit is contained in:
parent
93dbec971b
commit
4810f1dde6
1 changed files with 9 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
||||||
package netutil
|
package netutil
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"time"
|
"time"
|
||||||
|
@ -8,12 +9,19 @@ import (
|
||||||
"github.com/VictoriaMetrics/metrics"
|
"github.com/VictoriaMetrics/metrics"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var enableTCP6 = flag.Bool("enableTCP6", false, "Whether to enable listening for IPv6 TCP ports. By default only IPv4 TCP ports are listened")
|
||||||
|
|
||||||
// NewTCPListener returns new TCP listener for the given addr.
|
// NewTCPListener returns new TCP listener for the given addr.
|
||||||
//
|
//
|
||||||
// name is used for exported metrics. Each listener in the program must have
|
// name is used for exported metrics. Each listener in the program must have
|
||||||
// distinct name.
|
// distinct name.
|
||||||
func NewTCPListener(name, addr string) (*TCPListener, error) {
|
func NewTCPListener(name, addr string) (*TCPListener, error) {
|
||||||
ln, err := net.Listen("tcp4", addr)
|
network := "tcp4"
|
||||||
|
if *enableTCP6 {
|
||||||
|
// Enable listening on both tcp4 and tcp6
|
||||||
|
network = "tcp"
|
||||||
|
}
|
||||||
|
ln, err := net.Listen(network, addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue