File: header_test.go

package info (click to toggle)
golang-golang-x-net-dev 0.0%2Bgit20150226.3d87fd6-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 3,000 kB
  • ctags: 4,376
  • sloc: makefile: 22; asm: 2
file content (50 lines) | stat: -rw-r--r-- 1,111 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright 2014 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package ipv6_test

import (
	"net"
	"reflect"
	"testing"

	"golang.org/x/net/internal/iana"
	"golang.org/x/net/ipv6"
)

var (
	wireHeaderFromKernel = [ipv6.HeaderLen]byte{
		0x69, 0x8b, 0xee, 0xf1,
		0xca, 0xfe, 0x2c, 0x01,
		0x20, 0x01, 0x0d, 0xb8,
		0x00, 0x01, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x01,
		0x20, 0x01, 0x0d, 0xb8,
		0x00, 0x02, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x01,
	}

	testHeader = &ipv6.Header{
		Version:      ipv6.Version,
		TrafficClass: iana.DiffServAF43,
		FlowLabel:    0xbeef1,
		PayloadLen:   0xcafe,
		NextHeader:   iana.ProtocolIPv6Frag,
		HopLimit:     1,
		Src:          net.ParseIP("2001:db8:1::1"),
		Dst:          net.ParseIP("2001:db8:2::1"),
	}
)

func TestParseHeader(t *testing.T) {
	h, err := ipv6.ParseHeader(wireHeaderFromKernel[:])
	if err != nil {
		t.Fatal(err)
	}
	if !reflect.DeepEqual(h, testHeader) {
		t.Fatalf("got %#v; want %#v", h, testHeader)
	}
}