Commit f05346f3 authored by Juan Batiz-Benet's avatar Juan Batiz-Benet

hide-loopback in tool

parent 20cc417a
......@@ -10,8 +10,10 @@ import (
manet "github.com/jbenet/go-multiaddr/net"
)
// flags
var formats = []string{"string", "bytes", "hex", "slice"}
var format string
var hideLoopback bool
func init() {
flag.Usage = func() {
......@@ -22,27 +24,46 @@ func init() {
usage := fmt.Sprintf("output format, one of: %v", formats)
flag.StringVar(&format, "format", "string", usage)
flag.StringVar(&format, "f", "string", usage+" (shorthand)")
flag.BoolVar(&hideLoopback, "hide-loopback", false, "do not display loopback addresses")
}
func main() {
flag.Parse()
args := flag.Args()
if len(args) == 0 {
maddrs, err := manet.InterfaceMultiaddrs()
if err != nil {
die(err)
}
output(localAddresses()...)
} else {
output(address(args[0]))
}
}
func localAddresses() []ma.Multiaddr {
maddrs, err := manet.InterfaceMultiaddrs()
if err != nil {
die(err)
}
if !hideLoopback {
return maddrs
}
output(maddrs...)
return
var maddrs2 []ma.Multiaddr
for _, a := range maddrs {
if !manet.IsIPLoopback(a) {
maddrs2 = append(maddrs2, a)
}
}
m, err := ma.NewMultiaddr(args[0])
return maddrs2
}
func address(addr string) ma.Multiaddr {
m, err := ma.NewMultiaddr(addr)
if err != nil {
die(err)
}
output(m)
return m
}
func output(ms ...ma.Multiaddr) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment