header_test.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright 2014 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package ipv6_test
  5. import (
  6. "net"
  7. "reflect"
  8. "strings"
  9. "testing"
  10. "golang.org/x/net/internal/iana"
  11. "golang.org/x/net/ipv6"
  12. )
  13. var (
  14. wireHeaderFromKernel = [ipv6.HeaderLen]byte{
  15. 0x69, 0x8b, 0xee, 0xf1,
  16. 0xca, 0xfe, 0x2c, 0x01,
  17. 0x20, 0x01, 0x0d, 0xb8,
  18. 0x00, 0x01, 0x00, 0x00,
  19. 0x00, 0x00, 0x00, 0x00,
  20. 0x00, 0x00, 0x00, 0x01,
  21. 0x20, 0x01, 0x0d, 0xb8,
  22. 0x00, 0x02, 0x00, 0x00,
  23. 0x00, 0x00, 0x00, 0x00,
  24. 0x00, 0x00, 0x00, 0x01,
  25. }
  26. testHeader = &ipv6.Header{
  27. Version: ipv6.Version,
  28. TrafficClass: iana.DiffServAF43,
  29. FlowLabel: 0xbeef1,
  30. PayloadLen: 0xcafe,
  31. NextHeader: iana.ProtocolIPv6Frag,
  32. HopLimit: 1,
  33. Src: net.ParseIP("2001:db8:1::1"),
  34. Dst: net.ParseIP("2001:db8:2::1"),
  35. }
  36. )
  37. func TestParseHeader(t *testing.T) {
  38. h, err := ipv6.ParseHeader(wireHeaderFromKernel[:])
  39. if err != nil {
  40. t.Fatal(err)
  41. }
  42. if !reflect.DeepEqual(h, testHeader) {
  43. t.Fatalf("got %#v; want %#v", h, testHeader)
  44. }
  45. s := h.String()
  46. if strings.Contains(s, ",") {
  47. t.Fatalf("should be space-separated values: %s", s)
  48. }
  49. }