mirror of
https://github.com/tailscale/tailscale.git
synced 2025-10-09 08:01:31 +00:00
portlist: ignore ports bound to localhost
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:

committed by
Brad Fitzpatrick

parent
c706731dc7
commit
f8d67bb591
@@ -4,7 +4,10 @@
|
||||
|
||||
package portlist
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"net"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGetList(t *testing.T) {
|
||||
pl, err := GetList(nil)
|
||||
@@ -17,6 +20,25 @@ func TestGetList(t *testing.T) {
|
||||
t.Logf("As String: %v", pl.String())
|
||||
}
|
||||
|
||||
func TestIgnoreLocallyBoundPorts(t *testing.T) {
|
||||
ln, err := net.Listen("tcp", "127.0.0.1:0")
|
||||
if err != nil {
|
||||
t.Skipf("failed to bind: %v", err)
|
||||
}
|
||||
defer ln.Close()
|
||||
ta := ln.Addr().(*net.TCPAddr)
|
||||
port := ta.Port
|
||||
pl, err := GetList(nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, p := range pl {
|
||||
if p.Proto == "tcp" && int(p.Port) == port {
|
||||
t.Fatal("didn't expect to find test's localhost ephemeral port")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkGetList(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
|
Reference in New Issue
Block a user