From 7d558c930180892ed63e3213bb45bc62c71b6fa5 Mon Sep 17 00:00:00 2001 From: Matt Layher Date: Wed, 23 Mar 2022 07:49:25 -0400 Subject: [PATCH] internal/ndpcmd: implement Nonce handling Signed-off-by: Matt Layher --- internal/ndpcmd/print.go | 6 ++++-- option.go | 4 ++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/internal/ndpcmd/print.go b/internal/ndpcmd/print.go index ed00007..14ed1b0 100644 --- a/internal/ndpcmd/print.go +++ b/internal/ndpcmd/print.go @@ -137,7 +137,7 @@ func optStr(o ndp.Option) string { return fmt.Sprintf("%s link-layer address: %s", dir, o.Addr.String()) case *ndp.MTU: - return fmt.Sprintf("MTU: %d", *o) + return fmt.Sprintf("MTU: %d", o.MTU) case *ndp.PrefixInformation: var flags []string if o.OnLink { @@ -174,7 +174,9 @@ func optStr(o ndp.Option) string { case *ndp.DNSSearchList: return fmt.Sprintf("DNS search list: lifetime: %s, domain names: %s", o.Lifetime, strings.Join(o.DomainNames, ", ")) case *ndp.CaptivePortal: - return fmt.Sprintf("captive portal: %s", *o) + return fmt.Sprintf("captive portal: %s", o.URI) + case *ndp.Nonce: + return fmt.Sprintf("nonce: %s", o) default: panic(fmt.Sprintf("unrecognized option: %v", o)) } diff --git a/option.go b/option.go index db4dac3..c613e86 100644 --- a/option.go +++ b/option.go @@ -4,6 +4,7 @@ import ( "bytes" "crypto/subtle" "encoding/binary" + "encoding/hex" "errors" "fmt" "io" @@ -774,6 +775,9 @@ func (n *Nonce) Equal(x *Nonce) bool { return subtle.ConstantTimeCompare(n.b, x. // Code implements Option. func (*Nonce) Code() byte { return optNonce } +// String returns the string representation of a Nonce. +func (n *Nonce) String() string { return hex.EncodeToString(n.b) } + func (n *Nonce) marshal() ([]byte, error) { if len(n.b) == 0 { return nil, errors.New("ndp: nonce option requires a non-empty nonce value")