github.com/gopacket/gopacket@v1.1.0/pcapgo/ngread_test.go (about)

     1  // Copyright 2018 The GoPacket Authors. All rights reserved.
     2  //
     3  // Use of this source code is governed by a BSD-style license
     4  // that can be found in the LICENSE file in the root of the source
     5  // tree.
     6  
     7  package pcapgo
     8  
     9  import (
    10  	"bufio"
    11  	"bytes"
    12  	"encoding/hex"
    13  	"io"
    14  	"log"
    15  	"os"
    16  	"path/filepath"
    17  	"reflect"
    18  	"testing"
    19  	"time"
    20  
    21  	"github.com/gopacket/gopacket"
    22  	"github.com/gopacket/gopacket/layers"
    23  )
    24  
    25  func ngMustDecode(s string) []byte {
    26  	ret, err := hex.DecodeString(s)
    27  	if err != nil {
    28  		log.Panic("Initialization failed")
    29  	}
    30  	return ret
    31  }
    32  
    33  var ngPacketSource = [...][]byte{
    34  	ngMustDecode("ffffffffffff000b8201fc4208004500012ca8360000fa11178b00000000ffffffff004400430118591f0101060000003d1d0000000000000000000000000000000000000000000b8201fc4200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000638253633501013d0701000b8201fc4232040000000037040103062aff00000000000000"),
    35  	ngMustDecode("000b8201fc42000874adf19b0800450001480445000080110000c0a80001c0a8000a00430044013422330201060000003d1d0000000000000000c0a8000ac0a8000100000000000b8201fc4200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000638253633501020104ffffff003a04000007083b0400000c4e330400000e103604c0a80001ff0000000000000000000000000000000000000000000000000000"),
    36  	ngMustDecode("ffffffffffff000b8201fc4208004500012ca8370000fa11178a00000000ffffffff0044004301189fbd0101060000003d1e0000000000000000000000000000000000000000000b8201fc4200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000638253633501033d0701000b8201fc423204c0a8000a3604c0a8000137040103062aff00"),
    37  	ngMustDecode("000b8201fc42000874adf19b0800450001480446000080110000c0a80001c0a8000a004300440134dfdb0201060000003d1e0000000000000000c0a8000a0000000000000000000b8201fc4200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000638253633501053a04000007083b0400000c4e330400000e103604c0a800010104ffffff00ff0000000000000000000000000000000000000000000000000000"),
    38  	ngMustDecode("02000000450000a4c6ce00004011f147c0a8018bffffffff445c445c0090ba037b22686f73745f696e74223a20343039343531343438332c202276657273696f6e223a205b312c20385d2c2022646973706c61796e616d65223a2022222c2022706f7274223a2031373530302c20226e616d65737061636573223a205b32303532343235372c203633393533393037322c203633393533393333372c203633393533393535355d7d"),
    39  }
    40  
    41  type ngFileReadTestPacket struct {
    42  	data []byte
    43  	ci   gopacket.CaptureInfo
    44  	err  error
    45  }
    46  
    47  type ngFileReadTestSection struct {
    48  	sectionInfo NgSectionInfo
    49  	ifaces      []NgInterface
    50  }
    51  
    52  type ngFileReadTest struct {
    53  	testName                   string
    54  	testContents               io.Reader
    55  	testType                   string
    56  	wantMixedLinkType          bool
    57  	errorOnMismatchingLinkType bool
    58  	skipUnknownVersion         bool
    59  
    60  	linkType layers.LinkType
    61  	sections []ngFileReadTestSection
    62  	packets  []ngFileReadTestPacket
    63  }
    64  
    65  func ngRunFileReadTest(test ngFileReadTest, be string, zerocopy bool, t *testing.T) {
    66  	var err error
    67  	var f io.Reader
    68  	if test.testContents == nil {
    69  		testf, err := os.Open(filepath.Join("tests", be, test.testName+".pcapng"))
    70  		if err != nil {
    71  			t.Fatal("Couldn't open file:", err)
    72  		}
    73  		defer testf.Close()
    74  		f = testf
    75  	} else {
    76  		f = test.testContents
    77  	}
    78  
    79  	var r *NgReader
    80  
    81  	section := 0
    82  	checkInterface := func(intf NgInterface, i int) {
    83  		currentInterface := test.sections[section].ifaces[i]
    84  
    85  		// fix non-zero defaults
    86  		if currentInterface.TimestampResolution == 0 {
    87  			currentInterface.TimestampResolution = 6
    88  		}
    89  		// clear private values
    90  		intf.scaleDown = 0
    91  		intf.scaleUp = 0
    92  		intf.secondMask = 0
    93  
    94  		if !reflect.DeepEqual(intf, currentInterface) {
    95  			t.Fatalf("[section %d] interface %d mismatches:\ngot:\n%#v\nwant:\n%#v\n\n", section, i, intf, currentInterface)
    96  		}
    97  	}
    98  	testSection := func(intf []NgInterface, sectionInfo NgSectionInfo) {
    99  		currentSection := test.sections[section]
   100  
   101  		if !reflect.DeepEqual(sectionInfo, currentSection.sectionInfo) {
   102  			t.Fatalf("[section header %d] section info mismatch:\ngot:\n%#v\nwant:\n%#v\n\n", section, sectionInfo, currentSection.sectionInfo)
   103  		}
   104  
   105  		if intf == nil {
   106  			if r.NInterfaces() != len(test.sections[section].ifaces) {
   107  				t.Fatalf("[section %d] Expected at least %d interfaces, but got only %d", section, len(test.sections[section].ifaces), r.NInterfaces())
   108  			}
   109  			for i := 0; i < r.NInterfaces(); i++ {
   110  				in, err := r.Interface(i)
   111  				if err != nil {
   112  					t.Fatalf("Unexpected error querying interface %d", i)
   113  				}
   114  				checkInterface(in, i)
   115  			}
   116  		} else {
   117  			if len(intf) != len(test.sections[section].ifaces) {
   118  				t.Fatalf("[section %d] Expected at least %d interfaces, but got only %d", section, len(test.sections[section].ifaces), len(intf))
   119  			}
   120  			for i, in := range intf {
   121  				checkInterface(in, i)
   122  			}
   123  		}
   124  
   125  		section++
   126  	}
   127  
   128  	options := DefaultNgReaderOptions
   129  	options.ErrorOnMismatchingLinkType = test.errorOnMismatchingLinkType
   130  	options.WantMixedLinkType = test.wantMixedLinkType
   131  	options.SkipUnknownVersion = test.skipUnknownVersion
   132  	if len(test.sections) > 1 {
   133  		options.SectionEndCallback = testSection
   134  	}
   135  
   136  	r, err = NewNgReader(f, options)
   137  	if err != nil {
   138  		t.Fatal("Couldn't read start of file:", err)
   139  	}
   140  
   141  	if test.wantMixedLinkType {
   142  		if r.LinkType() != 0 {
   143  			t.Fatalf("[first interface (section %d)] LinkType should be 0 with WantMixedLinkType, but is %s", section, r.LinkType())
   144  		}
   145  	} else {
   146  		if r.LinkType() != test.linkType {
   147  			t.Fatalf("[first interface (section %d)] LinkType mismatch: Should be %s but is %s", section, test.linkType, r.LinkType())
   148  		}
   149  	}
   150  
   151  	for i, packet := range test.packets {
   152  		var data []byte
   153  		var ci gopacket.CaptureInfo
   154  		var err error
   155  
   156  		if zerocopy {
   157  			data, ci, err = r.ZeroCopyReadPacketData()
   158  		} else {
   159  			data, ci, err = r.ReadPacketData()
   160  		}
   161  		if err == io.EOF {
   162  			t.Fatalf("[packets] Expected %d packets, but got only %d", len(test.packets), i)
   163  		}
   164  		if err != nil {
   165  			if err != packet.err {
   166  				t.Fatalf("[packet %d] Expected error %s, but got %s", i, packet.err, err)
   167  			}
   168  			if err != ErrNgVersionMismatch {
   169  				testSection(nil, r.SectionInfo())
   170  			}
   171  			return
   172  		}
   173  
   174  		if bytes.Compare(data, packet.data) != 0 {
   175  			t.Log(data)
   176  			t.Log(packet.data)
   177  			t.Fatalf("[packet %d] data mismatch", i)
   178  		}
   179  
   180  		if !reflect.DeepEqual(ci, packet.ci) {
   181  			t.Fatalf("[packet %d] ci mismatch:\ngot:\n%#v\nwant:\n%#v\n\n", i, ci, packet.ci)
   182  		}
   183  	}
   184  
   185  	if zerocopy {
   186  		_, _, err = r.ZeroCopyReadPacketData()
   187  	} else {
   188  		_, _, err = r.ReadPacketData()
   189  	}
   190  	if err != io.EOF {
   191  		t.Fatalf("[packets] Expected only %d packet(s), but got at least one more!", len(test.packets))
   192  	}
   193  
   194  	testSection(nil, r.SectionInfo())
   195  
   196  	if section != len(test.sections) {
   197  		t.Fatalf("File should have %d sections, but has %d", len(test.sections), section)
   198  	}
   199  }
   200  
   201  var tests = []ngFileReadTest{
   202  	{
   203  		testName: "test001",
   204  		linkType: layers.LinkTypeEthernet,
   205  		sections: []ngFileReadTestSection{
   206  			{
   207  				sectionInfo: NgSectionInfo{
   208  					Hardware:    "Apple MBP",
   209  					OS:          "OS-X 10.10.5",
   210  					Application: "pcap_writer.lua",
   211  					Comment:     "test001",
   212  				},
   213  				ifaces: []NgInterface{
   214  					{
   215  						LinkType:   layers.LinkTypeEthernet,
   216  						SnapLength: 0,
   217  						Name:       "silly ethernet interface",
   218  					},
   219  				},
   220  			},
   221  		},
   222  		packets: []ngFileReadTestPacket{
   223  			{
   224  				data: ngPacketSource[0],
   225  				ci: gopacket.CaptureInfo{
   226  					Timestamp:      time.Unix(0, 0).UTC(),
   227  					Length:         len(ngPacketSource[0]),
   228  					CaptureLength:  len(ngPacketSource[0]),
   229  					InterfaceIndex: 0,
   230  				},
   231  			},
   232  			{
   233  				data: ngPacketSource[1],
   234  				ci: gopacket.CaptureInfo{
   235  					Timestamp:      time.Unix(0, 0).UTC(),
   236  					Length:         len(ngPacketSource[1]),
   237  					CaptureLength:  len(ngPacketSource[1]),
   238  					InterfaceIndex: 0,
   239  				},
   240  			},
   241  			{
   242  				data: ngPacketSource[2],
   243  				ci: gopacket.CaptureInfo{
   244  					Timestamp:      time.Unix(0, 0).UTC(),
   245  					Length:         len(ngPacketSource[2]),
   246  					CaptureLength:  len(ngPacketSource[2]),
   247  					InterfaceIndex: 0,
   248  				},
   249  			},
   250  			{
   251  				data: ngPacketSource[3],
   252  				ci: gopacket.CaptureInfo{
   253  					Timestamp:      time.Unix(0, 0).UTC(),
   254  					Length:         len(ngPacketSource[3]),
   255  					CaptureLength:  len(ngPacketSource[3]),
   256  					InterfaceIndex: 0,
   257  				},
   258  			},
   259  		},
   260  	},
   261  	{
   262  		testName:          "test002",
   263  		wantMixedLinkType: true,
   264  		sections: []ngFileReadTestSection{
   265  			{
   266  				sectionInfo: NgSectionInfo{
   267  					Hardware:    "Apple MBP",
   268  					OS:          "OS-X 10.10.5",
   269  					Application: "pcap_writer.lua",
   270  					Comment:     "test002",
   271  				},
   272  			},
   273  		},
   274  	},
   275  	{
   276  		testName: "test003",
   277  		linkType: layers.LinkTypeEthernet,
   278  		sections: []ngFileReadTestSection{
   279  			{
   280  				sectionInfo: NgSectionInfo{
   281  					Hardware:    "Apple MBP",
   282  					OS:          "OS-X 10.10.5",
   283  					Application: "pcap_writer.lua",
   284  					Comment:     "test003",
   285  				},
   286  				ifaces: []NgInterface{
   287  					{
   288  						LinkType:   layers.LinkTypeEthernet,
   289  						SnapLength: 96,
   290  						Name:       "silly ethernet interface",
   291  					},
   292  				},
   293  			},
   294  		},
   295  	},
   296  	{
   297  		testName: "test004",
   298  		linkType: layers.LinkTypeEthernet,
   299  		sections: []ngFileReadTestSection{
   300  			{
   301  				sectionInfo: NgSectionInfo{
   302  					Hardware:    "Apple MBP",
   303  					OS:          "OS-X 10.10.5",
   304  					Application: "pcap_writer.lua",
   305  					Comment:     "test004",
   306  				},
   307  				ifaces: []NgInterface{
   308  					{
   309  						LinkType:   layers.LinkTypeEthernet,
   310  						SnapLength: 96,
   311  						Name:       "eth0",
   312  					},
   313  					{
   314  						LinkType:   layers.LinkTypeEthernet,
   315  						SnapLength: 128,
   316  						Name:       "en1",
   317  					},
   318  				},
   319  			},
   320  		},
   321  		packets: []ngFileReadTestPacket{
   322  			{
   323  				data: ngPacketSource[0][:96],
   324  				ci: gopacket.CaptureInfo{
   325  					Timestamp:      time.Unix(0, 0x4c39764ca47aa*1000).UTC(),
   326  					Length:         len(ngPacketSource[0]),
   327  					CaptureLength:  96,
   328  					InterfaceIndex: 0,
   329  				},
   330  			},
   331  			{
   332  				data: ngPacketSource[1][:128],
   333  				ci: gopacket.CaptureInfo{
   334  					Timestamp:      time.Unix(0, 0x4c39764ca47aa*1000+1000*1000).UTC(),
   335  					Length:         len(ngPacketSource[1]),
   336  					CaptureLength:  128,
   337  					InterfaceIndex: 1,
   338  				},
   339  			},
   340  			{
   341  				data: ngPacketSource[2][:96],
   342  				ci: gopacket.CaptureInfo{
   343  					Timestamp:      time.Unix(0, 0x4c39764ca47aa*1000+2000*1000).UTC(),
   344  					Length:         len(ngPacketSource[2]),
   345  					CaptureLength:  96,
   346  					InterfaceIndex: 0,
   347  				},
   348  			},
   349  			{
   350  				data: ngPacketSource[3][:128],
   351  				ci: gopacket.CaptureInfo{
   352  					Timestamp:      time.Unix(0, 0x4c39764ca47aa*1000+3000*1000).UTC(),
   353  					Length:         len(ngPacketSource[3]),
   354  					CaptureLength:  128,
   355  					InterfaceIndex: 1,
   356  				},
   357  			},
   358  		},
   359  	},
   360  	{
   361  		testName: "test005",
   362  		linkType: layers.LinkTypeEthernet,
   363  		sections: []ngFileReadTestSection{
   364  			{
   365  				sectionInfo: NgSectionInfo{
   366  					Hardware:    "Apple MBP",
   367  					OS:          "OS-X 10.10.5",
   368  					Application: "pcap_writer.lua",
   369  					Comment:     "test005",
   370  				},
   371  				ifaces: []NgInterface{
   372  					{
   373  						LinkType:   layers.LinkTypeEthernet,
   374  						SnapLength: 96,
   375  						Name:       "eth0",
   376  					},
   377  					{
   378  						LinkType:   layers.LinkTypeEthernet,
   379  						SnapLength: 128,
   380  						Name:       "en1",
   381  					},
   382  				},
   383  			},
   384  		},
   385  		packets: []ngFileReadTestPacket{
   386  			{
   387  				data: ngPacketSource[0][:96],
   388  				ci: gopacket.CaptureInfo{
   389  					Timestamp:      time.Unix(0, 0x4c39764ca47aa*1000).UTC(),
   390  					Length:         len(ngPacketSource[0]),
   391  					CaptureLength:  96,
   392  					InterfaceIndex: 0,
   393  				},
   394  			},
   395  			{
   396  				data: ngPacketSource[1][:128],
   397  				ci: gopacket.CaptureInfo{
   398  					Timestamp:      time.Unix(0, 0x4c39764ca47aa*1000+1000*1000).UTC(),
   399  					Length:         len(ngPacketSource[1]),
   400  					CaptureLength:  128,
   401  					InterfaceIndex: 1,
   402  				},
   403  			},
   404  			{
   405  				data: ngPacketSource[2][:96],
   406  				ci: gopacket.CaptureInfo{
   407  					Timestamp:      time.Unix(0, 0x4c39764ca47aa*1000+2000*1000).UTC(),
   408  					Length:         len(ngPacketSource[2]),
   409  					CaptureLength:  96,
   410  					InterfaceIndex: 0,
   411  				},
   412  			},
   413  			{
   414  				data: ngPacketSource[3][:128],
   415  				ci: gopacket.CaptureInfo{
   416  					Timestamp:      time.Unix(0, 0x4c39764ca47aa*1000+3000*1000).UTC(),
   417  					Length:         len(ngPacketSource[3]),
   418  					CaptureLength:  128,
   419  					InterfaceIndex: 1,
   420  				},
   421  			},
   422  		},
   423  	},
   424  	{
   425  		testName: "test006",
   426  		linkType: layers.LinkTypeEthernet,
   427  		sections: []ngFileReadTestSection{
   428  			{
   429  				sectionInfo: NgSectionInfo{
   430  					Hardware:    "Apple MBP",
   431  					OS:          "OS-X 10.10.5",
   432  					Application: "pcap_writer.lua",
   433  					Comment:     "test006",
   434  				},
   435  				ifaces: []NgInterface{
   436  					{
   437  						LinkType:   layers.LinkTypeEthernet,
   438  						SnapLength: 96,
   439  						Name:       "eth0",
   440  					},
   441  					{
   442  						LinkType: layers.LinkTypeNull,
   443  						Name:     "en1",
   444  					},
   445  				},
   446  			},
   447  		},
   448  
   449  		packets: []ngFileReadTestPacket{
   450  			{
   451  				data: ngPacketSource[0][:96],
   452  				ci: gopacket.CaptureInfo{
   453  					Timestamp:      time.Unix(0, 0x4c39764ca47aa*1000).UTC(),
   454  					Length:         len(ngPacketSource[0]),
   455  					CaptureLength:  96,
   456  					InterfaceIndex: 0,
   457  				},
   458  			},
   459  			{
   460  				data: ngPacketSource[1][:96],
   461  				ci: gopacket.CaptureInfo{
   462  					Timestamp:      time.Unix(0, 0x4c39764ca47aa*1000+2000*1000).UTC(),
   463  					Length:         len(ngPacketSource[1]),
   464  					CaptureLength:  96,
   465  					InterfaceIndex: 0,
   466  				},
   467  			},
   468  			{
   469  				data: ngPacketSource[2][:96],
   470  				ci: gopacket.CaptureInfo{
   471  					Timestamp:      time.Unix(0, 0x4c39764ca47aa*1000+3000*1000).UTC(),
   472  					Length:         len(ngPacketSource[2]),
   473  					CaptureLength:  96,
   474  					InterfaceIndex: 0,
   475  				},
   476  			},
   477  			{
   478  				data: ngPacketSource[3][:96],
   479  				ci: gopacket.CaptureInfo{
   480  					Timestamp:      time.Unix(0, 0x4c39764ca47aa*1000+4000*1000).UTC(),
   481  					Length:         len(ngPacketSource[3]),
   482  					CaptureLength:  96,
   483  					InterfaceIndex: 0,
   484  				},
   485  			},
   486  		},
   487  	},
   488  	{
   489  		testName:                   "test006",
   490  		testType:                   "/ErrorOnMismatchingLink",
   491  		errorOnMismatchingLinkType: true,
   492  		linkType:                   layers.LinkTypeEthernet,
   493  		sections: []ngFileReadTestSection{
   494  			{
   495  				sectionInfo: NgSectionInfo{
   496  					Hardware:    "Apple MBP",
   497  					OS:          "OS-X 10.10.5",
   498  					Application: "pcap_writer.lua",
   499  					Comment:     "test006",
   500  				},
   501  				ifaces: []NgInterface{
   502  					{
   503  						LinkType:   layers.LinkTypeEthernet,
   504  						SnapLength: 96,
   505  						Name:       "eth0",
   506  					},
   507  					{
   508  						LinkType: layers.LinkTypeNull,
   509  						Name:     "en1",
   510  					},
   511  				},
   512  			},
   513  		},
   514  		packets: []ngFileReadTestPacket{
   515  			{
   516  				data: ngPacketSource[0][:96],
   517  				ci: gopacket.CaptureInfo{
   518  					Timestamp:      time.Unix(0, 0x4c39764ca47aa*1000).UTC(),
   519  					Length:         len(ngPacketSource[0]),
   520  					CaptureLength:  96,
   521  					InterfaceIndex: 0,
   522  				},
   523  			},
   524  			{err: ErrNgLinkTypeMismatch},
   525  		},
   526  	},
   527  	{
   528  		testName:          "test006",
   529  		testType:          "/WantMixedLinkType",
   530  		wantMixedLinkType: true,
   531  		linkType:          layers.LinkTypeEthernet,
   532  		sections: []ngFileReadTestSection{
   533  			{
   534  				sectionInfo: NgSectionInfo{
   535  					Hardware:    "Apple MBP",
   536  					OS:          "OS-X 10.10.5",
   537  					Application: "pcap_writer.lua",
   538  					Comment:     "test006",
   539  				},
   540  				ifaces: []NgInterface{
   541  					{
   542  						LinkType:   layers.LinkTypeEthernet,
   543  						SnapLength: 96,
   544  						Name:       "eth0",
   545  					},
   546  					{
   547  						LinkType: layers.LinkTypeNull,
   548  						Name:     "en1",
   549  					},
   550  				},
   551  			},
   552  		},
   553  		packets: []ngFileReadTestPacket{
   554  			{
   555  				data: ngPacketSource[0][:96],
   556  				ci: gopacket.CaptureInfo{
   557  					Timestamp:      time.Unix(0, 0x4c39764ca47aa*1000).UTC(),
   558  					Length:         len(ngPacketSource[0]),
   559  					CaptureLength:  96,
   560  					InterfaceIndex: 0,
   561  					AncillaryData:  []interface{}{layers.LinkTypeEthernet},
   562  				},
   563  			},
   564  			{
   565  				data: ngPacketSource[4],
   566  				ci: gopacket.CaptureInfo{
   567  					Timestamp:      time.Unix(0, 0x4c39764ca47aa*1000+1000*1000).UTC(),
   568  					Length:         len(ngPacketSource[4]),
   569  					CaptureLength:  len(ngPacketSource[4]),
   570  					InterfaceIndex: 1,
   571  					AncillaryData:  []interface{}{layers.LinkTypeNull},
   572  				},
   573  			},
   574  			{
   575  				data: ngPacketSource[1][:96],
   576  				ci: gopacket.CaptureInfo{
   577  					Timestamp:      time.Unix(0, 0x4c39764ca47aa*1000+2000*1000).UTC(),
   578  					Length:         len(ngPacketSource[1]),
   579  					CaptureLength:  96,
   580  					InterfaceIndex: 0,
   581  					AncillaryData:  []interface{}{layers.LinkTypeEthernet},
   582  				},
   583  			},
   584  			{
   585  				data: ngPacketSource[2][:96],
   586  				ci: gopacket.CaptureInfo{
   587  					Timestamp:      time.Unix(0, 0x4c39764ca47aa*1000+3000*1000).UTC(),
   588  					Length:         len(ngPacketSource[2]),
   589  					CaptureLength:  96,
   590  					InterfaceIndex: 0,
   591  					AncillaryData:  []interface{}{layers.LinkTypeEthernet},
   592  				},
   593  			},
   594  			{
   595  				data: ngPacketSource[3][:96],
   596  				ci: gopacket.CaptureInfo{
   597  					Timestamp:      time.Unix(0, 0x4c39764ca47aa*1000+4000*1000).UTC(),
   598  					Length:         len(ngPacketSource[3]),
   599  					CaptureLength:  96,
   600  					InterfaceIndex: 0,
   601  					AncillaryData:  []interface{}{layers.LinkTypeEthernet},
   602  				},
   603  			},
   604  		},
   605  	},
   606  	{
   607  		testName: "test007",
   608  		linkType: layers.LinkTypeEthernet,
   609  		sections: []ngFileReadTestSection{
   610  			{
   611  				sectionInfo: NgSectionInfo{
   612  					Hardware:    "Apple MBP",
   613  					OS:          "OS-X 10.10.5",
   614  					Application: "pcap_writer.lua",
   615  					Comment:     "test007",
   616  				},
   617  				ifaces: []NgInterface{
   618  					{
   619  						LinkType:   layers.LinkTypeEthernet,
   620  						SnapLength: 96,
   621  						Name:       "eth0",
   622  					},
   623  				},
   624  			},
   625  		},
   626  		packets: []ngFileReadTestPacket{
   627  			{
   628  				data: ngPacketSource[0][:96],
   629  				ci: gopacket.CaptureInfo{
   630  					Timestamp:      time.Unix(0, 0x4c39764ca47aa*1000).UTC(),
   631  					Length:         len(ngPacketSource[0]),
   632  					CaptureLength:  96,
   633  					InterfaceIndex: 0,
   634  				},
   635  			},
   636  		},
   637  	},
   638  	{
   639  		testName: "test008",
   640  		linkType: layers.LinkTypeEthernet,
   641  		sections: []ngFileReadTestSection{
   642  			{
   643  				sectionInfo: NgSectionInfo{
   644  					Hardware:    "Apple MBP",
   645  					OS:          "OS-X 10.10.5",
   646  					Application: "pcap_writer.lua",
   647  					Comment:     "test008",
   648  				},
   649  				ifaces: []NgInterface{
   650  					{
   651  						LinkType:            layers.LinkTypeEthernet,
   652  						SnapLength:          96,
   653  						Name:                "eth-_0 foo",
   654  						Comment:             "test008, and more\nfoo\r\nbar",
   655  						Description:         "silly ethernet interface",
   656  						Filter:              "tcp port 23 and host 192.0.2.5",
   657  						OS:                  "Microsoft Windows for Workgroups 3.11b\npatch 42",
   658  						TimestampResolution: 9,
   659  					},
   660  					{
   661  						LinkType:            layers.LinkTypeEthernet,
   662  						SnapLength:          128,
   663  						Name:                "en1",
   664  						Comment:             "test008",
   665  						Description:         "silly ethernet interface 2",
   666  						Filter:              "tcp port 23 and host 192.0.2.5",
   667  						OS:                  "Novell NetWare 4.11\nbut not using IPX",
   668  						TimestampResolution: 9,
   669  					},
   670  				},
   671  			},
   672  		},
   673  		packets: []ngFileReadTestPacket{
   674  			{
   675  				data: ngPacketSource[0][:96],
   676  				ci: gopacket.CaptureInfo{
   677  					Timestamp:      time.Unix(0, 0x4c39764ca47aa).UTC(),
   678  					Length:         len(ngPacketSource[0]),
   679  					CaptureLength:  96,
   680  					InterfaceIndex: 0,
   681  				},
   682  			},
   683  			{
   684  				data: ngPacketSource[1][:128],
   685  				ci: gopacket.CaptureInfo{
   686  					Timestamp:      time.Unix(0, 0x4c39764ca47aa+1000).UTC(),
   687  					Length:         len(ngPacketSource[1]),
   688  					CaptureLength:  128,
   689  					InterfaceIndex: 1,
   690  				},
   691  			},
   692  			{
   693  				data: ngPacketSource[2][:96],
   694  				ci: gopacket.CaptureInfo{
   695  					Timestamp:      time.Unix(0, 0x4c39764ca47aa+2000).UTC(),
   696  					Length:         len(ngPacketSource[2]),
   697  					CaptureLength:  96,
   698  					InterfaceIndex: 0,
   699  				},
   700  			},
   701  			{
   702  				data: ngPacketSource[3][:128],
   703  				ci: gopacket.CaptureInfo{
   704  					Timestamp:      time.Unix(0, 0x4c39764ca47aa+3000).UTC(),
   705  					Length:         len(ngPacketSource[3]),
   706  					CaptureLength:  128,
   707  					InterfaceIndex: 1,
   708  				},
   709  			},
   710  		},
   711  	},
   712  	{
   713  		testName: "test009",
   714  		linkType: layers.LinkTypeEthernet,
   715  		sections: []ngFileReadTestSection{
   716  			{
   717  				sectionInfo: NgSectionInfo{
   718  					Hardware:    "Apple MBP",
   719  					OS:          "OS-X 10.10.5",
   720  					Application: "pcap_writer.lua",
   721  					Comment:     "test009",
   722  				},
   723  				ifaces: []NgInterface{
   724  					{
   725  						LinkType:   layers.LinkTypeEthernet,
   726  						SnapLength: 0,
   727  						Name:       "eth0",
   728  					},
   729  				},
   730  			},
   731  		},
   732  		packets: []ngFileReadTestPacket{
   733  			{
   734  				data: ngPacketSource[0],
   735  				ci: gopacket.CaptureInfo{
   736  					Timestamp:      time.Unix(0, 0x4c39764ca47aa*1000).UTC(),
   737  					Length:         len(ngPacketSource[0]),
   738  					CaptureLength:  len(ngPacketSource[0]),
   739  					InterfaceIndex: 0,
   740  				},
   741  			},
   742  			{
   743  				data: ngPacketSource[1],
   744  				ci: gopacket.CaptureInfo{
   745  					Timestamp:      time.Unix(0, 0x4c39764ca47aa*1000+1000*1000).UTC(),
   746  					Length:         len(ngPacketSource[1]),
   747  					CaptureLength:  len(ngPacketSource[1]),
   748  					InterfaceIndex: 0,
   749  				},
   750  			},
   751  		},
   752  	},
   753  	{
   754  		testName: "test010",
   755  		linkType: layers.LinkTypeEthernet,
   756  		sections: []ngFileReadTestSection{
   757  			{
   758  				sectionInfo: NgSectionInfo{
   759  					Hardware:    "Apple MBP",
   760  					OS:          "OS-X 10.10.5",
   761  					Application: "pcap_writer.lua",
   762  					Comment:     "test010",
   763  				},
   764  				ifaces: []NgInterface{
   765  					{
   766  						LinkType:   layers.LinkTypeEthernet,
   767  						SnapLength: 0,
   768  						Name:       "eth0",
   769  					},
   770  				},
   771  			},
   772  		},
   773  		packets: []ngFileReadTestPacket{
   774  			{
   775  				data: ngPacketSource[0],
   776  				ci: gopacket.CaptureInfo{
   777  					Timestamp:      time.Time{},
   778  					Length:         len(ngPacketSource[0]),
   779  					CaptureLength:  len(ngPacketSource[0]),
   780  					InterfaceIndex: 0,
   781  				},
   782  			},
   783  			{
   784  				data: ngPacketSource[1],
   785  				ci: gopacket.CaptureInfo{
   786  					Timestamp:      time.Time{},
   787  					Length:         len(ngPacketSource[1]),
   788  					CaptureLength:  len(ngPacketSource[1]),
   789  					InterfaceIndex: 0,
   790  				},
   791  			},
   792  			{
   793  				data: ngPacketSource[2],
   794  				ci: gopacket.CaptureInfo{
   795  					Timestamp:      time.Time{},
   796  					Length:         len(ngPacketSource[2]),
   797  					CaptureLength:  len(ngPacketSource[2]),
   798  					InterfaceIndex: 0,
   799  				},
   800  			},
   801  			{
   802  				data: ngPacketSource[3],
   803  				ci: gopacket.CaptureInfo{
   804  					Timestamp:      time.Time{},
   805  					Length:         len(ngPacketSource[3]),
   806  					CaptureLength:  len(ngPacketSource[3]),
   807  					InterfaceIndex: 0,
   808  				},
   809  			},
   810  		},
   811  	},
   812  	{
   813  		testName: "test011",
   814  		linkType: layers.LinkTypeEthernet,
   815  		sections: []ngFileReadTestSection{
   816  			{
   817  				sectionInfo: NgSectionInfo{
   818  					Hardware:    "Apple MBP",
   819  					OS:          "OS-X 10.10.5",
   820  					Application: "pcap_writer.lua",
   821  					Comment:     "test011",
   822  				},
   823  				ifaces: []NgInterface{
   824  					{
   825  						LinkType:   layers.LinkTypeEthernet,
   826  						SnapLength: 0,
   827  						Name:       "eth0",
   828  					},
   829  				},
   830  			},
   831  		},
   832  		packets: []ngFileReadTestPacket{
   833  			{
   834  				data: ngPacketSource[0],
   835  				ci: gopacket.CaptureInfo{
   836  					Timestamp:      time.Time{},
   837  					Length:         len(ngPacketSource[0]),
   838  					CaptureLength:  len(ngPacketSource[0]),
   839  					InterfaceIndex: 0,
   840  				},
   841  			},
   842  			{
   843  				data: ngPacketSource[1],
   844  				ci: gopacket.CaptureInfo{
   845  					Timestamp:      time.Unix(0, 0x4c39764ca47aa*1000).UTC(),
   846  					Length:         len(ngPacketSource[1]),
   847  					CaptureLength:  len(ngPacketSource[1]),
   848  					InterfaceIndex: 0,
   849  				},
   850  			},
   851  			{
   852  				data: ngPacketSource[2],
   853  				ci: gopacket.CaptureInfo{
   854  					Timestamp:      time.Time{},
   855  					Length:         len(ngPacketSource[2]),
   856  					CaptureLength:  len(ngPacketSource[2]),
   857  					InterfaceIndex: 0,
   858  				},
   859  			},
   860  			{
   861  				data: ngPacketSource[3],
   862  				ci: gopacket.CaptureInfo{
   863  					Timestamp:      time.Unix(0, 0x4c39764ca47aa*1000+1000*2000).UTC(),
   864  					Length:         len(ngPacketSource[3]),
   865  					CaptureLength:  len(ngPacketSource[3]),
   866  					InterfaceIndex: 0,
   867  				},
   868  			},
   869  		},
   870  	},
   871  	{
   872  		testName: "test012",
   873  		linkType: layers.LinkTypeEthernet,
   874  		sections: []ngFileReadTestSection{
   875  			{
   876  				sectionInfo: NgSectionInfo{
   877  					Hardware:    "Apple MBP",
   878  					OS:          "OS-X 10.10.5",
   879  					Application: "pcap_writer.lua",
   880  					Comment:     "test012",
   881  				},
   882  				ifaces: []NgInterface{
   883  					{
   884  						LinkType:   layers.LinkTypeEthernet,
   885  						SnapLength: 315,
   886  						Name:       "eth0",
   887  					},
   888  				},
   889  			},
   890  		},
   891  		packets: []ngFileReadTestPacket{
   892  			{
   893  				data: ngPacketSource[0],
   894  				ci: gopacket.CaptureInfo{
   895  					Timestamp:      time.Time{},
   896  					Length:         len(ngPacketSource[0]),
   897  					CaptureLength:  len(ngPacketSource[0]),
   898  					InterfaceIndex: 0,
   899  				},
   900  			},
   901  			{
   902  				data: ngPacketSource[1][:315],
   903  				ci: gopacket.CaptureInfo{
   904  					Timestamp:      time.Time{},
   905  					Length:         len(ngPacketSource[1]),
   906  					CaptureLength:  315,
   907  					InterfaceIndex: 0,
   908  				},
   909  			},
   910  			{
   911  				data: ngPacketSource[2],
   912  				ci: gopacket.CaptureInfo{
   913  					Timestamp:      time.Unix(0, 0).UTC(),
   914  					Length:         len(ngPacketSource[2]),
   915  					CaptureLength:  len(ngPacketSource[2]),
   916  					InterfaceIndex: 0,
   917  				},
   918  			},
   919  			{
   920  				data: ngPacketSource[3][:315],
   921  				ci: gopacket.CaptureInfo{
   922  					Timestamp:      time.Unix(0, 0).UTC(),
   923  					Length:         len(ngPacketSource[3]),
   924  					CaptureLength:  315,
   925  					InterfaceIndex: 0,
   926  				},
   927  			},
   928  		},
   929  	},
   930  	{
   931  		testName: "test013",
   932  		linkType: layers.LinkTypeEthernet,
   933  		sections: []ngFileReadTestSection{
   934  			{
   935  				sectionInfo: NgSectionInfo{
   936  					Hardware:    "Apple MBP",
   937  					OS:          "OS-X 10.10.5",
   938  					Application: "pcap_writer.lua",
   939  					Comment:     "test013",
   940  				},
   941  				ifaces: []NgInterface{
   942  					{
   943  						LinkType:   layers.LinkTypeEthernet,
   944  						SnapLength: 96,
   945  						Name:       "silly ethernet interface",
   946  						Statistics: NgInterfaceStatistics{
   947  							LastUpdate:      time.Unix(0, 0).UTC(),
   948  							StartTime:       time.Unix(0, 0x4c39764ca47aa*1000).UTC(),
   949  							EndTime:         time.Unix(0, 0x4c39764ca47aa*1000+1000*1000).UTC(),
   950  							PacketsDropped:  10,
   951  							PacketsReceived: NgNoValue64,
   952  						},
   953  					},
   954  				},
   955  			},
   956  		},
   957  	},
   958  	{
   959  		testName:          "test014",
   960  		wantMixedLinkType: true,
   961  		sections: []ngFileReadTestSection{
   962  			{
   963  				sectionInfo: NgSectionInfo{
   964  					Hardware:    "Apple MBP",
   965  					OS:          "OS-X 10.10.5",
   966  					Application: "pcap_writer.lua",
   967  					Comment:     "test014",
   968  				},
   969  				ifaces: []NgInterface{
   970  					{
   971  						LinkType:   layers.LinkTypeEthernet,
   972  						SnapLength: 96,
   973  						Name:       "eth0",
   974  						Statistics: NgInterfaceStatistics{
   975  							LastUpdate:      time.Unix(0, 0x4c39764ca47aa*1000).UTC(),
   976  							StartTime:       time.Unix(0, 0x4c39764ca47aa*1000).UTC(),
   977  							EndTime:         time.Unix(0, 0x4c39764ca47aa*1000+1000*1000).UTC(),
   978  							PacketsDropped:  10,
   979  							PacketsReceived: NgNoValue64,
   980  						},
   981  					},
   982  					{
   983  						LinkType:   layers.LinkTypeNull,
   984  						SnapLength: 0,
   985  						Name:       "null1",
   986  						Statistics: NgInterfaceStatistics{
   987  							LastUpdate:      time.Unix(0, 0x4c39764ca47aa*1000).UTC(),
   988  							StartTime:       time.Unix(0, 0x4c39764ca47aa*1000).UTC(),
   989  							EndTime:         time.Unix(0, 0x4c39764ca47aa*1000+1000*1000).UTC(),
   990  							PacketsDropped:  10,
   991  							PacketsReceived: NgNoValue64,
   992  						},
   993  					},
   994  					{
   995  						LinkType:   layers.LinkTypeEthernet,
   996  						SnapLength: 128,
   997  						Name:       "silly ethernet interface 2",
   998  						Statistics: NgInterfaceStatistics{
   999  							LastUpdate:      time.Unix(0, 0x4c39764ca47aa*1000).UTC(),
  1000  							StartTime:       time.Unix(0, 0x4c39764ca47aa*1000).UTC(),
  1001  							EndTime:         time.Unix(0, 0x4c39764ca47aa*1000+1000*1000).UTC(),
  1002  							PacketsDropped:  10,
  1003  							PacketsReceived: NgNoValue64,
  1004  							Comment:         "test014 ISB",
  1005  						},
  1006  					},
  1007  				},
  1008  			},
  1009  		},
  1010  	},
  1011  	{
  1012  		testName: "test015",
  1013  		linkType: layers.LinkTypeEthernet,
  1014  		sections: []ngFileReadTestSection{
  1015  			{
  1016  				sectionInfo: NgSectionInfo{
  1017  					Hardware:    "Apple MBP",
  1018  					OS:          "OS-X 10.10.5",
  1019  					Application: "pcap_writer.lua",
  1020  					Comment:     "test015",
  1021  				},
  1022  				ifaces: []NgInterface{
  1023  					{
  1024  						LinkType:   layers.LinkTypeEthernet,
  1025  						SnapLength: 96,
  1026  						Name:       "silly ethernet interface",
  1027  						Comment:    "test015 IDB",
  1028  					},
  1029  				},
  1030  			},
  1031  		},
  1032  	},
  1033  	{
  1034  		testName: "test016",
  1035  		linkType: layers.LinkTypeEthernet,
  1036  		sections: []ngFileReadTestSection{
  1037  			{
  1038  				sectionInfo: NgSectionInfo{
  1039  					Hardware:    "Apple MBP",
  1040  					OS:          "OS-X 10.10.5",
  1041  					Application: "pcap_writer.lua",
  1042  					Comment:     "test016",
  1043  				},
  1044  				ifaces: []NgInterface{
  1045  					{
  1046  						LinkType:   layers.LinkTypeEthernet,
  1047  						SnapLength: 0,
  1048  						Name:       "eth0",
  1049  					},
  1050  				},
  1051  			},
  1052  		},
  1053  		packets: []ngFileReadTestPacket{
  1054  			{
  1055  				data: ngPacketSource[0],
  1056  				ci: gopacket.CaptureInfo{
  1057  					Timestamp:      time.Time{},
  1058  					Length:         len(ngPacketSource[0]),
  1059  					CaptureLength:  len(ngPacketSource[0]),
  1060  					InterfaceIndex: 0,
  1061  				},
  1062  			},
  1063  			{
  1064  				data: ngPacketSource[1],
  1065  				ci: gopacket.CaptureInfo{
  1066  					Timestamp:      time.Unix(0, 0x4c39764ca47aa*1000).UTC(),
  1067  					Length:         len(ngPacketSource[1]),
  1068  					CaptureLength:  len(ngPacketSource[1]),
  1069  					InterfaceIndex: 0,
  1070  				},
  1071  			},
  1072  			{
  1073  				data: ngPacketSource[2],
  1074  				ci: gopacket.CaptureInfo{
  1075  					Timestamp:      time.Time{},
  1076  					Length:         len(ngPacketSource[2]),
  1077  					CaptureLength:  len(ngPacketSource[2]),
  1078  					InterfaceIndex: 0,
  1079  				},
  1080  			},
  1081  			{
  1082  				data: ngPacketSource[3],
  1083  				ci: gopacket.CaptureInfo{
  1084  					Timestamp:      time.Unix(0, 0x4c39764ca47aa*1000+1000*2000).UTC(),
  1085  					Length:         len(ngPacketSource[3]),
  1086  					CaptureLength:  len(ngPacketSource[3]),
  1087  					InterfaceIndex: 0,
  1088  				},
  1089  			},
  1090  		},
  1091  	},
  1092  	{
  1093  		testName:          "test017",
  1094  		wantMixedLinkType: true,
  1095  		sections: []ngFileReadTestSection{
  1096  			{
  1097  				sectionInfo: NgSectionInfo{
  1098  					Hardware:    "Apple MBP",
  1099  					OS:          "OS-X 10.10.5",
  1100  					Application: "pcap_writer.lua",
  1101  					Comment:     "test017",
  1102  				},
  1103  			},
  1104  		},
  1105  	},
  1106  	{
  1107  		testName: "test018",
  1108  		linkType: layers.LinkTypeEthernet,
  1109  		sections: []ngFileReadTestSection{
  1110  			{
  1111  				sectionInfo: NgSectionInfo{
  1112  					Hardware:    "Apple MBP",
  1113  					OS:          "OS-X 10.10.5",
  1114  					Application: "pcap_writer.lua",
  1115  					Comment:     "test018",
  1116  				},
  1117  				ifaces: []NgInterface{
  1118  					{
  1119  						LinkType:   layers.LinkTypeEthernet,
  1120  						SnapLength: 0,
  1121  						Name:       "eth0",
  1122  					},
  1123  				},
  1124  			},
  1125  		},
  1126  		packets: []ngFileReadTestPacket{
  1127  			{
  1128  				data: ngPacketSource[0],
  1129  				ci: gopacket.CaptureInfo{
  1130  					Timestamp:      time.Time{},
  1131  					Length:         len(ngPacketSource[0]),
  1132  					CaptureLength:  len(ngPacketSource[0]),
  1133  					InterfaceIndex: 0,
  1134  				},
  1135  			},
  1136  			{
  1137  				data: ngPacketSource[1],
  1138  				ci: gopacket.CaptureInfo{
  1139  					Timestamp:      time.Unix(0, 0x4c39764ca47aa*1000).UTC(),
  1140  					Length:         len(ngPacketSource[1]),
  1141  					CaptureLength:  len(ngPacketSource[1]),
  1142  					InterfaceIndex: 0,
  1143  				},
  1144  			},
  1145  			{
  1146  				data: ngPacketSource[2],
  1147  				ci: gopacket.CaptureInfo{
  1148  					Timestamp:      time.Time{},
  1149  					Length:         len(ngPacketSource[2]),
  1150  					CaptureLength:  len(ngPacketSource[2]),
  1151  					InterfaceIndex: 0,
  1152  				},
  1153  			},
  1154  			{
  1155  				data: ngPacketSource[3],
  1156  				ci: gopacket.CaptureInfo{
  1157  					Timestamp:      time.Unix(0, 0x4c39764ca47aa*1000+1000*2000).UTC(),
  1158  					Length:         len(ngPacketSource[3]),
  1159  					CaptureLength:  len(ngPacketSource[3]),
  1160  					InterfaceIndex: 0,
  1161  				},
  1162  			},
  1163  		},
  1164  	},
  1165  	{
  1166  		testName: "test100",
  1167  		linkType: layers.LinkTypeEthernet,
  1168  		sections: []ngFileReadTestSection{
  1169  			{
  1170  				sectionInfo: NgSectionInfo{
  1171  					Hardware:    "Apple MBP",
  1172  					OS:          "OS-X 10.10.5",
  1173  					Application: "pcap_writer.lua",
  1174  					Comment:     "test100",
  1175  				},
  1176  				ifaces: []NgInterface{
  1177  					{
  1178  						LinkType:   layers.LinkTypeEthernet,
  1179  						SnapLength: 0,
  1180  						Name:       "eth0",
  1181  					},
  1182  					{
  1183  						LinkType:   layers.LinkTypeNull,
  1184  						SnapLength: 0,
  1185  						Name:       "null1",
  1186  					},
  1187  					{
  1188  						LinkType:   layers.LinkTypeEthernet,
  1189  						SnapLength: 128,
  1190  						Name:       "wifi2?",
  1191  					},
  1192  				},
  1193  			},
  1194  		},
  1195  		packets: []ngFileReadTestPacket{
  1196  			{
  1197  				data: ngPacketSource[0],
  1198  				ci: gopacket.CaptureInfo{
  1199  					Timestamp:      time.Time{},
  1200  					Length:         len(ngPacketSource[0]),
  1201  					CaptureLength:  len(ngPacketSource[0]),
  1202  					InterfaceIndex: 0,
  1203  				},
  1204  			},
  1205  			{
  1206  				data: ngPacketSource[1],
  1207  				ci: gopacket.CaptureInfo{
  1208  					Timestamp:      time.Unix(0, 0x4c39764ca47aa*1000).UTC(),
  1209  					Length:         len(ngPacketSource[1]),
  1210  					CaptureLength:  len(ngPacketSource[1]),
  1211  					InterfaceIndex: 0,
  1212  				},
  1213  			},
  1214  			{
  1215  				data: ngPacketSource[2],
  1216  				ci: gopacket.CaptureInfo{
  1217  					Timestamp:      time.Time{},
  1218  					Length:         len(ngPacketSource[2]),
  1219  					CaptureLength:  len(ngPacketSource[2]),
  1220  					InterfaceIndex: 0,
  1221  				},
  1222  			},
  1223  			{
  1224  				data: ngPacketSource[3],
  1225  				ci: gopacket.CaptureInfo{
  1226  					Timestamp:      time.Unix(0, 0x4c39764ca47aa*1000+1000*2000).UTC(),
  1227  					Length:         len(ngPacketSource[3]),
  1228  					CaptureLength:  len(ngPacketSource[3]),
  1229  					InterfaceIndex: 0,
  1230  				},
  1231  			},
  1232  		},
  1233  	},
  1234  	{
  1235  		testName: "test101",
  1236  		linkType: layers.LinkTypeEthernet,
  1237  		sections: []ngFileReadTestSection{
  1238  			{
  1239  				sectionInfo: NgSectionInfo{
  1240  					Hardware:    "Apple MBP",
  1241  					OS:          "OS-X 10.10.5",
  1242  					Application: "pcap_writer.lua",
  1243  					Comment:     "test101",
  1244  				},
  1245  				ifaces: []NgInterface{
  1246  					{
  1247  						LinkType:   layers.LinkTypeEthernet,
  1248  						SnapLength: 96,
  1249  						Name:       "eth0",
  1250  						Statistics: NgInterfaceStatistics{
  1251  							LastUpdate:      time.Unix(0, 0).UTC(),
  1252  							PacketsDropped:  NgNoValue64,
  1253  							PacketsReceived: NgNoValue64,
  1254  						},
  1255  					},
  1256  					{
  1257  						LinkType:   layers.LinkTypeNull,
  1258  						SnapLength: 0,
  1259  						Name:       "null1",
  1260  						Statistics: NgInterfaceStatistics{
  1261  							LastUpdate:      time.Unix(0, 0x4c39764ca47aa*1000-1000*1000).UTC(),
  1262  							PacketsDropped:  NgNoValue64,
  1263  							PacketsReceived: NgNoValue64,
  1264  						},
  1265  					},
  1266  					{
  1267  						LinkType:   layers.LinkTypeEthernet,
  1268  						SnapLength: 128,
  1269  						Name:       "silly ethernet interface 2",
  1270  						Statistics: NgInterfaceStatistics{
  1271  							LastUpdate:      time.Unix(0, 0x4c39764ca47aa*1000+1000*1000).UTC(),
  1272  							StartTime:       time.Unix(0, 0x4c39764ca47aa*1000).UTC(),
  1273  							EndTime:         time.Unix(0, 0x4c39764ca47aa*1000+1000*1000).UTC(),
  1274  							PacketsDropped:  10,
  1275  							PacketsReceived: NgNoValue64,
  1276  							Comment:         "test101 ISB-2",
  1277  						},
  1278  					},
  1279  				},
  1280  			},
  1281  		},
  1282  		packets: []ngFileReadTestPacket{
  1283  			{
  1284  				data: ngPacketSource[0][:96],
  1285  				ci: gopacket.CaptureInfo{
  1286  					Timestamp:      time.Unix(0, 0x4c39764ca47aa*1000).UTC(),
  1287  					Length:         len(ngPacketSource[0]),
  1288  					CaptureLength:  96,
  1289  					InterfaceIndex: 0,
  1290  				},
  1291  			},
  1292  			{
  1293  				data: ngPacketSource[1][:128],
  1294  				ci: gopacket.CaptureInfo{
  1295  					Timestamp:      time.Unix(0, 0x4c39764ca47aa*1000).UTC(),
  1296  					Length:         len(ngPacketSource[1]),
  1297  					CaptureLength:  128,
  1298  					InterfaceIndex: 2,
  1299  				},
  1300  			},
  1301  			{
  1302  				data: ngPacketSource[2][:96],
  1303  				ci: gopacket.CaptureInfo{
  1304  					Timestamp:      time.Time{},
  1305  					Length:         len(ngPacketSource[2]),
  1306  					CaptureLength:  96,
  1307  					InterfaceIndex: 0,
  1308  				},
  1309  			},
  1310  		},
  1311  	},
  1312  	{
  1313  		testName: "test102",
  1314  		linkType: layers.LinkTypeEthernet,
  1315  		sections: []ngFileReadTestSection{
  1316  			{
  1317  				sectionInfo: NgSectionInfo{
  1318  					Hardware:    "Apple MBP",
  1319  					OS:          "OS-X 10.10.5",
  1320  					Application: "pcap_writer.lua",
  1321  					Comment:     "test102",
  1322  				},
  1323  				ifaces: []NgInterface{
  1324  					{
  1325  						LinkType:   layers.LinkTypeEthernet,
  1326  						SnapLength: 96,
  1327  						Name:       "eth0",
  1328  						Statistics: NgInterfaceStatistics{
  1329  							LastUpdate:      time.Unix(0, 0).UTC(),
  1330  							PacketsDropped:  NgNoValue64,
  1331  							PacketsReceived: NgNoValue64,
  1332  						},
  1333  					},
  1334  					{
  1335  						LinkType:   layers.LinkTypeNull,
  1336  						SnapLength: 0,
  1337  						Name:       "null1",
  1338  						Statistics: NgInterfaceStatistics{
  1339  							LastUpdate:      time.Unix(0, 0x4c39764ca47aa*1000-1000*1000).UTC(),
  1340  							PacketsDropped:  NgNoValue64,
  1341  							PacketsReceived: NgNoValue64,
  1342  						},
  1343  					},
  1344  					{
  1345  						LinkType:   layers.LinkTypeEthernet,
  1346  						SnapLength: 0,
  1347  						Name:       "silly!\r\nethernet interface 2",
  1348  						Statistics: NgInterfaceStatistics{
  1349  							LastUpdate:      time.Unix(0, 0x4c39764ca47aa*1000+1000*1000).UTC(),
  1350  							StartTime:       time.Unix(0, 0x4c39764ca47aa*1000).UTC(),
  1351  							EndTime:         time.Unix(0, 0x4c39764ca47aa*1000+1000*1000).UTC(),
  1352  							PacketsDropped:  10,
  1353  							PacketsReceived: NgNoValue64,
  1354  							Comment:         "test102 ISB-2",
  1355  						},
  1356  					},
  1357  				},
  1358  			},
  1359  		},
  1360  		packets: []ngFileReadTestPacket{
  1361  			{
  1362  				data: ngPacketSource[0][:96],
  1363  				ci: gopacket.CaptureInfo{
  1364  					Timestamp:      time.Unix(0, 0x4c39764ca47aa*1000).UTC(),
  1365  					Length:         len(ngPacketSource[0]),
  1366  					CaptureLength:  96,
  1367  					InterfaceIndex: 0,
  1368  				},
  1369  			},
  1370  			{
  1371  				data: ngPacketSource[1],
  1372  				ci: gopacket.CaptureInfo{
  1373  					Timestamp:      time.Unix(0, 0x4c39764ca47aa*1000).UTC(),
  1374  					Length:         len(ngPacketSource[1]),
  1375  					CaptureLength:  len(ngPacketSource[1]),
  1376  					InterfaceIndex: 2,
  1377  				},
  1378  			},
  1379  			{
  1380  				data: ngPacketSource[2][:96],
  1381  				ci: gopacket.CaptureInfo{
  1382  					Timestamp:      time.Time{},
  1383  					Length:         len(ngPacketSource[2]),
  1384  					CaptureLength:  96,
  1385  					InterfaceIndex: 0,
  1386  				},
  1387  			},
  1388  			{
  1389  				data: ngPacketSource[3][:96],
  1390  				ci: gopacket.CaptureInfo{
  1391  					Timestamp:      time.Unix(0, 0x4c39764ca47aa*1000+2000*1000).UTC(),
  1392  					Length:         len(ngPacketSource[3]),
  1393  					CaptureLength:  96,
  1394  					InterfaceIndex: 0,
  1395  				},
  1396  			},
  1397  		},
  1398  	},
  1399  	{
  1400  		testName: "test200",
  1401  		linkType: layers.LinkTypeEthernet,
  1402  		sections: []ngFileReadTestSection{
  1403  			{
  1404  				sectionInfo: NgSectionInfo{
  1405  					Hardware:    "Apple MBP",
  1406  					OS:          "OS-X 10.10.5",
  1407  					Application: "pcap_writer.lua",
  1408  					Comment:     "test200",
  1409  				},
  1410  				ifaces: []NgInterface{
  1411  					{
  1412  						LinkType:   layers.LinkTypeEthernet,
  1413  						SnapLength: 96,
  1414  						Name:       "eth0",
  1415  					},
  1416  				},
  1417  			},
  1418  			{
  1419  				sectionInfo: NgSectionInfo{
  1420  					Hardware:    "Apple MBP",
  1421  					OS:          "OS-X 10.10.5",
  1422  					Application: "pcap_writer.lua",
  1423  					Comment:     "test200",
  1424  				},
  1425  				ifaces: []NgInterface{
  1426  					{
  1427  						LinkType:   layers.LinkTypeEthernet,
  1428  						SnapLength: 0,
  1429  						Name:       "eth0",
  1430  					},
  1431  				},
  1432  			},
  1433  			{
  1434  				sectionInfo: NgSectionInfo{
  1435  					Hardware:    "Apple MBP",
  1436  					OS:          "OS-X 10.10.5",
  1437  					Application: "pcap_writer.lua",
  1438  					Comment:     "test200",
  1439  				},
  1440  				ifaces: []NgInterface{
  1441  					{
  1442  						LinkType:   layers.LinkTypeNull,
  1443  						SnapLength: 128,
  1444  						Name:       "null1",
  1445  					},
  1446  				},
  1447  			},
  1448  		},
  1449  	},
  1450  	{
  1451  		testName: "test201",
  1452  		linkType: layers.LinkTypeEthernet,
  1453  		sections: []ngFileReadTestSection{
  1454  			{
  1455  				sectionInfo: NgSectionInfo{
  1456  					Hardware:    "Apple MBP",
  1457  					OS:          "OS-X 10.10.5",
  1458  					Application: "pcap_writer.lua",
  1459  					Comment:     "test201 SHB-0",
  1460  				},
  1461  				ifaces: []NgInterface{
  1462  					{
  1463  						LinkType:   layers.LinkTypeEthernet,
  1464  						SnapLength: 96,
  1465  						Name:       "eth0",
  1466  					},
  1467  					{
  1468  						LinkType:   layers.LinkTypeNull,
  1469  						SnapLength: 0,
  1470  						Name:       "null1",
  1471  						Statistics: NgInterfaceStatistics{
  1472  							LastUpdate:      time.Unix(0, 0x4c39764ca47aa*1000).UTC(),
  1473  							PacketsDropped:  NgNoValue64,
  1474  							PacketsReceived: NgNoValue64,
  1475  						},
  1476  					},
  1477  				},
  1478  			},
  1479  			{
  1480  				sectionInfo: NgSectionInfo{
  1481  					Hardware:    "Apple MBP",
  1482  					OS:          "OS-X 10.10.5",
  1483  					Application: "pcap_writer.lua",
  1484  					Comment:     "test201 SHB-1",
  1485  				},
  1486  				ifaces: []NgInterface{
  1487  					{
  1488  						LinkType:   layers.LinkTypeEthernet,
  1489  						SnapLength: 128,
  1490  						Name:       "silly ethernet interface 2",
  1491  						Statistics: NgInterfaceStatistics{
  1492  							LastUpdate:      time.Unix(0, 0x4c39764ca47aa*1000+1000*1000).UTC(),
  1493  							StartTime:       time.Unix(0, 0x4c39764ca47aa*1000).UTC(),
  1494  							EndTime:         time.Unix(0, 0x4c39764ca47aa*1000+1000*1000).UTC(),
  1495  							PacketsDropped:  10,
  1496  							PacketsReceived: NgNoValue64,
  1497  							Comment:         "test201 ISB-2",
  1498  						},
  1499  					},
  1500  				},
  1501  			},
  1502  			{
  1503  				sectionInfo: NgSectionInfo{
  1504  					Hardware:    "Apple MBP",
  1505  					OS:          "OS-X 10.10.5",
  1506  					Application: "pcap_writer.lua",
  1507  					Comment:     "test201 SHB-2",
  1508  				},
  1509  				ifaces: []NgInterface{
  1510  					{
  1511  						LinkType:   layers.LinkTypeEthernet,
  1512  						SnapLength: 96,
  1513  						Name:       "eth0",
  1514  						Statistics: NgInterfaceStatistics{
  1515  							LastUpdate:      time.Unix(0, 0).UTC(),
  1516  							PacketsDropped:  NgNoValue64,
  1517  							PacketsReceived: NgNoValue64,
  1518  						},
  1519  					},
  1520  					{
  1521  						LinkType:   layers.LinkTypeNull,
  1522  						SnapLength: 0,
  1523  						Name:       "null1",
  1524  					},
  1525  				},
  1526  			},
  1527  		},
  1528  		packets: []ngFileReadTestPacket{
  1529  			{
  1530  				data: ngPacketSource[0][:96],
  1531  				ci: gopacket.CaptureInfo{
  1532  					Timestamp:      time.Unix(0, 0x4c39764ca47aa*1000).UTC(),
  1533  					Length:         len(ngPacketSource[0]),
  1534  					CaptureLength:  96,
  1535  					InterfaceIndex: 0,
  1536  				},
  1537  			},
  1538  			{
  1539  				data: ngPacketSource[1][:128],
  1540  				ci: gopacket.CaptureInfo{
  1541  					Timestamp:      time.Unix(0, 0x4c39764ca47aa*1000).UTC(),
  1542  					Length:         len(ngPacketSource[1]),
  1543  					CaptureLength:  128,
  1544  					InterfaceIndex: 0,
  1545  				},
  1546  			},
  1547  			{
  1548  				data: ngPacketSource[2][:128],
  1549  				ci: gopacket.CaptureInfo{
  1550  					Timestamp:      time.Time{},
  1551  					Length:         len(ngPacketSource[2]),
  1552  					CaptureLength:  128,
  1553  					InterfaceIndex: 0,
  1554  				},
  1555  			},
  1556  		},
  1557  	},
  1558  	{
  1559  		testName: "test202",
  1560  		linkType: layers.LinkTypeEthernet,
  1561  		sections: []ngFileReadTestSection{
  1562  			{
  1563  				sectionInfo: NgSectionInfo{
  1564  					Hardware:    "Apple MBP",
  1565  					OS:          "OS-X 10.10.5",
  1566  					Application: "pcap_writer.lua",
  1567  					Comment:     "test202 SHB-0",
  1568  				},
  1569  				ifaces: []NgInterface{
  1570  					{
  1571  						LinkType:   layers.LinkTypeEthernet,
  1572  						SnapLength: 96,
  1573  						Name:       "eth0",
  1574  					},
  1575  					{
  1576  						LinkType:   layers.LinkTypeNull,
  1577  						SnapLength: 0,
  1578  						Name:       "null1",
  1579  						Statistics: NgInterfaceStatistics{
  1580  							LastUpdate:      time.Unix(0, 0x4c39764ca47aa*1000).UTC(),
  1581  							PacketsDropped:  NgNoValue64,
  1582  							PacketsReceived: NgNoValue64,
  1583  						},
  1584  					},
  1585  				},
  1586  			},
  1587  			{
  1588  				sectionInfo: NgSectionInfo{
  1589  					Hardware:    "Apple MBP",
  1590  					OS:          "OS-X 10.10.5",
  1591  					Application: "pcap_writer.lua",
  1592  					Comment:     "test202 SHB-1",
  1593  				},
  1594  				ifaces: []NgInterface{
  1595  					{
  1596  						LinkType:   layers.LinkTypeEthernet,
  1597  						SnapLength: 128,
  1598  						Name:       "silly ethernet interface 2",
  1599  						Statistics: NgInterfaceStatistics{
  1600  							LastUpdate:      time.Unix(0, 0x4c39764ca47aa*1000+1000*1000).UTC(),
  1601  							StartTime:       time.Unix(0, 0x4c39764ca47aa*1000).UTC(),
  1602  							EndTime:         time.Unix(0, 0x4c39764ca47aa*1000+1000*1000).UTC(),
  1603  							PacketsDropped:  10,
  1604  							PacketsReceived: NgNoValue64,
  1605  							Comment:         "test202 ISB-2",
  1606  						},
  1607  					},
  1608  				},
  1609  			},
  1610  			{
  1611  				sectionInfo: NgSectionInfo{
  1612  					Hardware:    "Apple MBP",
  1613  					OS:          "OS-X 10.10.5",
  1614  					Application: "pcap_writer.lua",
  1615  					Comment:     "test202 SHB-2",
  1616  				},
  1617  				ifaces: []NgInterface{
  1618  					{
  1619  						LinkType:   layers.LinkTypeEthernet,
  1620  						SnapLength: 96,
  1621  						Name:       "eth0",
  1622  						Statistics: NgInterfaceStatistics{
  1623  							LastUpdate:      time.Unix(0, 0).UTC(),
  1624  							StartTime:       time.Unix(0, 0x4c39764ca47aa*1000).UTC(),
  1625  							EndTime:         time.Unix(0, 0x4c39764ca47aa*1000+1000*1000).UTC(),
  1626  							PacketsReceived: 100,
  1627  							PacketsDropped:  1,
  1628  							Comment:         "test202 ISB-0",
  1629  						},
  1630  					},
  1631  					{
  1632  						LinkType:   layers.LinkTypeNull,
  1633  						SnapLength: 0,
  1634  						Name:       "null1",
  1635  					},
  1636  				},
  1637  			},
  1638  		},
  1639  		packets: []ngFileReadTestPacket{
  1640  			{
  1641  				data: ngPacketSource[0][:96],
  1642  				ci: gopacket.CaptureInfo{
  1643  					Timestamp:      time.Unix(0, 0x4c39764ca47aa*1000).UTC(),
  1644  					Length:         len(ngPacketSource[0]),
  1645  					CaptureLength:  96,
  1646  					InterfaceIndex: 0,
  1647  				},
  1648  			},
  1649  			{
  1650  				data: ngPacketSource[1][:96],
  1651  				ci: gopacket.CaptureInfo{
  1652  					Timestamp:      time.Unix(0, 0x4c39764ca47aa*1000).UTC(),
  1653  					Length:         len(ngPacketSource[1]),
  1654  					CaptureLength:  96,
  1655  					InterfaceIndex: 0,
  1656  				},
  1657  			},
  1658  			{
  1659  				data: ngPacketSource[0][:128],
  1660  				ci: gopacket.CaptureInfo{
  1661  					Timestamp:      time.Time{},
  1662  					Length:         len(ngPacketSource[0]),
  1663  					CaptureLength:  128,
  1664  					InterfaceIndex: 0,
  1665  				},
  1666  			},
  1667  			{
  1668  				data: ngPacketSource[1][:128],
  1669  				ci: gopacket.CaptureInfo{
  1670  					Timestamp:      time.Unix(0, 0x4c39764ca47aa*1000).UTC(),
  1671  					Length:         len(ngPacketSource[1]),
  1672  					CaptureLength:  128,
  1673  					InterfaceIndex: 0,
  1674  				},
  1675  			},
  1676  			{
  1677  				data: ngPacketSource[2][:128],
  1678  				ci: gopacket.CaptureInfo{
  1679  					Timestamp:      time.Time{},
  1680  					Length:         len(ngPacketSource[2]),
  1681  					CaptureLength:  128,
  1682  					InterfaceIndex: 0,
  1683  				},
  1684  			},
  1685  			{
  1686  				data: ngPacketSource[3][:128],
  1687  				ci: gopacket.CaptureInfo{
  1688  					Timestamp:      time.Unix(0, 0x4c39764ca47aa*1000).UTC(),
  1689  					Length:         len(ngPacketSource[3]),
  1690  					CaptureLength:  128,
  1691  					InterfaceIndex: 0,
  1692  				},
  1693  			},
  1694  		},
  1695  	},
  1696  	{
  1697  		testName: "test901",
  1698  		linkType: layers.LinkTypeEthernet,
  1699  		sections: []ngFileReadTestSection{
  1700  			{
  1701  				sectionInfo: NgSectionInfo{
  1702  					Hardware:    "my computer",
  1703  					OS:          "linux",
  1704  					Application: "pcap_writer.lua",
  1705  					Comment:     "test901 SHB-0",
  1706  				},
  1707  				ifaces: []NgInterface{
  1708  					{
  1709  						LinkType:   layers.LinkTypeEthernet,
  1710  						SnapLength: 0,
  1711  						Name:       "eth0",
  1712  					},
  1713  				},
  1714  			},
  1715  		},
  1716  		packets: []ngFileReadTestPacket{
  1717  			{
  1718  				data: ngPacketSource[0],
  1719  				ci: gopacket.CaptureInfo{
  1720  					Timestamp:      time.Unix(0, 0x4c39764ca47aa*1000).UTC(),
  1721  					Length:         len(ngPacketSource[0]),
  1722  					CaptureLength:  len(ngPacketSource[0]),
  1723  					InterfaceIndex: 0,
  1724  				},
  1725  			},
  1726  			{err: ErrNgVersionMismatch},
  1727  		},
  1728  	},
  1729  	{
  1730  		testName:           "test901",
  1731  		skipUnknownVersion: true,
  1732  		linkType:           layers.LinkTypeEthernet,
  1733  		sections: []ngFileReadTestSection{
  1734  			{
  1735  				sectionInfo: NgSectionInfo{
  1736  					Hardware:    "my computer",
  1737  					OS:          "linux",
  1738  					Application: "pcap_writer.lua",
  1739  					Comment:     "test901 SHB-0",
  1740  				},
  1741  				ifaces: []NgInterface{
  1742  					{
  1743  						LinkType:   layers.LinkTypeEthernet,
  1744  						SnapLength: 0,
  1745  						Name:       "eth0",
  1746  					},
  1747  				},
  1748  			},
  1749  			{
  1750  				sectionInfo: NgSectionInfo{
  1751  					Hardware:    "my computer",
  1752  					OS:          "linux",
  1753  					Application: "pcap_writer.lua",
  1754  					Comment:     "test901 SHB-2",
  1755  				},
  1756  				ifaces: []NgInterface{
  1757  					{
  1758  						LinkType:   layers.LinkTypeEthernet,
  1759  						SnapLength: 0,
  1760  						Name:       "eth0",
  1761  					},
  1762  				},
  1763  			},
  1764  		},
  1765  		packets: []ngFileReadTestPacket{
  1766  			{
  1767  				data: ngPacketSource[0],
  1768  				ci: gopacket.CaptureInfo{
  1769  					Timestamp:      time.Unix(0, 0x4c39764ca47aa*1000).UTC(),
  1770  					Length:         len(ngPacketSource[0]),
  1771  					CaptureLength:  len(ngPacketSource[0]),
  1772  					InterfaceIndex: 0,
  1773  				},
  1774  			},
  1775  			{
  1776  				data: ngPacketSource[2],
  1777  				ci: gopacket.CaptureInfo{
  1778  					Timestamp:      time.Unix(0, 0x4c39764ca47aa*1000).UTC(),
  1779  					Length:         len(ngPacketSource[2]),
  1780  					CaptureLength:  len(ngPacketSource[2]),
  1781  					InterfaceIndex: 0,
  1782  				},
  1783  			},
  1784  		},
  1785  	},
  1786  	{
  1787  		testName: "test902",
  1788  		linkType: layers.LinkTypeEthernet,
  1789  		sections: []ngFileReadTestSection{
  1790  			{
  1791  				sectionInfo: NgSectionInfo{
  1792  					Hardware:    "my computer",
  1793  					OS:          "linux",
  1794  					Application: "pcap_writer.lua",
  1795  					Comment:     "test902",
  1796  				},
  1797  				ifaces: []NgInterface{
  1798  					{
  1799  						LinkType:            layers.LinkTypeEthernet,
  1800  						SnapLength:          0,
  1801  						Name:                "eth0",
  1802  						TimestampResolution: 0x88,
  1803  					},
  1804  				},
  1805  			},
  1806  		},
  1807  		packets: []ngFileReadTestPacket{
  1808  			{
  1809  				data: ngPacketSource[0],
  1810  				ci: gopacket.CaptureInfo{
  1811  					Timestamp:      time.Unix(1519128000, 195312500).UTC(),
  1812  					Length:         len(ngPacketSource[0]),
  1813  					CaptureLength:  len(ngPacketSource[0]),
  1814  					InterfaceIndex: 0,
  1815  				},
  1816  			},
  1817  		},
  1818  	},
  1819  }
  1820  
  1821  func TestNgFileReadBE(t *testing.T) {
  1822  	for _, test := range tests {
  1823  		ngRunFileReadTest(test, "be", false, t)
  1824  	}
  1825  }
  1826  
  1827  func TestNgFileReadLE(t *testing.T) {
  1828  	for _, test := range tests {
  1829  		ngRunFileReadTest(test, "le", false, t)
  1830  	}
  1831  }
  1832  
  1833  func TestNgFileReadBEZero(t *testing.T) {
  1834  	for _, test := range tests {
  1835  		ngRunFileReadTest(test, "be", true, t)
  1836  	}
  1837  }
  1838  
  1839  func TestNgFileReadLEZero(t *testing.T) {
  1840  	for _, test := range tests {
  1841  		ngRunFileReadTest(test, "le", true, t)
  1842  	}
  1843  }
  1844  
  1845  type endlessNgPacketReader struct {
  1846  	packet []byte
  1847  }
  1848  
  1849  func (e endlessNgPacketReader) Read(p []byte) (n int, err error) {
  1850  	n = copy(p, e.packet)
  1851  	return
  1852  }
  1853  
  1854  func setupNgReadBenchmark(b *testing.B) *NgReader {
  1855  	header := bytes.NewBuffer([]byte{
  1856  		0x0A, 0x0D, 0x0D, 0x0A, // Section Header
  1857  		0, 0, 0, 28, // block total length
  1858  		0x1A, 0x2B, 0x3C, 0x4D, // BOM
  1859  		0, 1, 0, 0, //Version
  1860  		0, 0, 0, 0, //Section length
  1861  		0, 0, 0, 0, //Section length
  1862  		0, 0, 0, 28, //block total length
  1863  
  1864  		0, 0, 0, 1, // IDB
  1865  		0, 0, 0, 20, // block total length
  1866  		0, 1, 0, 0, // Ethernet
  1867  		0, 0, 0, 0, // Snap length
  1868  		0, 0, 0, 20, // block total length
  1869  	})
  1870  
  1871  	packet := endlessNgPacketReader{
  1872  		[]byte{
  1873  			0, 0, 0, 6, // EPB
  1874  			0, 0, 0, 48, // block total length
  1875  			0, 0, 0, 0, // interface ID
  1876  			0, 0, 0, 0, // time (high)
  1877  			0, 0, 0, 0, // time (low)
  1878  			0, 0, 0, 16, // capture packet length
  1879  			0, 0, 0, 16, // original packet length
  1880  			1, 2, 3, 4,
  1881  			5, 6, 7, 8,
  1882  			9, 10, 11, 12,
  1883  			13, 14, 15, 16,
  1884  			0, 0, 0, 48, // block total length
  1885  			0, 0, 0, 6, // EPB
  1886  			0, 0, 0, 40, // block total length
  1887  			0, 0, 0, 0, // interface ID
  1888  			0, 0, 0, 0, // time (high)
  1889  			0, 0, 0, 0, // time (low)
  1890  			0, 0, 0, 8, // capture packet length
  1891  			0, 0, 0, 8, // original packet length
  1892  			8, 7, 6, 5,
  1893  			4, 3, 2, 1,
  1894  			0, 0, 0, 40, // block total length
  1895  		},
  1896  	}
  1897  	packetReader := bufio.NewReaderSize(packet, len(packet.packet))
  1898  
  1899  	r, err := NewNgReader(header, DefaultNgReaderOptions)
  1900  
  1901  	if err != nil {
  1902  		b.Fatal("Couldn't read header + IDB:", err)
  1903  	}
  1904  	r.r = packetReader
  1905  	return r
  1906  }
  1907  
  1908  func BenchmarkNgReadPacketData(b *testing.B) {
  1909  	r := setupNgReadBenchmark(b)
  1910  	b.ResetTimer()
  1911  	for i := 0; i < b.N; i++ {
  1912  		_, _, _ = r.ReadPacketData()
  1913  	}
  1914  }
  1915  
  1916  func BenchmarkNgZeroCopyReadPacketData(b *testing.B) {
  1917  	r := setupNgReadBenchmark(b)
  1918  	b.ResetTimer()
  1919  	for i := 0; i < b.N; i++ {
  1920  		_, _, _ = r.ZeroCopyReadPacketData()
  1921  	}
  1922  }