Skip to content

Commit

Permalink
internal/ndpcmd: implement Nonce handling
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Layher <mdlayher@gmail.com>
  • Loading branch information
mdlayher committed Mar 23, 2022
1 parent 0e15311 commit 7d558c9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 4 additions & 2 deletions internal/ndpcmd/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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))
}
Expand Down
4 changes: 4 additions & 0 deletions option.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"crypto/subtle"
"encoding/binary"
"encoding/hex"
"errors"
"fmt"
"io"
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 7d558c9

Please sign in to comment.