mirror of
https://github.com/duke-git/lancet.git
synced 2026-11-16 05:12:11 +08:00
fix(package): [netutil] bracket IPv6 dial addresses (#398)
This commit is contained in:
1 parent
e49a01e725
commit
3b94ec1932
2 files changed
+22
-1
No files matched your search
+1
-1
@@ -315,7 +315,7 @@ func IsPingConnected(host string) bool {
|
|||||||
// IsTelnetConnected checks if can telnet specified host or not.
|
// IsTelnetConnected checks if can telnet specified host or not.
|
||||||
// Play: https://go.dev/play/p/yiLCGtQv_ZG
|
// Play: https://go.dev/play/p/yiLCGtQv_ZG
|
||||||
func IsTelnetConnected(host string, port string) bool {
|
func IsTelnetConnected(host string, port string) bool {
|
||||||
adder := host + ":" + port
|
adder := net.JoinHostPort(host, port)
|
||||||
conn, err := net.DialTimeout("tcp", adder, 5*time.Second)
|
conn, err := net.DialTimeout("tcp", adder, 5*time.Second)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package netutil
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestIsTelnetConnectedIPv6(t *testing.T) {
|
||||||
|
listener, err := net.Listen("tcp6", "[::1]:0")
|
||||||
|
if err != nil {
|
||||||
|
t.Skipf("IPv6 loopback unavailable: %v", err)
|
||||||
|
}
|
||||||
|
defer listener.Close()
|
||||||
|
host, port, err := net.SplitHostPort(listener.Addr().String())
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if !IsTelnetConnected(host, port) {
|
||||||
|
t.Error("could not connect to the IPv6 loopback listener")
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user