github.com/haraldrudell/parl@v0.4.176/pnet/ifindex_test.go (about) 1 /* 2 © 2020–present Harald Rudell <harald.rudell@gmail.com> (https://haraldrudell.github.io/haraldrudell/) 3 ISC License 4 */ 5 6 package pnet 7 8 import ( 9 "net/netip" 10 "strconv" 11 "strings" 12 "testing" 13 14 "github.com/haraldrudell/parl/perrors" 15 ) 16 17 func TestIfIndex_Interface(t *testing.T) { 18 var ifIndex = NewIfIndex(1) // pick 1 which is the first interface index 19 20 var name string 21 var i4, i6 []netip.Prefix 22 var err error 23 24 if name, i4, i6, err = ifIndex.InterfaceAddrs(); err != nil { 25 t.Fatalf("ifIndex.Interface err: %s", perrors.Short(err)) 26 } 27 var stringifySlice = func(slic []netip.Prefix) (s string) { 28 var sL = make([]string, len(slic)) 29 for i, p := range slic { 30 sL[i] = p.String() 31 if p.Addr().Is6() { 32 sL[i] += " zone: " + strconv.Quote(p.Addr().Zone()) 33 } 34 } 35 return strconv.Itoa(len(slic)) + "[" + strings.Join(sL, "\x20") + "]" 36 } 37 t.Logf("name: %q IPv4: %s IPv6: %s", 38 name, 39 stringifySlice(i4), 40 stringifySlice(i6), 41 ) 42 }