github.com/gopacket/gopacket@v1.1.0/layers/dns_test.go (about)

     1  // Copyright 2012, 2018 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 layers
     8  
     9  import (
    10  	"bytes"
    11  	"net"
    12  	"strings"
    13  	"testing"
    14  
    15  	"github.com/gopacket/gopacket"
    16  )
    17  
    18  func FuzzDecodeFromBytes(f *testing.F) {
    19  	f.Fuzz(func(t *testing.T, bytes []byte) {
    20  		dns := DNS{}
    21  		dns.DecodeFromBytes(bytes, gopacket.NilDecodeFeedback)
    22  	})
    23  }
    24  
    25  // it have a layer like that:
    26  //
    27  //	name: xxx.com
    28  //	type: CNAME
    29  //	class: 254 (QCLASS None)   # [RFC 2136]
    30  //	ttl: 0
    31  //	data-length: 0
    32  //	data: nil
    33  var testPacketDNSNilRdata = []byte{
    34  	0x96, 0x99, 0x28, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x03, 0x00, 0x00, 0x02, 0x6a, 0x79, 0x09,
    35  	0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x03, 0x63, 0x6f, 0x6d, 0x00, 0x00, 0x06,
    36  	0x00, 0x01, 0x0c, 0x50, 0x46, 0x32, 0x45, 0x41, 0x5a, 0x43, 0x4c, 0x2d, 0x42, 0x49, 0x5a, 0x02,
    37  	0x6a, 0x79, 0x09, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x03, 0x63, 0x6f, 0x6d,
    38  	0x00, 0x00, 0x05, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x22, 0x00, 0x1c, 0x00,
    39  	0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x22, 0x00, 0x01, 0x00, 0xff, 0x00, 0x00, 0x00,
    40  	0x00, 0x00, 0x00, 0xc0, 0x22, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x04, 0xb0, 0x00, 0x04, 0x0a,
    41  	0x54, 0x4e, 0xf1,
    42  }
    43  
    44  func TestPacketDNSNilRdata(t *testing.T) {
    45  	p := gopacket.NewPacket(testPacketDNSNilRdata, LayerTypeDNS, testDecodeOptions)
    46  	if p.ErrorLayer() != nil {
    47  		t.Error("Failed to decode packet:", p.ErrorLayer().Error())
    48  	}
    49  	checkLayers(p, []gopacket.LayerType{LayerTypeDNS}, t)
    50  }
    51  
    52  // testPacketDNSRegression is the packet:
    53  //
    54  //	11:08:05.708342 IP 109.194.160.4.57766 > 95.211.92.14.53: 63000% [1au] A? picslife.ru. (40)
    55  //	   0x0000:  0022 19b6 7e22 000f 35bb 0b40 0800 4500  ."..~"..5..@..E.
    56  //	   0x0010:  0044 89c4 0000 3811 2f3d 6dc2 a004 5fd3  .D....8./=m..._.
    57  //	   0x0020:  5c0e e1a6 0035 0030 a597 f618 0010 0001  \....5.0........
    58  //	   0x0030:  0000 0000 0001 0870 6963 736c 6966 6502  .......picslife.
    59  //	   0x0040:  7275 0000 0100 0100 0029 1000 0000 8000  ru.......)......
    60  //	   0x0050:  0000                                     ..
    61  var testPacketDNSRegression = []byte{
    62  	0x00, 0x22, 0x19, 0xb6, 0x7e, 0x22, 0x00, 0x0f, 0x35, 0xbb, 0x0b, 0x40, 0x08, 0x00, 0x45, 0x00,
    63  	0x00, 0x44, 0x89, 0xc4, 0x00, 0x00, 0x38, 0x11, 0x2f, 0x3d, 0x6d, 0xc2, 0xa0, 0x04, 0x5f, 0xd3,
    64  	0x5c, 0x0e, 0xe1, 0xa6, 0x00, 0x35, 0x00, 0x30, 0xa5, 0x97, 0xf6, 0x18, 0x00, 0x10, 0x00, 0x01,
    65  	0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x08, 0x70, 0x69, 0x63, 0x73, 0x6c, 0x69, 0x66, 0x65, 0x02,
    66  	0x72, 0x75, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x29, 0x10, 0x00, 0x00, 0x00, 0x80, 0x00,
    67  	0x00, 0x00,
    68  }
    69  
    70  func TestPacketDNSRegression(t *testing.T) {
    71  	p := gopacket.NewPacket(testPacketDNSRegression, LinkTypeEthernet, testDecodeOptions)
    72  	if p.ErrorLayer() != nil {
    73  		t.Error("Failed to decode packet:", p.ErrorLayer().Error())
    74  	}
    75  	checkLayers(p, []gopacket.LayerType{LayerTypeEthernet, LayerTypeIPv4, LayerTypeUDP, LayerTypeDNS}, t)
    76  }
    77  func BenchmarkDecodePacketDNSRegression(b *testing.B) {
    78  	for i := 0; i < b.N; i++ {
    79  		gopacket.NewPacket(testPacketDNSRegression, LinkTypeEthernet, gopacket.NoCopy)
    80  	}
    81  }
    82  
    83  // response to `dig TXT google.com` over IPv4 link:
    84  var testParseDNSTypeTXTValue = `v=spf1 include:_spf.google.com ~all`
    85  var testParseDNSTypeTXT = []byte{
    86  	0x02, 0x00, 0x00, 0x00, // PF_INET
    87  	0x45, 0x00, 0x00, 0x73, 0x00, 0x00, 0x40, 0x00, 0x39, 0x11, 0x64, 0x98, 0xd0, 0x43, 0xde, 0xde,
    88  	0x0a, 0xba, 0x23, 0x06, 0x00, 0x35, 0x81, 0xb2, 0x00, 0x5f, 0xdc, 0xb5, 0x98, 0x71, 0x81, 0x80,
    89  	0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x06, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x03,
    90  	0x63, 0x6f, 0x6d, 0x00, 0x00, 0x10, 0x00, 0x01, 0xc0, 0x0c, 0x00, 0x10, 0x00, 0x01, 0x00, 0x00,
    91  	0x0e, 0x10, 0x00, 0x24, 0x23, 0x76, 0x3d, 0x73, 0x70, 0x66, 0x31, 0x20, 0x69, 0x6e, 0x63, 0x6c,
    92  	0x75, 0x64, 0x65, 0x3a, 0x5f, 0x73, 0x70, 0x66, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e,
    93  	0x63, 0x6f, 0x6d, 0x20, 0x7e, 0x61, 0x6c, 0x6c, 0x00, 0x00, 0x29, 0x10, 0x00, 0x00, 0x00, 0x00,
    94  	0x00, 0x00, 0x00,
    95  }
    96  
    97  func TestParseDNSTypeTXT(t *testing.T) {
    98  	p := gopacket.NewPacket(testParseDNSTypeTXT, LinkTypeNull, testDecodeOptions)
    99  	if p.ErrorLayer() != nil {
   100  		t.Error("Failed to decode packet:", p.ErrorLayer().Error())
   101  	}
   102  	checkLayers(p, []gopacket.LayerType{LayerTypeLoopback, LayerTypeIPv4, LayerTypeUDP, LayerTypeDNS}, t)
   103  	answers := p.Layer(LayerTypeDNS).(*DNS).Answers
   104  	if len(answers) != 1 {
   105  		t.Error("Failed to parse 1 DNS answer")
   106  	}
   107  	if len(answers[0].TXTs) != 1 {
   108  		t.Error("Failed to parse 1 TXT record")
   109  	}
   110  	txt := string(answers[0].TXTs[0])
   111  	if txt != testParseDNSTypeTXTValue {
   112  		t.Errorf("Incorrect TXT value, expected %q, got %q", testParseDNSTypeTXTValue, txt)
   113  	}
   114  }
   115  
   116  var testParseDNSBadVers = []byte{
   117  	0x02, 0x00, 0x00, 0x00, // PF_INET
   118  	0x45, 0x00, 0x00, 0x38, 0xa5, 0xa0, 0x40, 0x00, 0x38, 0x11, 0x00, 0xbd, 0xc0, 0x05, 0x05, 0xf1,
   119  	0xac, 0x1e, 0x2a, 0x43, 0x00, 0x35, 0xfd, 0x78, 0x00, 0x24, 0x40, 0xc1, 0x8f, 0xb3, 0x81, 0x00,
   120  	0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x10, 0x00, 0x01, 0x00, 0x00, 0x29,
   121  	0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
   122  }
   123  var testParseDNSBadVersResponseCode = DNSResponseCodeBadVers
   124  
   125  func TestParseDNSBadVers(t *testing.T) {
   126  	p := gopacket.NewPacket(testParseDNSBadVers, LinkTypeNull, testDecodeOptions)
   127  	if p.ErrorLayer() != nil {
   128  		t.Error("Failed to decode packet:", p.ErrorLayer().Error())
   129  	}
   130  	checkLayers(p, []gopacket.LayerType{LayerTypeLoopback, LayerTypeIPv4, LayerTypeUDP, LayerTypeDNS}, t)
   131  	questions := p.Layer(LayerTypeDNS).(*DNS).Questions
   132  	if len(questions) != 1 {
   133  		t.Error("Failed to parse 1 DNS question")
   134  	}
   135  	answers := p.Layer(LayerTypeDNS).(*DNS).Answers
   136  	if len(answers) != 0 {
   137  		t.Error("Failed to parse 0 DNS answer")
   138  	}
   139  	additionals := p.Layer(LayerTypeDNS).(*DNS).Additionals
   140  	if len(additionals) != 1 {
   141  		t.Error("Failed to parse 1 DNS additional")
   142  	}
   143  
   144  	optAll := additionals[0].OPT
   145  	if len(optAll) != 0 {
   146  		t.Errorf("Parsed %d OPTs, expected 0", len(optAll))
   147  	}
   148  	responseCode := p.Layer(LayerTypeDNS).(*DNS).ResponseCode
   149  	if responseCode != testParseDNSBadVersResponseCode {
   150  		t.Errorf("Incorrect extended response code, expected %q, got %q", testParseDNSBadVersResponseCode, responseCode)
   151  	}
   152  }
   153  
   154  var testParseDNSBadCookie = []byte{
   155  	0x02, 0x00, 0x00, 0x00, // PF_INET
   156  	0x45, 0x00, 0x00, 0x54, 0xfe, 0xaa, 0x00, 0x00, 0x40, 0x11, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x01,
   157  	0x7f, 0x00, 0x00, 0x01, 0x00, 0x35, 0xd6, 0xaa, 0x00, 0x40, 0xfe, 0x53, 0xf6, 0xab, 0x81, 0x87,
   158  	0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, 0x29,
   159  	0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x0a, 0x00, 0x18, 0x36, 0xbf, 0x11, 0x1f,
   160  	0xef, 0x2e, 0x01, 0x09, 0x7d, 0x8f, 0xfe, 0x06, 0x5c, 0x63, 0x6f, 0xfb, 0x14, 0x2d, 0x76, 0x74,
   161  	0x94, 0x40, 0x7a, 0x73,
   162  }
   163  var testParseDNSBadCookieResponseCode = DNSResponseCodeBadCookie
   164  
   165  func TestParseDNSBadCookie(t *testing.T) {
   166  	p := gopacket.NewPacket(testParseDNSBadCookie, LinkTypeNull, testDecodeOptions)
   167  	if p.ErrorLayer() != nil {
   168  		t.Error("Failed to decode packet:", p.ErrorLayer().Error())
   169  	}
   170  	checkLayers(p, []gopacket.LayerType{LayerTypeLoopback, LayerTypeIPv4, LayerTypeUDP, LayerTypeDNS}, t)
   171  	questions := p.Layer(LayerTypeDNS).(*DNS).Questions
   172  	if len(questions) != 1 {
   173  		t.Error("Failed to parse 1 DNS question")
   174  	}
   175  	answers := p.Layer(LayerTypeDNS).(*DNS).Answers
   176  	if len(answers) != 0 {
   177  		t.Error("Failed to parse 0 DNS answer")
   178  	}
   179  	additionals := p.Layer(LayerTypeDNS).(*DNS).Additionals
   180  	if len(additionals) != 1 {
   181  		t.Error("Failed to parse 1 DNS additional")
   182  	}
   183  
   184  	optAll := additionals[0].OPT
   185  	if len(optAll) != 1 {
   186  		t.Errorf("Parsed %d OPTs, expected 1", len(optAll))
   187  	}
   188  	responseCode := p.Layer(LayerTypeDNS).(*DNS).ResponseCode
   189  	if responseCode != testParseDNSBadCookieResponseCode {
   190  		t.Errorf("Incorrect extended response code, expected %q, got %q", testParseDNSBadCookieResponseCode, responseCode)
   191  	}
   192  }
   193  
   194  var testParseDNSTypeURI = []byte{
   195  	0x02, 0x00, 0x00, 0x00, // PF_INET
   196  	0x45, 0x00, 0x00, 0x6f, 0x3e, 0x65, 0x00, 0x00, 0x40, 0x11, 0x3e, 0x17, 0x7f, 0x00, 0x00, 0x01,
   197  	0x7f, 0x00, 0x00, 0x01, 0x00, 0x35, 0xe7, 0xd3, 0x00, 0x5b, 0xfe, 0x6e, 0xaf, 0x2d, 0x85, 0x80,
   198  	0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x05, 0x5f, 0x68, 0x74, 0x74, 0x70, 0x03, 0x64,
   199  	0x6e, 0x73, 0x04, 0x74, 0x65, 0x73, 0x74, 0x00, 0x01, 0x00, 0x00, 0x01, 0xc0, 0x0c, 0x01, 0x00,
   200  	0x00, 0x01, 0x00, 0x00, 0x2a, 0x30, 0x00, 0x1c, 0x00, 0x0a, 0x00, 0x05, 0x68, 0x74, 0x74, 0x70,
   201  	0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x64, 0x6e, 0x73, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x3a,
   202  	0x38, 0x30, 0x30, 0x30, 0x00, 0x00, 0x29, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   203  }
   204  var testParseDNSTypeURITarget = "http://www.dns.test:8000"
   205  var testParseDNSTypeURIPriority = uint16(10)
   206  var testParseDNSTypeURIWeight = uint16(5)
   207  
   208  func TestParseDNSTypeURI(t *testing.T) {
   209  	p := gopacket.NewPacket(testParseDNSTypeURI, LinkTypeNull, testDecodeOptions)
   210  	if p.ErrorLayer() != nil {
   211  		t.Error("Failed to decode packet:", p.ErrorLayer().Error())
   212  	}
   213  	checkLayers(p, []gopacket.LayerType{LayerTypeLoopback, LayerTypeIPv4, LayerTypeUDP, LayerTypeDNS}, t)
   214  	answers := p.Layer(LayerTypeDNS).(*DNS).Answers
   215  	if len(answers) != 1 {
   216  		t.Error("Failed to parse 1 DNS answer")
   217  	}
   218  	if len(answers[0].URI.Target) < 1 {
   219  		t.Error("Failed to parse 1 URI record")
   220  	}
   221  	target := string(answers[0].URI.Target)
   222  	if target != testParseDNSTypeURITarget {
   223  		t.Errorf("Incorrect URI target value, expected %q, got %q", testParseDNSTypeURITarget, target)
   224  	}
   225  	priority := answers[0].URI.Priority
   226  	if priority != testParseDNSTypeURIPriority {
   227  		t.Errorf("Incorrect URI priority value, expected %q, got %q", testParseDNSTypeURIPriority, priority)
   228  	}
   229  	weight := answers[0].URI.Weight
   230  	if weight != testParseDNSTypeURIWeight {
   231  		t.Errorf("Incorrect URI weight value, expected %q, got %q", testParseDNSTypeURIWeight, weight)
   232  	}
   233  }
   234  
   235  var testParseDNSTypeOPT = []byte{
   236  	0x00, 0x90, 0x0b, 0x12, 0x91, 0xc1, 0x00, 0x1c, 0xc0, 0x93, 0x33, 0xfb, 0x08, 0x00, 0x45, 0x00,
   237  	0x00, 0x5A, 0xce, 0x58, 0x00, 0x00, 0x40, 0x11, 0x67, 0xe2, 0xac, 0x10, 0x01, 0xc7, 0x4b, 0x4b,
   238  	0x4b, 0x4b, 0xd6, 0x00, 0x00, 0x35, 0x00, 0x46, 0x44, 0xb0, 0x50, 0x12, 0x01, 0x00, 0x00, 0x01,
   239  	0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x77, 0x77, 0x77, 0x04, 0x69, 0x65, 0x74, 0x66, 0x03,
   240  	0x6f, 0x72, 0x67, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x29, 0x10, 0x00, 0x00, 0x00, 0x80,
   241  	0x00, 0x00, 0x13, 0x69, 0x42, 0x00, 0x0F, 0x4F, 0x70, 0x65, 0x6E, 0x44, 0x4E, 0x53, 0x01, 0x23,
   242  	0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
   243  }
   244  
   245  func TestParseDNSTypeOPT(t *testing.T) {
   246  	p := gopacket.NewPacket(testParseDNSTypeOPT, LinkTypeEthernet, testDecodeOptions)
   247  
   248  	if p.ErrorLayer() != nil {
   249  		t.Error("Failed to decode packet:", p.ErrorLayer().Error())
   250  	}
   251  	checkLayers(p, []gopacket.LayerType{LayerTypeEthernet, LayerTypeIPv4, LayerTypeUDP, LayerTypeDNS}, t)
   252  	questions := p.Layer(LayerTypeDNS).(*DNS).Questions
   253  	if len(questions) != 1 {
   254  		t.Error("Failed to parse 1 DNS question")
   255  	}
   256  	additionals := p.Layer(LayerTypeDNS).(*DNS).Additionals
   257  	if len(additionals) != 1 {
   258  		t.Error("Failed to parse 1 DNS additional")
   259  	}
   260  
   261  	optAll := additionals[0].OPT
   262  	if len(optAll) != 1 {
   263  		t.Errorf("Parsed %d OPTs, expected 1", len(optAll))
   264  	}
   265  
   266  	if additionals[0].OPT[0].Code != DNSOptionCodeDeviceID {
   267  		t.Error("Failed to parse the OPT Code")
   268  	}
   269  	if string(additionals[0].OPT[0].Data[:7]) != "OpenDNS" {
   270  		t.Error("Failed to parse the Data Part 1")
   271  	}
   272  	if !bytes.Equal(additionals[0].OPT[0].Data[7:], []byte{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}) {
   273  		t.Error("Failed to parse the Data Part 2")
   274  	}
   275  }
   276  
   277  func testQuestionEqual(t *testing.T, i int, exp, got DNSQuestion) {
   278  	if !bytes.Equal(exp.Name, got.Name) {
   279  		t.Errorf("expected Questions[%d].Name = %v, got %v", i, string(exp.Name), string(got.Name))
   280  	}
   281  	if exp.Type != got.Type {
   282  		t.Errorf("expected Questions[%d].Type = %v, got %v", i, exp.Type, got.Type)
   283  	}
   284  	if exp.Class != got.Class {
   285  		t.Errorf("expected Questions[%d].Class = %v, got %v", i, exp.Class, got.Class)
   286  	}
   287  }
   288  
   289  func testResourceEqual(t *testing.T, i int, name string, exp, got DNSResourceRecord) {
   290  	if !bytes.Equal(exp.Name, got.Name) {
   291  		t.Errorf("expected %s[%d].Name = %v, got %v", name, i, string(exp.Name), string(got.Name))
   292  	}
   293  
   294  	if exp.Type != got.Type {
   295  		t.Errorf("expected %s[%d].Type = %v, got %v", name, i, exp.Type, got.Type)
   296  	}
   297  
   298  	if exp.Class != got.Class {
   299  		t.Errorf("expected %s[%d].Class = %v, got %v", name, i, exp.Class, got.Class)
   300  	}
   301  
   302  	if exp.TTL != got.TTL {
   303  		t.Errorf("expected %s[%d].TTL = %v, got %v", name, i, exp.TTL, got.TTL)
   304  	}
   305  	if exp.DataLength != got.DataLength {
   306  		t.Errorf("expected %s[%d].DataLength = %v, got %v", name, i, exp.DataLength, got.DataLength)
   307  	}
   308  
   309  	// we don't check .Data
   310  
   311  	if !exp.IP.Equal(got.IP) {
   312  		t.Errorf("expected %s[%d].IP = %v, got %v", name, i, exp.IP, got.IP)
   313  	}
   314  	if !bytes.Equal(exp.NS, got.NS) {
   315  		t.Errorf("expected %s[%d].NS = %v, got %v", name, i, exp.NS, got.NS)
   316  	}
   317  	if !bytes.Equal(exp.CNAME, got.CNAME) {
   318  		t.Errorf("expected %s[%d].CNAME = %v, got %v", name, i, exp.CNAME, got.CNAME)
   319  	}
   320  	if !bytes.Equal(exp.PTR, got.PTR) {
   321  		t.Errorf("expected %s[%d].PTR = %v, got %v", name, i, exp.PTR, got.PTR)
   322  	}
   323  	if len(exp.TXTs) != len(got.TXTs) {
   324  		t.Errorf("expected %s[%d].TXTs = %v, got %v", name, i, exp.TXTs, got.TXTs)
   325  	}
   326  	for j := range exp.TXTs {
   327  		if !bytes.Equal(exp.TXTs[j], got.TXTs[j]) {
   328  			t.Errorf("expected %s[%d].TXTs[%d] = %v, got %v", name, i, j, exp.TXTs[j], got.TXTs[j])
   329  		}
   330  	}
   331  
   332  	// SOA
   333  	if !bytes.Equal(exp.SOA.MName, got.SOA.MName) {
   334  		t.Errorf("expected %s[%d].SOA.MName = %v, got %v", name, i, exp.SOA.MName, got.SOA.MName)
   335  	}
   336  	if !bytes.Equal(exp.SOA.RName, got.SOA.RName) {
   337  		t.Errorf("expected %s[%d].SOA.RName = %v, got %v", name, i, exp.SOA.RName, got.SOA.RName)
   338  	}
   339  	if exp.SOA.Serial != got.SOA.Serial {
   340  		t.Errorf("expected %s[%d].SOA.Serial = %v, got %v", name, i, exp.SOA.Serial, got.SOA.Serial)
   341  	}
   342  	if exp.SOA.Refresh != got.SOA.Refresh {
   343  		t.Errorf("expected %s[%d].SOA.Refresh = %v, got %v", name, i, exp.SOA.Refresh, got.SOA.Refresh)
   344  	}
   345  	if exp.SOA.Retry != got.SOA.Retry {
   346  		t.Errorf("expected %s[%d].SOA.Retry = %v, got %v", name, i, exp.SOA.Retry, got.SOA.Retry)
   347  	}
   348  	if exp.SOA.Expire != got.SOA.Expire {
   349  		t.Errorf("expected %s[%d].SOA.Expire = %v, got %v", name, i, exp.SOA.Expire, got.SOA.Expire)
   350  	}
   351  	if exp.SOA.Minimum != got.SOA.Minimum {
   352  		t.Errorf("expected %s[%d].SOA.Minimum = %v, got %v", name, i, exp.SOA.Minimum, got.SOA.Minimum)
   353  	}
   354  
   355  	// SRV
   356  	if !bytes.Equal(exp.SRV.Name, got.SRV.Name) {
   357  		t.Errorf("expected %s[%d].SRV.Name = %v, got %v", name, i, exp.SRV.Name, got.SRV.Name)
   358  	}
   359  	if exp.SRV.Weight != got.SRV.Weight {
   360  		t.Errorf("expected %s[%d].SRV.Weight = %v, got %v", name, i, exp.SRV.Weight, got.SRV.Weight)
   361  	}
   362  	if exp.SRV.Port != got.SRV.Port {
   363  		t.Errorf("expected %s[%d].SRV.Port = %v, got %v", name, i, exp.SRV.Port, got.SRV.Port)
   364  	}
   365  	// MX
   366  	if !bytes.Equal(exp.MX.Name, got.MX.Name) {
   367  		t.Errorf("expected %s[%d].MX.Name = %v, got %v", name, i, exp.MX.Name, got.MX.Name)
   368  	}
   369  	if exp.MX.Preference != got.MX.Preference {
   370  		t.Errorf("expected %s[%d].MX.Preference = %v, got %v", name, i, exp.MX.Preference, got.MX.Preference)
   371  	}
   372  	// URI
   373  	if !bytes.Equal(exp.URI.Target, got.URI.Target) {
   374  		t.Errorf("expected %s[%d].URI.Target = %v, got %v", name, i, exp.URI.Target, got.URI.Target)
   375  	}
   376  	if exp.URI.Weight != got.URI.Weight {
   377  		t.Errorf("expected %s[%d].URI.Weight = %v, got %v", name, i, exp.URI.Weight, got.URI.Weight)
   378  	}
   379  	if exp.URI.Priority != got.URI.Priority {
   380  		t.Errorf("expected %s[%d].URI.Priority = %v, got %v", name, i, exp.URI.Priority, got.URI.Priority)
   381  	}
   382  
   383  	// OPT
   384  	if len(exp.OPT) != len(got.OPT) {
   385  		t.Errorf("expected len(%s[%d].OPT) = %v, got %v", name, i, len(exp.OPT), len(got.OPT))
   386  	}
   387  
   388  	for j := range exp.OPT {
   389  		if exp.OPT[j].Code != got.OPT[j].Code {
   390  			t.Errorf("expected %s[%d].OPT[%d].Code = %v, got %v", name, i, j, exp.OPT[j].Code, got.OPT[j].Code)
   391  		}
   392  		if !bytes.Equal(exp.OPT[j].Data, got.OPT[j].Data) {
   393  			t.Errorf("expected %s[%d].OPT[%d].Data = %v, got %v", name, i, j, exp.OPT[j].Data, got.OPT[j].Data)
   394  		}
   395  	}
   396  }
   397  
   398  func testDNSEqual(t *testing.T, exp, got *DNS) {
   399  	if exp.ID != got.ID {
   400  		t.Errorf("expected ID = %v, got %v", exp.ID, got.ID)
   401  	}
   402  	if exp.AA != got.AA {
   403  		t.Errorf("expected AA = %v, got %v", exp.AA, got.AA)
   404  	}
   405  	if exp.OpCode != got.OpCode {
   406  		t.Errorf("expected OpCode = %v, got %v", exp.OpCode, got.OpCode)
   407  	}
   408  	if exp.AA != got.AA {
   409  		t.Errorf("expected AA = %v, got %v", exp.AA, got.AA)
   410  	}
   411  	if exp.TC != got.TC {
   412  		t.Errorf("expected TC = %v, got %v", exp.TC, got.TC)
   413  	}
   414  	if exp.RD != got.RD {
   415  		t.Errorf("expected RD = %v, got %v", exp.RD, got.RD)
   416  	}
   417  	if exp.RA != got.RA {
   418  		t.Errorf("expected RA = %v, got %v", exp.RA, got.RA)
   419  	}
   420  	if exp.Z != got.Z {
   421  		t.Errorf("expected Z = %v, got %v", exp.Z, got.Z)
   422  	}
   423  	if exp.ResponseCode != got.ResponseCode {
   424  		t.Errorf("expected ResponseCode = %v, got %v", exp.ResponseCode, got.ResponseCode)
   425  	}
   426  	if exp.QDCount != got.QDCount {
   427  		t.Errorf("expected QDCount = %v, got %v", exp.QDCount, got.QDCount)
   428  	}
   429  	if exp.ANCount != got.ANCount {
   430  		t.Errorf("expected ANCount = %v, got %v", exp.ANCount, got.ANCount)
   431  	}
   432  	if exp.ANCount != got.ANCount {
   433  		t.Errorf("expected ANCount = %v, got %v", exp.ANCount, got.ANCount)
   434  	}
   435  	if exp.NSCount != got.NSCount {
   436  		t.Errorf("expected NSCount = %v, got %v", exp.NSCount, got.NSCount)
   437  	}
   438  	if exp.ARCount != got.ARCount {
   439  		t.Errorf("expected ARCount = %v, got %v", exp.ARCount, got.ARCount)
   440  	}
   441  
   442  	if len(exp.Questions) != len(got.Questions) {
   443  		t.Errorf("expected %d Questions, got %d", len(exp.Questions), len(got.Questions))
   444  	}
   445  	for i := range exp.Questions {
   446  		testQuestionEqual(t, i, exp.Questions[i], got.Questions[i])
   447  	}
   448  
   449  	if len(exp.Answers) != len(got.Answers) {
   450  		t.Errorf("expected %d Answers, got %d", len(exp.Answers), len(got.Answers))
   451  	}
   452  	for i := range exp.Answers {
   453  		testResourceEqual(t, i, "Answers", exp.Answers[i], got.Answers[i])
   454  	}
   455  
   456  	if len(exp.Authorities) != len(got.Authorities) {
   457  		t.Errorf("expected %d Answers, got %d", len(exp.Authorities), len(got.Authorities))
   458  	}
   459  	for i := range exp.Authorities {
   460  		testResourceEqual(t, i, "Authorities", exp.Authorities[i], got.Authorities[i])
   461  	}
   462  
   463  	if len(exp.Additionals) != len(got.Additionals) {
   464  		t.Errorf("expected %d Additionals, got %d", len(exp.Additionals), len(got.Additionals))
   465  	}
   466  	for i := range exp.Additionals {
   467  		testResourceEqual(t, i, "Additionals", exp.Additionals[i], got.Additionals[i])
   468  	}
   469  }
   470  
   471  func TestDNSEncodeQuery(t *testing.T) {
   472  	dns := &DNS{ID: 1234, OpCode: DNSOpCodeQuery, RD: true}
   473  	dns.Questions = append(dns.Questions,
   474  		DNSQuestion{
   475  			Name:  []byte("example1.com"),
   476  			Type:  DNSTypeA,
   477  			Class: DNSClassIN,
   478  		})
   479  
   480  	dns.Questions = append(dns.Questions,
   481  		DNSQuestion{
   482  			Name:  []byte("example2.com"),
   483  			Type:  DNSTypeA,
   484  			Class: DNSClassIN,
   485  		})
   486  
   487  	buf := gopacket.NewSerializeBuffer()
   488  	opts := gopacket.SerializeOptions{FixLengths: true}
   489  	err := gopacket.SerializeLayers(buf, opts, dns)
   490  	if err != nil {
   491  		t.Fatal(err)
   492  	}
   493  	if int(dns.QDCount) != len(dns.Questions) {
   494  		t.Errorf("fix lengths did not adjust QDCount, expected %d got %d", len(dns.Questions), dns.QDCount)
   495  	}
   496  
   497  	p2 := gopacket.NewPacket(buf.Bytes(), LayerTypeDNS, testDecodeOptions)
   498  	dns2 := p2.Layer(LayerTypeDNS).(*DNS)
   499  	testDNSEqual(t, dns, dns2)
   500  }
   501  
   502  func TestDNSEncodeQueryWithOPT(t *testing.T) {
   503  	dns := &DNS{ID: 1234, OpCode: DNSOpCodeQuery, RD: true}
   504  	dns.Questions = append(dns.Questions,
   505  		DNSQuestion{
   506  			Name:  []byte("example1.com"),
   507  			Type:  DNSTypeA,
   508  			Class: DNSClassIN,
   509  		})
   510  
   511  	dns.Questions = append(dns.Questions,
   512  		DNSQuestion{
   513  			Name:  []byte("example2.com"),
   514  			Type:  DNSTypeA,
   515  			Class: DNSClassIN,
   516  		})
   517  	dns.Additionals = append(dns.Additionals,
   518  		DNSResourceRecord{
   519  			Type:  DNSTypeOPT,
   520  			Class: 4096,
   521  			OPT: []DNSOPT{
   522  				DNSOPT{
   523  					Code: DNSOptionCodeDeviceID,
   524  					Data: []byte("OpenDNS"),
   525  				},
   526  			},
   527  		})
   528  
   529  	buf := gopacket.NewSerializeBuffer()
   530  	opts := gopacket.SerializeOptions{FixLengths: true}
   531  	err := gopacket.SerializeLayers(buf, opts, dns)
   532  	if err != nil {
   533  		t.Fatal(err)
   534  	}
   535  	if int(dns.QDCount) != len(dns.Questions) {
   536  		t.Errorf("fix lengths did not adjust QDCount, expected %d got %d", len(dns.Questions), dns.QDCount)
   537  	}
   538  	if int(dns.ARCount) != len(dns.Additionals) {
   539  		t.Errorf("fix lengths did not adjust ARCount, expected %d got %d", len(dns.Additionals), dns.ARCount)
   540  	}
   541  
   542  	p2 := gopacket.NewPacket(buf.Bytes(), LayerTypeDNS, testDecodeOptions)
   543  	dns2 := p2.Layer(LayerTypeDNS).(*DNS)
   544  	testDNSEqual(t, dns, dns2)
   545  }
   546  
   547  func TestDNSEncodeResponse(t *testing.T) {
   548  	dns := &DNS{ID: 1234, QR: true, OpCode: DNSOpCodeQuery,
   549  		AA: true, RD: true, RA: true}
   550  	dns.Questions = append(dns.Questions,
   551  		DNSQuestion{
   552  			Name:  []byte("example1.com"),
   553  			Type:  DNSTypeA,
   554  			Class: DNSClassIN,
   555  		})
   556  	dns.Questions = append(dns.Questions,
   557  		DNSQuestion{
   558  			Name:  []byte("www.example2.com"),
   559  			Type:  DNSTypeAAAA,
   560  			Class: DNSClassIN,
   561  		})
   562  
   563  	dns.Answers = append(dns.Answers,
   564  		DNSResourceRecord{
   565  			Name:  []byte("example1.com"),
   566  			Type:  DNSTypeA,
   567  			Class: DNSClassIN,
   568  			TTL:   1024,
   569  			IP:    net.IP([]byte{1, 2, 3, 4}),
   570  		})
   571  
   572  	dns.Answers = append(dns.Answers,
   573  		DNSResourceRecord{
   574  			Name:  []byte("example1.com"),
   575  			Type:  DNSTypeURI,
   576  			Class: DNSClassIN,
   577  			TTL:   1024,
   578  			URI: DNSURI{
   579  				Target:   []byte("http://www.example2.com/"),
   580  				Priority: 10240,
   581  				Weight:   1,
   582  			},
   583  		})
   584  
   585  	dns.Answers = append(dns.Answers,
   586  		DNSResourceRecord{
   587  			Name:  []byte("www.example2.com"),
   588  			Type:  DNSTypeAAAA,
   589  			Class: DNSClassIN,
   590  			TTL:   1024,
   591  			IP:    net.IP([]byte{5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4}),
   592  		})
   593  
   594  	dns.Answers = append(dns.Answers,
   595  		DNSResourceRecord{
   596  			Name:  []byte("www.example2.com"),
   597  			Type:  DNSTypeCNAME,
   598  			Class: DNSClassIN,
   599  			TTL:   1024,
   600  			CNAME: []byte("example2.com"),
   601  		})
   602  
   603  	buf := gopacket.NewSerializeBuffer()
   604  	opts := gopacket.SerializeOptions{FixLengths: true}
   605  	err := gopacket.SerializeLayers(buf, opts, dns)
   606  	if err != nil {
   607  		t.Fatal(err)
   608  	}
   609  	if int(dns.ANCount) != len(dns.Answers) {
   610  		t.Errorf("fix lengths did not adjust ANCount, expected %d got %d", len(dns.Answers), dns.ANCount)
   611  	}
   612  	for i, a := range dns.Answers {
   613  		if a.DataLength == 0 {
   614  			t.Errorf("fix lengths did not adjust Answers[%d].DataLength", i)
   615  		}
   616  	}
   617  
   618  	p2 := gopacket.NewPacket(buf.Bytes(), LayerTypeDNS, testDecodeOptions)
   619  	dns2 := p2.Layer(LayerTypeDNS).(*DNS)
   620  	testDNSEqual(t, dns, dns2)
   621  }
   622  
   623  // testDNSMalformedPacket is the packet:
   624  //
   625  //	10:30:00.389666 IP 10.77.43.131.60718 > 10.1.0.17.53: 18245 updateD [b2&3=0x5420] [18516a] [12064q] [21584n] [12081au][|domain]
   626  //		0x0000:  0000 0101 0000 4e96 1476 afa1 0800 4500  ......N..v....E.
   627  //		0x0010:  0039 d431 0000 f311 b3a0 0a4d 2b83 0a01  .9.1.......M+...
   628  //		0x0020:  0011 ed2e 0035 0025 0832 4745 5420 2f20  .....5.%.2GET./.
   629  //		0x0030:  4854 5450 2f31 2e31 0d0a 486f 7374 3a20  HTTP/1.1..Host:.
   630  //		0x0040:  7777 770d 0a0d 0a                        www....
   631  var testDNSMalformedPacket = []byte{
   632  	0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x4e, 0x96, 0x14, 0x76, 0xaf, 0xa1, 0x08, 0x00, 0x45, 0x00,
   633  	0x00, 0x39, 0xd4, 0x31, 0x00, 0x00, 0xf3, 0x11, 0xb3, 0xa0, 0x0a, 0x4d, 0x2b, 0x83, 0x0a, 0x01,
   634  	0x00, 0x11, 0xed, 0x2e, 0x00, 0x35, 0x00, 0x25, 0x08, 0x32, 0x47, 0x45, 0x54, 0x20, 0x2f, 0x20,
   635  	0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x31, 0x0d, 0x0a, 0x48, 0x6f, 0x73, 0x74, 0x3a, 0x20,
   636  	0x77, 0x77, 0x77, 0x0d, 0x0a, 0x0d, 0x0a,
   637  }
   638  
   639  func TestDNSMalformedPacket(t *testing.T) {
   640  	p := gopacket.NewPacket(testDNSMalformedPacket, LinkTypeEthernet, testDecodeOptions)
   641  	if errLayer := p.ErrorLayer(); errLayer == nil {
   642  		t.Error("No error layer on invalid DNS name")
   643  	} else if err := errLayer.Error(); !strings.Contains(err.Error(), "invalid index") {
   644  		t.Errorf("unexpected error message: %v", err)
   645  	}
   646  }
   647  
   648  // testDNSMalformedPacket2 is the packet:
   649  //
   650  //	15:14:42.056054 IP 10.77.0.245.53 > 10.1.0.45.38769: 12625 zoneInit YXRRSet- [49833q],[|domain]
   651  //		0x0000:  0055 22af c637 0022 55ac deac 0800 4500  .U"..7."U.....E.
   652  //		0x0010:  0079 3767 4000 3911 f49d 0a4d 00f5 0a01  .y7g@.9....M....
   653  //		0x0020:  002d 0035 9771 0065 6377 3151 f057 c2a9  .-.5.q.ecw1Q.W..
   654  //		0x0030:  fc6e e86a beb0 f7d4 8599 373e b5f8 9db2  .n.j......7>....
   655  //		0x0040:  a399 21a1 9762 def1 def4 f5ab 5675 023e  ..!..b......Vu.>
   656  //		0x0050:  c9ca 304f 178a c2ad f2fc 677a 0e4c b892  ..0O......gz.L..
   657  //		0x0060:  ab71 09bb 1ea4 f7c4 fe47 7a39 868b 29a0  .q.......Gz9..).
   658  //		0x0070:  62c4 d184 5b4e 8817 4cc0 d1d0 d430 11d3  b...[N..L....0..
   659  //		0x0080:  d147 543f afc7 1a                        .GT?...
   660  var testDNSMalformedPacket2 = []byte{
   661  	0x00, 0x55, 0x22, 0xaf, 0xc6, 0x37, 0x00, 0x22, 0x55, 0xac, 0xde, 0xac, 0x08, 0x00, 0x45, 0x00,
   662  	0x00, 0x79, 0x37, 0x67, 0x40, 0x00, 0x39, 0x11, 0xf4, 0x9d, 0x0a, 0x4d, 0x00, 0xf5, 0x0a, 0x01,
   663  	0x00, 0x2d, 0x00, 0x35, 0x97, 0x71, 0x00, 0x65, 0x63, 0x77, 0x31, 0x51, 0xf0, 0x57, 0xc2, 0xa9,
   664  	0xfc, 0x6e, 0xe8, 0x6a, 0xbe, 0xb0, 0xf7, 0xd4, 0x85, 0x99, 0x37, 0x3e, 0xb5, 0xf8, 0x9d, 0xb2,
   665  	0xa3, 0x99, 0x21, 0xa1, 0x97, 0x62, 0xde, 0xf1, 0xde, 0xf4, 0xf5, 0xab, 0x56, 0x75, 0x02, 0x3e,
   666  	0xc9, 0xca, 0x30, 0x4f, 0x17, 0x8a, 0xc2, 0xad, 0xf2, 0xfc, 0x67, 0x7a, 0x0e, 0x4c, 0xb8, 0x92,
   667  	0xab, 0x71, 0x09, 0xbb, 0x1e, 0xa4, 0xf7, 0xc4, 0xfe, 0x47, 0x7a, 0x39, 0x86, 0x8b, 0x29, 0xa0,
   668  	0x62, 0xc4, 0xd1, 0x84, 0x5b, 0x4e, 0x88, 0x17, 0x4c, 0xc0, 0xd1, 0xd0, 0xd4, 0x30, 0x11, 0xd3,
   669  	0xd1, 0x47, 0x54, 0x3f, 0xaf, 0xc7, 0x1a,
   670  }
   671  
   672  func TestDNSMalformedPacket2(t *testing.T) {
   673  	p := gopacket.NewPacket(testDNSMalformedPacket2, LinkTypeEthernet, testDecodeOptions)
   674  	if errLayer := p.ErrorLayer(); errLayer == nil {
   675  		t.Error("No error layer on invalid DNS name")
   676  	} else if err := errLayer.Error(); !strings.Contains(err.Error(), "offset pointer too high") {
   677  		t.Errorf("unexpected error message: %v", err)
   678  	}
   679  }
   680  
   681  // testBlankNameRootQuery is the packet:
   682  //
   683  //	08:31:18.143065 IP 10.77.0.26.53 > 10.1.0.233.65071: 59508- 0/13/3 (508)
   684  //		0x0000:  0055 22af c637 0022 55ac deac 0800 4500  .U"..7."U.....E.
   685  //		0x0010:  0218 76b2 4000 7211 7ad2 0a4d 001a 0a01  ..v.@.r.z..M....
   686  //		0x0020:  00e9 0035 fe2f 0204 b8f5 e874 8100 0001  ...5./.....t....
   687  //		0x0030:  0000 000d 0003 0c61 786b 7663 6863 7063  .......axkvchcpc
   688  //		0x0040:  7073 6c0a 7878 7878 7878 7878 7878 036e  psl.xxxxxxxxxx.n
   689  //		0x0050:  6574 0000 0100 0100 0002 0001 0000 0e10  et..............
   690  //		0x0060:  0014 016d 0c72 6f6f 742d 7365 7276 6572  ...m.root-server
   691  //		0x0070:  7303 6e65 7400 c02d 0002 0001 0000 0e10  s.net..-........
   692  //		0x0080:  0014 0161 0c72 6f6f 742d 7365 7276 6572  ...a.root-server
   693  //		0x0090:  7303 6e65 7400 c02d 0002 0001 0000 0e10  s.net..-........
   694  //		0x00a0:  0014 0169 0c72 6f6f 742d 7365 7276 6572  ...i.root-server
   695  //		0x00b0:  7303 6e65 7400 c02d 0002 0001 0000 0e10  s.net..-........
   696  //		0x00c0:  0014 0162 0c72 6f6f 742d 7365 7276 6572  ...b.root-server
   697  //		0x00d0:  7303 6e65 7400 c02d 0002 0001 0000 0e10  s.net..-........
   698  //		0x00e0:  0014 016c 0c72 6f6f 742d 7365 7276 6572  ...l.root-server
   699  //		0x00f0:  7303 6e65 7400 c02d 0002 0001 0000 0e10  s.net..-........
   700  //		0x0100:  0014 0166 0c72 6f6f 742d 7365 7276 6572  ...f.root-server
   701  //		0x0110:  7303 6e65 7400 c02d 0002 0001 0000 0e10  s.net..-........
   702  //		0x0120:  0014 0167 0c72 6f6f 742d 7365 7276 6572  ...g.root-server
   703  //		0x0130:  7303 6e65 7400 c02d 0002 0001 0000 0e10  s.net..-........
   704  //		0x0140:  0014 0164 0c72 6f6f 742d 7365 7276 6572  ...d.root-server
   705  //		0x0150:  7303 6e65 7400 c02d 0002 0001 0000 0e10  s.net..-........
   706  //		0x0160:  0014 0168 0c72 6f6f 742d 7365 7276 6572  ...h.root-server
   707  //		0x0170:  7303 6e65 7400 c02d 0002 0001 0000 0e10  s.net..-........
   708  //		0x0180:  0014 0165 0c72 6f6f 742d 7365 7276 6572  ...e.root-server
   709  //		0x0190:  7303 6e65 7400 c02d 0002 0001 0000 0e10  s.net..-........
   710  //		0x01a0:  0014 016a 0c72 6f6f 742d 7365 7276 6572  ...j.root-server
   711  //		0x01b0:  7303 6e65 7400 c02d 0002 0001 0000 0e10  s.net..-........
   712  //		0x01c0:  0014 016b 0c72 6f6f 742d 7365 7276 6572  ...k.root-server
   713  //		0x01d0:  7303 6e65 7400 c02d 0002 0001 0000 0e10  s.net..-........
   714  //		0x01e0:  0014 0163 0c72 6f6f 742d 7365 7276 6572  ...c.root-server
   715  //		0x01f0:  7303 6e65 7400 c038 0001 0001 0000 0e10  s.net..8........
   716  //		0x0200:  0004 ca0c 1b21 c058 0001 0001 0000 0e10  .....!.X........
   717  //		0x0210:  0004 c629 0004 c078 0001 0001 0000 0e10  ...)...x........
   718  //		0x0220:  0004 c024 9411                           ...$..
   719  var testBlankNameRootQuery = []byte{
   720  	0x00, 0x55, 0x22, 0xaf, 0xc6, 0x37, 0x00, 0x22, 0x55, 0xac, 0xde, 0xac, 0x08, 0x00, 0x45, 0x00,
   721  	0x02, 0x18, 0x76, 0xb2, 0x40, 0x00, 0x72, 0x11, 0x7a, 0xd2, 0x0a, 0x4d, 0x00, 0x1a, 0x0a, 0x01,
   722  	0x00, 0xe9, 0x00, 0x35, 0xfe, 0x2f, 0x02, 0x04, 0xb8, 0xf5, 0xe8, 0x74, 0x81, 0x00, 0x00, 0x01,
   723  	0x00, 0x00, 0x00, 0x0d, 0x00, 0x03, 0x0c, 0x61, 0x78, 0x6b, 0x76, 0x63, 0x68, 0x63, 0x70, 0x63,
   724  	0x70, 0x73, 0x6c, 0x0a, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x03, 0x6e,
   725  	0x65, 0x74, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x0e, 0x10,
   726  	0x00, 0x14, 0x01, 0x6d, 0x0c, 0x72, 0x6f, 0x6f, 0x74, 0x2d, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72,
   727  	0x73, 0x03, 0x6e, 0x65, 0x74, 0x00, 0xc0, 0x2d, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x0e, 0x10,
   728  	0x00, 0x14, 0x01, 0x61, 0x0c, 0x72, 0x6f, 0x6f, 0x74, 0x2d, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72,
   729  	0x73, 0x03, 0x6e, 0x65, 0x74, 0x00, 0xc0, 0x2d, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x0e, 0x10,
   730  	0x00, 0x14, 0x01, 0x69, 0x0c, 0x72, 0x6f, 0x6f, 0x74, 0x2d, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72,
   731  	0x73, 0x03, 0x6e, 0x65, 0x74, 0x00, 0xc0, 0x2d, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x0e, 0x10,
   732  	0x00, 0x14, 0x01, 0x62, 0x0c, 0x72, 0x6f, 0x6f, 0x74, 0x2d, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72,
   733  	0x73, 0x03, 0x6e, 0x65, 0x74, 0x00, 0xc0, 0x2d, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x0e, 0x10,
   734  	0x00, 0x14, 0x01, 0x6c, 0x0c, 0x72, 0x6f, 0x6f, 0x74, 0x2d, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72,
   735  	0x73, 0x03, 0x6e, 0x65, 0x74, 0x00, 0xc0, 0x2d, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x0e, 0x10,
   736  	0x00, 0x14, 0x01, 0x66, 0x0c, 0x72, 0x6f, 0x6f, 0x74, 0x2d, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72,
   737  	0x73, 0x03, 0x6e, 0x65, 0x74, 0x00, 0xc0, 0x2d, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x0e, 0x10,
   738  	0x00, 0x14, 0x01, 0x67, 0x0c, 0x72, 0x6f, 0x6f, 0x74, 0x2d, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72,
   739  	0x73, 0x03, 0x6e, 0x65, 0x74, 0x00, 0xc0, 0x2d, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x0e, 0x10,
   740  	0x00, 0x14, 0x01, 0x64, 0x0c, 0x72, 0x6f, 0x6f, 0x74, 0x2d, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72,
   741  	0x73, 0x03, 0x6e, 0x65, 0x74, 0x00, 0xc0, 0x2d, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x0e, 0x10,
   742  	0x00, 0x14, 0x01, 0x68, 0x0c, 0x72, 0x6f, 0x6f, 0x74, 0x2d, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72,
   743  	0x73, 0x03, 0x6e, 0x65, 0x74, 0x00, 0xc0, 0x2d, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x0e, 0x10,
   744  	0x00, 0x14, 0x01, 0x65, 0x0c, 0x72, 0x6f, 0x6f, 0x74, 0x2d, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72,
   745  	0x73, 0x03, 0x6e, 0x65, 0x74, 0x00, 0xc0, 0x2d, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x0e, 0x10,
   746  	0x00, 0x14, 0x01, 0x6a, 0x0c, 0x72, 0x6f, 0x6f, 0x74, 0x2d, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72,
   747  	0x73, 0x03, 0x6e, 0x65, 0x74, 0x00, 0xc0, 0x2d, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x0e, 0x10,
   748  	0x00, 0x14, 0x01, 0x6b, 0x0c, 0x72, 0x6f, 0x6f, 0x74, 0x2d, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72,
   749  	0x73, 0x03, 0x6e, 0x65, 0x74, 0x00, 0xc0, 0x2d, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x0e, 0x10,
   750  	0x00, 0x14, 0x01, 0x63, 0x0c, 0x72, 0x6f, 0x6f, 0x74, 0x2d, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72,
   751  	0x73, 0x03, 0x6e, 0x65, 0x74, 0x00, 0xc0, 0x38, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x0e, 0x10,
   752  	0x00, 0x04, 0xca, 0x0c, 0x1b, 0x21, 0xc0, 0x58, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x0e, 0x10,
   753  	0x00, 0x04, 0xc6, 0x29, 0x00, 0x04, 0xc0, 0x78, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x0e, 0x10,
   754  	0x00, 0x04, 0xc0, 0x24, 0x94, 0x11,
   755  }
   756  
   757  func TestBlankNameRootQuery(t *testing.T) {
   758  	p := gopacket.NewPacket(testBlankNameRootQuery, LinkTypeEthernet, testDecodeOptions)
   759  	if err := p.ErrorLayer(); err != nil {
   760  		t.Error("Error layer on blank DNS name field:", err)
   761  	}
   762  }
   763  
   764  // testAnotherMalformedDNS is the packet:
   765  //
   766  //	10:52:13.690904 IP 10.77.0.29.53 > 10.1.0.6.42280: 13491 op6+% [b2&3=0x3313] [11720a] [23583q] [29742n] [52087au] Type22277 (Class 43688)? M- M-<.VM-^KM-wQM-s"M-^E^]M-+^Wx^P^@M-^\^\M-oM-FM-U^F^E7M-tM-^VM-^[M-F^H>G^FM-uM-^KM-_6GM-[M-jM-bM-^H]hM-^J.[|domain]
   767  //		0x0000:  0055 22af c637 0022 55ac deac 0800 4500  .U"..7."U.....E.
   768  //		0x0010:  05c1 2eea 4000 3611 fbd1 0a4d 001d 0a01  ....@.6....M....
   769  //		0x0020:  0006 0035 a528 05ad 00a2 34b3 3313 5c1f  ...5.(....4.3.\.
   770  //		0x0030:  2dc8 742e cb77 2da0 bc2e 568b f751 f322  -.t..w-...V..Q."
   771  //		0x0040:  851d ab17 7810 009c 1cef c6d5 0605 37f4  ....x.........7.
   772  //		0x0050:  969b c65e 483e 4706 f58b df36 47db eae2  ...^H>G....6G...
   773  //		0x0060:  885d 688a c5a5 5705 aaa8 95eb 93a4 d85a  .]h...W........Z
   774  //		0x0070:  c9af 261f 7816 a354 2d23 d84a 579c 4876  ..&.x..T-#.JW.Hv
   775  //		0x0080:  a391 43db 5c41 191a 92b8 dcdd 6839 eef5  ..C.\A......h9..
   776  //		0x0090:  728e 13e0 0679 6f47 88a0 25b9 44d8 f8e7  r....yoG..%.D...
   777  //		0x00a0:  8afe 0bfa f811 8da5 f8a3 1f8e d23b fe12  .............;..
   778  //		0x00b0:  d943 9327 92ad 4410 183e 688d b06d 5391  .C.'..D..>h..mS.
   779  //		0x00c0:  695b e49f 8f1e c075 d043 afe0 1174 9db0  i[.....u.C...t..
   780  //		0x00d0:  06b0 f01e b85b 3c84 945e 06d0 b20f 9eaa  .....[<..^......
   781  //		0x00e0:  123d 0ab0 2a55 309c 0ee9 3e5e db2f f377  .=..*U0...>^./.w
   782  //		0x00f0:  d7f1 9bae 373d 3316 0796 b80e dd18 5173  ....7=3.......Qs
   783  //		0x0100:  b28d 84fd 1812 d87b 42c8 5f11 4db6 b269  .......{B._.M..i
   784  //		0x0110:  1c42 4aea d5a4 644b 6c00 f0c0 fcee 71a7  .BJ...dKl.....q.
   785  //		0x0120:  e7f0 719c a207 dc5c a6fa f005 a338 7ff0  ..q....\.....8..
   786  //		0x0130:  5beb 3b4d 8952 2a46 d47b a5a2 e1fb 9e76  [.;M.R*F.{.....v
   787  //		0x0140:  c815 6258 50f4 6997 bad5 b479 2d06 ebbb  ..bXP.i....y-...
   788  //		0x0150:  2cac 2ecc e4f0 1f94 ce9f 186c 61da 9681  ,..........la...
   789  //		0x0160:  345c 4d88 efc7 037b fbe3 4402 ea06 2e5d  4\M....{..D....]
   790  //		0x0170:  2e6e 4860 e180 3ef7 c006 0ad1 ebb9 c4ff  .nH`..>.........
   791  //		0x0180:  dee2 f21c 02c2 751a ded8 ae2e 13a9 3fa2  ......u.......?.
   792  //		0x0190:  392a 8b54 11b2 2b4e 2bf1 4780 db9f 8c10  9*.T..+N+.G.....
   793  //		0x01a0:  ac6f 61b0 7b19 423f 07e5 4628 b870 f75d  .oa.{.B?..F(.p.]
   794  //		0x01b0:  09a3 63b2 77af 5985 a0ae 51d8 243f a7c8  ..c.w.Y...Q.$?..
   795  //		0x01c0:  ab08 7fc6 0217 c09f c412 0c45 e6aa 96bf  ...........E....
   796  //		0x01d0:  184c 4307 1f1f c4f4 7734 da31 2088 662b  .LC.....w4.1..f+
   797  //		0x01e0:  44c5 096f 1d1d 2dc5 ffd6 867d 9fc5 7b45  D..o..-....}..{E
   798  //		0x01f0:  f949 7dd9 38de 0d51 ac2a 32fc f50b 1bbe  .I}.8..Q.*2.....
   799  //		0x0200:  1c4b 5441 fbf3 0821 6c28 4530 5676 1d27  .KTA...!l(E0Vv.'
   800  //		0x0210:  5087 466c 3d5b 45a6 af7f 917a 6d43 66c2  P.Fl=[E....zmCf.
   801  //		0x0220:  036a 8bef ca60 9b13 8d29 9fda 82fa 01b1  .j...`...)......
   802  //		0x0230:  df8f 1f83 c71d 630f 349e 508c 9f7a e3da  ......c.4.P..z..
   803  //		0x0240:  a114 3622 9df8 9926 4dac 4150 d505 7b3a  ..6"...&M.AP..{:
   804  //		0x0250:  6fed fc75 6b4f 2d60 8a89 767d 9af0 896e  o..ukO-`..v}...n
   805  //		0x0260:  907d 1ada def3 345c 0d81 283c a24f fcbb  .}....4\..(<.O..
   806  //		0x0270:  bbdd b7b3 e3bb 9f1b d966 51b7 8217 7fa0  .........fQ.....
   807  //		0x0280:  e828 d3ca a6f1 532f 164e e405 bb3b 0de3  .(....S/.N...;..
   808  //		0x0290:  985d 6e89 d825 ebc6 d8ba 5190 a114 c6a3  .]n..%....Q.....
   809  //		0x02a0:  18b4 8aa7 181a 01ac cdc0 8048 ea72 a5e3  ...........H.r..
   810  //		0x02b0:  e37a dc57 65cd b787 39e6 c39e 317b 45d8  .z.We...9...1{E.
   811  //		0x02c0:  475c 05ba e8f8 8224 5a85 27b8 1584 8d78  G\.....$Z.'....x
   812  //		0x02d0:  62b6 6495 ac10 338f 1122 f2ff 043e 9e2a  b.d...3.."...>.*
   813  //		0x02e0:  1058 a910 5792 6fcd 9a96 6183 6708 8f70  .X..W.o...a.g..p
   814  //		0x02f0:  edc6 a67c 64ff 50fa 520b de94 c82c c4d6  ...|d.P.R....,..
   815  //		0x0300:  7d8f 0fd5 2f0d 9833 7c6c be10 a4e5 dc99  }.../..3|l......
   816  //		0x0310:  a467 ef5f b35b c11c e23c 131a 48b2 9cef  .g._.[...<..H...
   817  //		0x0320:  5a2f fece dd9e 2aea 0db9 faf3 a6ef b29d  Z/....*.........
   818  //		0x0330:  e85d a410 dd6a 6806 3fc6 1694 179f cb4b  .]...jh.?......K
   819  //		0x0340:  08c4 86b2 0713 cddb b257 d56b fe82 7d82  .........W.k..}.
   820  //		0x0350:  0d1f 6dc9 67b2 d2a1 6791 4f38 edf9 491f  ..m.g...g.O8..I.
   821  //		0x0360:  2c02 35f5 8165 ecc3 bc6a b631 3c7e 1ad4  ,.5..e...j.1<~..
   822  //		0x0370:  8e27 f962 f942 11b5 1b45 9bac b474 3c6e  .'.b.B...E...t<n
   823  //		0x0380:  6832 3075 be6d ac0d a8a0 7d47 a6ef 4e43  h20u.m....}G..NC
   824  //		0x0390:  6b9a 3097 8a8b 82a3 9515 362c f7d6 a37f  k.0.......6,....
   825  //		0x03a0:  7313 1199 a5f3 03dc bcc9 fb10 c23d eeb9  s............=..
   826  //		0x03b0:  78ff c8f3 0d38 9f74 ceec b7ae 63e3 3424  x....8.t....c.4$
   827  //		0x03c0:  b783 f106 011f 666b bf2d abc8 ea10 57a1  ......fk.-....W.
   828  //		0x03d0:  7cf2 4a3f 57ca 1386 bfba 27e5 4662 81c8  |.J?W.....'.Fb..
   829  //		0x03e0:  041e 1820 b3d5 c399 cd4d 222f 29f0 b994  .........M"/)...
   830  //		0x03f0:  865a e6e2 1686 3261 b0cd caaf 07ec d0bc  .Z....2a........
   831  //		0x0400:  afb8 3cf0 51c1 6c7a 6383 6b3a ff47 9551  ..<.Q.lzc.k:.G.Q
   832  //		0x0410:  1099 525f 355e 4684 bd34 ec12 88c9 dcc2  ..R_5^F..4......
   833  //		0x0420:  d11c 826d f1df 37e6 f08f 6ce8 817d bdc3  ...m..7...l..}..
   834  //		0x0430:  20b9 a274 c645 c67d f299 fef9 287f 09ee  ...t.E.}....(...
   835  //		0x0440:  ac67 6872 a126 b1d3 922c 4c2a 0ec9 b6d4  .ghr.&...,L*....
   836  //		0x0450:  fb59 6163 d1c4 1708 8d94 bc3d be5e ae29  .Yac.......=.^.)
   837  //		0x0460:  51ff a765 9df6 ae35 ed6b 0555 933f 3ed6  Q..e...5.k.U.?>.
   838  //		0x0470:  259b d93e f86f 6088 0c4e 357b 5c67 7d93  %..>.o`..N5{\g}.
   839  //		0x0480:  a695 1a42 e1e1 ef91 14d7 b7b7 0ca4 2dda  ...B..........-.
   840  //		0x0490:  6ac1 771e 25c1 a578 4ca8 6fd8 de04 1c09  j.w.%..xL.o.....
   841  //		0x04a0:  df49 f179 6a58 2b45 7231 307f bc67 e5e7  .I.yjX+Er10..g..
   842  //		0x04b0:  c5cd fec0 b021 508e 4fc5 f821 f734 90bc  .....!P.O..!.4..
   843  //		0x04c0:  c87f 14f1 2e5c d17b 1818 5b4a 6b68 0212  .....\.{..[Jkh..
   844  //		0x04d0:  1791 4a30 8518 99a9 b516 67e7 ed56 d1d1  ..J0......g..V..
   845  //		0x04e0:  239d dfda 11c5 0afe e58a b6e0 fb66 ab5c  #............f.\
   846  //		0x04f0:  f590 dcd6 457d 01d1 83f5 a9f0 cdb2 9c14  ....E}..........
   847  //		0x0500:  ff66 f10c d428 a07b 34e3 d600 91f2 aca7  .f...(.{4.......
   848  //		0x0510:  4e1f f3ac a96e 2aa3 ec9b 448c 748d f858  N....n*...D.t..X
   849  //		0x0520:  131c d496 af9b f5f0 d2f5 57ac 0b64 55a1  ..........W..dU.
   850  //		0x0530:  860e 5ad0 3e62 26b5 9e17 f51f 88c1 02e3  ..Z.>b&.........
   851  //		0x0540:  4a38 de70 3216 6f88 5d1e f429 ee19 4121  J8.p2.o.]..)..A!
   852  //		0x0550:  f571 84ac 3789 141f 1798 90b1 8373 2499  .q..7........s$.
   853  //		0x0560:  c131 b13f f3a3 9a07 aef1 bfe8 8cd7 8c2e  .1.?............
   854  //		0x0570:  ba35 dfc5 eb07 013c 7621 6481 bdfb 6233  .5.....<v!d...b3
   855  //		0x0580:  22e2 0f05 7e15 0417 67e4 2632 5207 28a6  "...~...g.&2R.(.
   856  //		0x0590:  8e88 9423 de54 5412 b53e fd8d d47a de58  ...#.TT..>...z.X
   857  //		0x05a0:  a1b2 6e08 d06d dc21 1eda 14a0 a2f7 1701  ..n..m.!........
   858  //		0x05b0:  a5e0 dfd7 871f 595d db43 70f5 bab3 b732  ......Y].Cp....2
   859  //		0x05c0:  6275 da15 b203 dac7 321f 8d61 11bd 30    bu......2..a..0
   860  var testAnotherMalformedDNS = []byte{
   861  	0x00, 0x55, 0x22, 0xaf, 0xc6, 0x37, 0x00, 0x22, 0x55, 0xac, 0xde, 0xac, 0x08, 0x00, 0x45, 0x00,
   862  	0x05, 0xc1, 0x2e, 0xea, 0x40, 0x00, 0x36, 0x11, 0xfb, 0xd1, 0x0a, 0x4d, 0x00, 0x1d, 0x0a, 0x01,
   863  	0x00, 0x06, 0x00, 0x35, 0xa5, 0x28, 0x05, 0xad, 0x00, 0xa2, 0x34, 0xb3, 0x33, 0x13, 0x5c, 0x1f,
   864  	0x2d, 0xc8, 0x74, 0x2e, 0xcb, 0x77, 0x2d, 0xa0, 0xbc, 0x2e, 0x56, 0x8b, 0xf7, 0x51, 0xf3, 0x22,
   865  	0x85, 0x1d, 0xab, 0x17, 0x78, 0x10, 0x00, 0x9c, 0x1c, 0xef, 0xc6, 0xd5, 0x06, 0x05, 0x37, 0xf4,
   866  	0x96, 0x9b, 0xc6, 0x5e, 0x48, 0x3e, 0x47, 0x06, 0xf5, 0x8b, 0xdf, 0x36, 0x47, 0xdb, 0xea, 0xe2,
   867  	0x88, 0x5d, 0x68, 0x8a, 0xc5, 0xa5, 0x57, 0x05, 0xaa, 0xa8, 0x95, 0xeb, 0x93, 0xa4, 0xd8, 0x5a,
   868  	0xc9, 0xaf, 0x26, 0x1f, 0x78, 0x16, 0xa3, 0x54, 0x2d, 0x23, 0xd8, 0x4a, 0x57, 0x9c, 0x48, 0x76,
   869  	0xa3, 0x91, 0x43, 0xdb, 0x5c, 0x41, 0x19, 0x1a, 0x92, 0xb8, 0xdc, 0xdd, 0x68, 0x39, 0xee, 0xf5,
   870  	0x72, 0x8e, 0x13, 0xe0, 0x06, 0x79, 0x6f, 0x47, 0x88, 0xa0, 0x25, 0xb9, 0x44, 0xd8, 0xf8, 0xe7,
   871  	0x8a, 0xfe, 0x0b, 0xfa, 0xf8, 0x11, 0x8d, 0xa5, 0xf8, 0xa3, 0x1f, 0x8e, 0xd2, 0x3b, 0xfe, 0x12,
   872  	0xd9, 0x43, 0x93, 0x27, 0x92, 0xad, 0x44, 0x10, 0x18, 0x3e, 0x68, 0x8d, 0xb0, 0x6d, 0x53, 0x91,
   873  	0x69, 0x5b, 0xe4, 0x9f, 0x8f, 0x1e, 0xc0, 0x75, 0xd0, 0x43, 0xaf, 0xe0, 0x11, 0x74, 0x9d, 0xb0,
   874  	0x06, 0xb0, 0xf0, 0x1e, 0xb8, 0x5b, 0x3c, 0x84, 0x94, 0x5e, 0x06, 0xd0, 0xb2, 0x0f, 0x9e, 0xaa,
   875  	0x12, 0x3d, 0x0a, 0xb0, 0x2a, 0x55, 0x30, 0x9c, 0x0e, 0xe9, 0x3e, 0x5e, 0xdb, 0x2f, 0xf3, 0x77,
   876  	0xd7, 0xf1, 0x9b, 0xae, 0x37, 0x3d, 0x33, 0x16, 0x07, 0x96, 0xb8, 0x0e, 0xdd, 0x18, 0x51, 0x73,
   877  	0xb2, 0x8d, 0x84, 0xfd, 0x18, 0x12, 0xd8, 0x7b, 0x42, 0xc8, 0x5f, 0x11, 0x4d, 0xb6, 0xb2, 0x69,
   878  	0x1c, 0x42, 0x4a, 0xea, 0xd5, 0xa4, 0x64, 0x4b, 0x6c, 0x00, 0xf0, 0xc0, 0xfc, 0xee, 0x71, 0xa7,
   879  	0xe7, 0xf0, 0x71, 0x9c, 0xa2, 0x07, 0xdc, 0x5c, 0xa6, 0xfa, 0xf0, 0x05, 0xa3, 0x38, 0x7f, 0xf0,
   880  	0x5b, 0xeb, 0x3b, 0x4d, 0x89, 0x52, 0x2a, 0x46, 0xd4, 0x7b, 0xa5, 0xa2, 0xe1, 0xfb, 0x9e, 0x76,
   881  	0xc8, 0x15, 0x62, 0x58, 0x50, 0xf4, 0x69, 0x97, 0xba, 0xd5, 0xb4, 0x79, 0x2d, 0x06, 0xeb, 0xbb,
   882  	0x2c, 0xac, 0x2e, 0xcc, 0xe4, 0xf0, 0x1f, 0x94, 0xce, 0x9f, 0x18, 0x6c, 0x61, 0xda, 0x96, 0x81,
   883  	0x34, 0x5c, 0x4d, 0x88, 0xef, 0xc7, 0x03, 0x7b, 0xfb, 0xe3, 0x44, 0x02, 0xea, 0x06, 0x2e, 0x5d,
   884  	0x2e, 0x6e, 0x48, 0x60, 0xe1, 0x80, 0x3e, 0xf7, 0xc0, 0x06, 0x0a, 0xd1, 0xeb, 0xb9, 0xc4, 0xff,
   885  	0xde, 0xe2, 0xf2, 0x1c, 0x02, 0xc2, 0x75, 0x1a, 0xde, 0xd8, 0xae, 0x2e, 0x13, 0xa9, 0x3f, 0xa2,
   886  	0x39, 0x2a, 0x8b, 0x54, 0x11, 0xb2, 0x2b, 0x4e, 0x2b, 0xf1, 0x47, 0x80, 0xdb, 0x9f, 0x8c, 0x10,
   887  	0xac, 0x6f, 0x61, 0xb0, 0x7b, 0x19, 0x42, 0x3f, 0x07, 0xe5, 0x46, 0x28, 0xb8, 0x70, 0xf7, 0x5d,
   888  	0x09, 0xa3, 0x63, 0xb2, 0x77, 0xaf, 0x59, 0x85, 0xa0, 0xae, 0x51, 0xd8, 0x24, 0x3f, 0xa7, 0xc8,
   889  	0xab, 0x08, 0x7f, 0xc6, 0x02, 0x17, 0xc0, 0x9f, 0xc4, 0x12, 0x0c, 0x45, 0xe6, 0xaa, 0x96, 0xbf,
   890  	0x18, 0x4c, 0x43, 0x07, 0x1f, 0x1f, 0xc4, 0xf4, 0x77, 0x34, 0xda, 0x31, 0x20, 0x88, 0x66, 0x2b,
   891  	0x44, 0xc5, 0x09, 0x6f, 0x1d, 0x1d, 0x2d, 0xc5, 0xff, 0xd6, 0x86, 0x7d, 0x9f, 0xc5, 0x7b, 0x45,
   892  	0xf9, 0x49, 0x7d, 0xd9, 0x38, 0xde, 0x0d, 0x51, 0xac, 0x2a, 0x32, 0xfc, 0xf5, 0x0b, 0x1b, 0xbe,
   893  	0x1c, 0x4b, 0x54, 0x41, 0xfb, 0xf3, 0x08, 0x21, 0x6c, 0x28, 0x45, 0x30, 0x56, 0x76, 0x1d, 0x27,
   894  	0x50, 0x87, 0x46, 0x6c, 0x3d, 0x5b, 0x45, 0xa6, 0xaf, 0x7f, 0x91, 0x7a, 0x6d, 0x43, 0x66, 0xc2,
   895  	0x03, 0x6a, 0x8b, 0xef, 0xca, 0x60, 0x9b, 0x13, 0x8d, 0x29, 0x9f, 0xda, 0x82, 0xfa, 0x01, 0xb1,
   896  	0xdf, 0x8f, 0x1f, 0x83, 0xc7, 0x1d, 0x63, 0x0f, 0x34, 0x9e, 0x50, 0x8c, 0x9f, 0x7a, 0xe3, 0xda,
   897  	0xa1, 0x14, 0x36, 0x22, 0x9d, 0xf8, 0x99, 0x26, 0x4d, 0xac, 0x41, 0x50, 0xd5, 0x05, 0x7b, 0x3a,
   898  	0x6f, 0xed, 0xfc, 0x75, 0x6b, 0x4f, 0x2d, 0x60, 0x8a, 0x89, 0x76, 0x7d, 0x9a, 0xf0, 0x89, 0x6e,
   899  	0x90, 0x7d, 0x1a, 0xda, 0xde, 0xf3, 0x34, 0x5c, 0x0d, 0x81, 0x28, 0x3c, 0xa2, 0x4f, 0xfc, 0xbb,
   900  	0xbb, 0xdd, 0xb7, 0xb3, 0xe3, 0xbb, 0x9f, 0x1b, 0xd9, 0x66, 0x51, 0xb7, 0x82, 0x17, 0x7f, 0xa0,
   901  	0xe8, 0x28, 0xd3, 0xca, 0xa6, 0xf1, 0x53, 0x2f, 0x16, 0x4e, 0xe4, 0x05, 0xbb, 0x3b, 0x0d, 0xe3,
   902  	0x98, 0x5d, 0x6e, 0x89, 0xd8, 0x25, 0xeb, 0xc6, 0xd8, 0xba, 0x51, 0x90, 0xa1, 0x14, 0xc6, 0xa3,
   903  	0x18, 0xb4, 0x8a, 0xa7, 0x18, 0x1a, 0x01, 0xac, 0xcd, 0xc0, 0x80, 0x48, 0xea, 0x72, 0xa5, 0xe3,
   904  	0xe3, 0x7a, 0xdc, 0x57, 0x65, 0xcd, 0xb7, 0x87, 0x39, 0xe6, 0xc3, 0x9e, 0x31, 0x7b, 0x45, 0xd8,
   905  	0x47, 0x5c, 0x05, 0xba, 0xe8, 0xf8, 0x82, 0x24, 0x5a, 0x85, 0x27, 0xb8, 0x15, 0x84, 0x8d, 0x78,
   906  	0x62, 0xb6, 0x64, 0x95, 0xac, 0x10, 0x33, 0x8f, 0x11, 0x22, 0xf2, 0xff, 0x04, 0x3e, 0x9e, 0x2a,
   907  	0x10, 0x58, 0xa9, 0x10, 0x57, 0x92, 0x6f, 0xcd, 0x9a, 0x96, 0x61, 0x83, 0x67, 0x08, 0x8f, 0x70,
   908  	0xed, 0xc6, 0xa6, 0x7c, 0x64, 0xff, 0x50, 0xfa, 0x52, 0x0b, 0xde, 0x94, 0xc8, 0x2c, 0xc4, 0xd6,
   909  	0x7d, 0x8f, 0x0f, 0xd5, 0x2f, 0x0d, 0x98, 0x33, 0x7c, 0x6c, 0xbe, 0x10, 0xa4, 0xe5, 0xdc, 0x99,
   910  	0xa4, 0x67, 0xef, 0x5f, 0xb3, 0x5b, 0xc1, 0x1c, 0xe2, 0x3c, 0x13, 0x1a, 0x48, 0xb2, 0x9c, 0xef,
   911  	0x5a, 0x2f, 0xfe, 0xce, 0xdd, 0x9e, 0x2a, 0xea, 0x0d, 0xb9, 0xfa, 0xf3, 0xa6, 0xef, 0xb2, 0x9d,
   912  	0xe8, 0x5d, 0xa4, 0x10, 0xdd, 0x6a, 0x68, 0x06, 0x3f, 0xc6, 0x16, 0x94, 0x17, 0x9f, 0xcb, 0x4b,
   913  	0x08, 0xc4, 0x86, 0xb2, 0x07, 0x13, 0xcd, 0xdb, 0xb2, 0x57, 0xd5, 0x6b, 0xfe, 0x82, 0x7d, 0x82,
   914  	0x0d, 0x1f, 0x6d, 0xc9, 0x67, 0xb2, 0xd2, 0xa1, 0x67, 0x91, 0x4f, 0x38, 0xed, 0xf9, 0x49, 0x1f,
   915  	0x2c, 0x02, 0x35, 0xf5, 0x81, 0x65, 0xec, 0xc3, 0xbc, 0x6a, 0xb6, 0x31, 0x3c, 0x7e, 0x1a, 0xd4,
   916  	0x8e, 0x27, 0xf9, 0x62, 0xf9, 0x42, 0x11, 0xb5, 0x1b, 0x45, 0x9b, 0xac, 0xb4, 0x74, 0x3c, 0x6e,
   917  	0x68, 0x32, 0x30, 0x75, 0xbe, 0x6d, 0xac, 0x0d, 0xa8, 0xa0, 0x7d, 0x47, 0xa6, 0xef, 0x4e, 0x43,
   918  	0x6b, 0x9a, 0x30, 0x97, 0x8a, 0x8b, 0x82, 0xa3, 0x95, 0x15, 0x36, 0x2c, 0xf7, 0xd6, 0xa3, 0x7f,
   919  	0x73, 0x13, 0x11, 0x99, 0xa5, 0xf3, 0x03, 0xdc, 0xbc, 0xc9, 0xfb, 0x10, 0xc2, 0x3d, 0xee, 0xb9,
   920  	0x78, 0xff, 0xc8, 0xf3, 0x0d, 0x38, 0x9f, 0x74, 0xce, 0xec, 0xb7, 0xae, 0x63, 0xe3, 0x34, 0x24,
   921  	0xb7, 0x83, 0xf1, 0x06, 0x01, 0x1f, 0x66, 0x6b, 0xbf, 0x2d, 0xab, 0xc8, 0xea, 0x10, 0x57, 0xa1,
   922  	0x7c, 0xf2, 0x4a, 0x3f, 0x57, 0xca, 0x13, 0x86, 0xbf, 0xba, 0x27, 0xe5, 0x46, 0x62, 0x81, 0xc8,
   923  	0x04, 0x1e, 0x18, 0x20, 0xb3, 0xd5, 0xc3, 0x99, 0xcd, 0x4d, 0x22, 0x2f, 0x29, 0xf0, 0xb9, 0x94,
   924  	0x86, 0x5a, 0xe6, 0xe2, 0x16, 0x86, 0x32, 0x61, 0xb0, 0xcd, 0xca, 0xaf, 0x07, 0xec, 0xd0, 0xbc,
   925  	0xaf, 0xb8, 0x3c, 0xf0, 0x51, 0xc1, 0x6c, 0x7a, 0x63, 0x83, 0x6b, 0x3a, 0xff, 0x47, 0x95, 0x51,
   926  	0x10, 0x99, 0x52, 0x5f, 0x35, 0x5e, 0x46, 0x84, 0xbd, 0x34, 0xec, 0x12, 0x88, 0xc9, 0xdc, 0xc2,
   927  	0xd1, 0x1c, 0x82, 0x6d, 0xf1, 0xdf, 0x37, 0xe6, 0xf0, 0x8f, 0x6c, 0xe8, 0x81, 0x7d, 0xbd, 0xc3,
   928  	0x20, 0xb9, 0xa2, 0x74, 0xc6, 0x45, 0xc6, 0x7d, 0xf2, 0x99, 0xfe, 0xf9, 0x28, 0x7f, 0x09, 0xee,
   929  	0xac, 0x67, 0x68, 0x72, 0xa1, 0x26, 0xb1, 0xd3, 0x92, 0x2c, 0x4c, 0x2a, 0x0e, 0xc9, 0xb6, 0xd4,
   930  	0xfb, 0x59, 0x61, 0x63, 0xd1, 0xc4, 0x17, 0x08, 0x8d, 0x94, 0xbc, 0x3d, 0xbe, 0x5e, 0xae, 0x29,
   931  	0x51, 0xff, 0xa7, 0x65, 0x9d, 0xf6, 0xae, 0x35, 0xed, 0x6b, 0x05, 0x55, 0x93, 0x3f, 0x3e, 0xd6,
   932  	0x25, 0x9b, 0xd9, 0x3e, 0xf8, 0x6f, 0x60, 0x88, 0x0c, 0x4e, 0x35, 0x7b, 0x5c, 0x67, 0x7d, 0x93,
   933  	0xa6, 0x95, 0x1a, 0x42, 0xe1, 0xe1, 0xef, 0x91, 0x14, 0xd7, 0xb7, 0xb7, 0x0c, 0xa4, 0x2d, 0xda,
   934  	0x6a, 0xc1, 0x77, 0x1e, 0x25, 0xc1, 0xa5, 0x78, 0x4c, 0xa8, 0x6f, 0xd8, 0xde, 0x04, 0x1c, 0x09,
   935  	0xdf, 0x49, 0xf1, 0x79, 0x6a, 0x58, 0x2b, 0x45, 0x72, 0x31, 0x30, 0x7f, 0xbc, 0x67, 0xe5, 0xe7,
   936  	0xc5, 0xcd, 0xfe, 0xc0, 0xb0, 0x21, 0x50, 0x8e, 0x4f, 0xc5, 0xf8, 0x21, 0xf7, 0x34, 0x90, 0xbc,
   937  	0xc8, 0x7f, 0x14, 0xf1, 0x2e, 0x5c, 0xd1, 0x7b, 0x18, 0x18, 0x5b, 0x4a, 0x6b, 0x68, 0x02, 0x12,
   938  	0x17, 0x91, 0x4a, 0x30, 0x85, 0x18, 0x99, 0xa9, 0xb5, 0x16, 0x67, 0xe7, 0xed, 0x56, 0xd1, 0xd1,
   939  	0x23, 0x9d, 0xdf, 0xda, 0x11, 0xc5, 0x0a, 0xfe, 0xe5, 0x8a, 0xb6, 0xe0, 0xfb, 0x66, 0xab, 0x5c,
   940  	0xf5, 0x90, 0xdc, 0xd6, 0x45, 0x7d, 0x01, 0xd1, 0x83, 0xf5, 0xa9, 0xf0, 0xcd, 0xb2, 0x9c, 0x14,
   941  	0xff, 0x66, 0xf1, 0x0c, 0xd4, 0x28, 0xa0, 0x7b, 0x34, 0xe3, 0xd6, 0x00, 0x91, 0xf2, 0xac, 0xa7,
   942  	0x4e, 0x1f, 0xf3, 0xac, 0xa9, 0x6e, 0x2a, 0xa3, 0xec, 0x9b, 0x44, 0x8c, 0x74, 0x8d, 0xf8, 0x58,
   943  	0x13, 0x1c, 0xd4, 0x96, 0xaf, 0x9b, 0xf5, 0xf0, 0xd2, 0xf5, 0x57, 0xac, 0x0b, 0x64, 0x55, 0xa1,
   944  	0x86, 0x0e, 0x5a, 0xd0, 0x3e, 0x62, 0x26, 0xb5, 0x9e, 0x17, 0xf5, 0x1f, 0x88, 0xc1, 0x02, 0xe3,
   945  	0x4a, 0x38, 0xde, 0x70, 0x32, 0x16, 0x6f, 0x88, 0x5d, 0x1e, 0xf4, 0x29, 0xee, 0x19, 0x41, 0x21,
   946  	0xf5, 0x71, 0x84, 0xac, 0x37, 0x89, 0x14, 0x1f, 0x17, 0x98, 0x90, 0xb1, 0x83, 0x73, 0x24, 0x99,
   947  	0xc1, 0x31, 0xb1, 0x3f, 0xf3, 0xa3, 0x9a, 0x07, 0xae, 0xf1, 0xbf, 0xe8, 0x8c, 0xd7, 0x8c, 0x2e,
   948  	0xba, 0x35, 0xdf, 0xc5, 0xeb, 0x07, 0x01, 0x3c, 0x76, 0x21, 0x64, 0x81, 0xbd, 0xfb, 0x62, 0x33,
   949  	0x22, 0xe2, 0x0f, 0x05, 0x7e, 0x15, 0x04, 0x17, 0x67, 0xe4, 0x26, 0x32, 0x52, 0x07, 0x28, 0xa6,
   950  	0x8e, 0x88, 0x94, 0x23, 0xde, 0x54, 0x54, 0x12, 0xb5, 0x3e, 0xfd, 0x8d, 0xd4, 0x7a, 0xde, 0x58,
   951  	0xa1, 0xb2, 0x6e, 0x08, 0xd0, 0x6d, 0xdc, 0x21, 0x1e, 0xda, 0x14, 0xa0, 0xa2, 0xf7, 0x17, 0x01,
   952  	0xa5, 0xe0, 0xdf, 0xd7, 0x87, 0x1f, 0x59, 0x5d, 0xdb, 0x43, 0x70, 0xf5, 0xba, 0xb3, 0xb7, 0x32,
   953  	0x62, 0x75, 0xda, 0x15, 0xb2, 0x03, 0xda, 0xc7, 0x32, 0x1f, 0x8d, 0x61, 0x11, 0xbd, 0x30,
   954  }
   955  
   956  func TestAnotherMalformedDNS(t *testing.T) {
   957  	p := gopacket.NewPacket(testAnotherMalformedDNS, LinkTypeEthernet, testDecodeOptions)
   958  	if errLayer := p.ErrorLayer(); errLayer == nil {
   959  		t.Error("No error layer on invalid DNS name")
   960  	} else if err := errLayer.Error(); !strings.Contains(err.Error(), "offset too high") {
   961  		t.Errorf("unexpected error message: %v", err)
   962  	}
   963  }
   964  
   965  // testMalformedDNSAgain is the packet:
   966  //
   967  //	12:14:52.702061 IP 10.77.0.4.53 > 10.1.0.41.61610: 12529 updateDA [b2&3=0x5cad] [38274a] [61303q] [1718n] [14913au][|domain]
   968  //		0x0000:  0055 22af c637 0022 55ac deac 0800 4500  .U"..7."U.....E.
   969  //		0x0010:  0091 2dff 0000 7811 ffe2 0a4d 0004 0a01  ..-...x....M....
   970  //		0x0020:  0029 0035 f0aa 007d 5b53 30f1 5cad ef77  .).5...}[S0.\..w
   971  //		0x0030:  9582 06b6 3a41 357a 8cef cdc0 a732 b800  ....:A5z.....2..
   972  //		0x0040:  466e 1c30 2e75 95ac c03d 1ed4 8635 2d09  Fn.0.u...=...5-.
   973  //		0x0050:  2fee 3a82 b4f0 427e 2b6b f870 cc7f c9a1  /.:...B~+k.p....
   974  //		0x0060:  e6f1 a761 97ec 2ff7 d248 4d95 321c 6e4e  ...a../..HM.2.nN
   975  //		0x0070:  57fa 6d3d 9ec0 fe3a 6f1e e634 4396 b494  W.m=...:o..4C...
   976  //		0x0080:  8b7a a929 d7e1 da7c c346 ca77 4890 6bf3  .z.)...|.F.wH.k.
   977  //		0x0090:  5ecb 7e97 c49d 3564 984f bf7c 8ac1 dd    ^.~...5d.O.|...
   978  var testMalformedDNSAgain = []byte{
   979  	0x00, 0x55, 0x22, 0xaf, 0xc6, 0x37, 0x00, 0x22, 0x55, 0xac, 0xde, 0xac, 0x08, 0x00, 0x45, 0x00,
   980  	0x00, 0x91, 0x2d, 0xff, 0x00, 0x00, 0x78, 0x11, 0xff, 0xe2, 0x0a, 0x4d, 0x00, 0x04, 0x0a, 0x01,
   981  	0x00, 0x29, 0x00, 0x35, 0xf0, 0xaa, 0x00, 0x7d, 0x5b, 0x53, 0x30, 0xf1, 0x5c, 0xad, 0xef, 0x77,
   982  	0x95, 0x82, 0x06, 0xb6, 0x3a, 0x41, 0x35, 0x7a, 0x8c, 0xef, 0xcd, 0xc0, 0xa7, 0x32, 0xb8, 0x00,
   983  	0x46, 0x6e, 0x1c, 0x30, 0x2e, 0x75, 0x95, 0xac, 0xc0, 0x3d, 0x1e, 0xd4, 0x86, 0x35, 0x2d, 0x09,
   984  	0x2f, 0xee, 0x3a, 0x82, 0xb4, 0xf0, 0x42, 0x7e, 0x2b, 0x6b, 0xf8, 0x70, 0xcc, 0x7f, 0xc9, 0xa1,
   985  	0xe6, 0xf1, 0xa7, 0x61, 0x97, 0xec, 0x2f, 0xf7, 0xd2, 0x48, 0x4d, 0x95, 0x32, 0x1c, 0x6e, 0x4e,
   986  	0x57, 0xfa, 0x6d, 0x3d, 0x9e, 0xc0, 0xfe, 0x3a, 0x6f, 0x1e, 0xe6, 0x34, 0x43, 0x96, 0xb4, 0x94,
   987  	0x8b, 0x7a, 0xa9, 0x29, 0xd7, 0xe1, 0xda, 0x7c, 0xc3, 0x46, 0xca, 0x77, 0x48, 0x90, 0x6b, 0xf3,
   988  	0x5e, 0xcb, 0x7e, 0x97, 0xc4, 0x9d, 0x35, 0x64, 0x98, 0x4f, 0xbf, 0x7c, 0x8a, 0xc1, 0xdd,
   989  }
   990  
   991  func TestMalformedDNSAgain(t *testing.T) {
   992  	p := gopacket.NewPacket(testMalformedDNSAgain, LinkTypeEthernet, testDecodeOptions)
   993  	if errLayer := p.ErrorLayer(); errLayer == nil {
   994  		t.Error("No error layer on invalid DNS name")
   995  	} else if err := errLayer.Error(); !strings.Contains(err.Error(), "walked out of range") {
   996  		t.Errorf("unexpected error message: %v", err)
   997  	}
   998  }
   999  
  1000  // testMalformedDNSOhGodMakeItStop is the packet:
  1001  //
  1002  //	15:08:24.430906 IP 10.77.0.19.53 > 10.1.0.19.50635: 12397 zoneInit% [b2&3=0x7232] [47729a] [46283q] [60247n] [61718au][|domain]
  1003  //		0x0000:  0055 22af c637 0022 55ac deac 0800 4500  .U"..7."U.....E.
  1004  //		0x0010:  0079 c51c 4000 3511 6be4 0a4d 0013 0a01  .y..@.5.k..M....
  1005  //		0x0020:  0013 0035 c5cb 0065 ef45 306d 7232 b4cb  ...5...e.E0mr2..
  1006  //		0x0030:  ba71 eb57 f116 3994 e000 4626 0534 66cc  .q.W..9...F&.4f.
  1007  //		0x0040:  7b32 24f2 eece bca7 20e2 9a2a e1ce e737  {2$........*...7
  1008  //		0x0050:  ac39 5fae 72ec c3ec 284f ca4a 171f 466d  .9_.r...(O.J..Fm
  1009  //		0x0060:  f6c6 84d7 e795 310f 26df 9b59 6db9 21cf  ......1.&..Ym.!.
  1010  //		0x0070:  15cb 30a3 c4cf df23 805a ed1a 0584 4fc3  ..0....#.Z....O.
  1011  //		0x0080:  7fa3 3cb4 e04f e9                        ..<..O.
  1012  var testMalformedDNSOhGodMakeItStop = []byte{
  1013  	0x00, 0x55, 0x22, 0xaf, 0xc6, 0x37, 0x00, 0x22, 0x55, 0xac, 0xde, 0xac, 0x08, 0x00, 0x45, 0x00,
  1014  	0x00, 0x79, 0xc5, 0x1c, 0x40, 0x00, 0x35, 0x11, 0x6b, 0xe4, 0x0a, 0x4d, 0x00, 0x13, 0x0a, 0x01,
  1015  	0x00, 0x13, 0x00, 0x35, 0xc5, 0xcb, 0x00, 0x65, 0xef, 0x45, 0x30, 0x6d, 0x72, 0x32, 0xb4, 0xcb,
  1016  	0xba, 0x71, 0xeb, 0x57, 0xf1, 0x16, 0x39, 0x94, 0xe0, 0x00, 0x46, 0x26, 0x05, 0x34, 0x66, 0xcc,
  1017  	0x7b, 0x32, 0x24, 0xf2, 0xee, 0xce, 0xbc, 0xa7, 0x20, 0xe2, 0x9a, 0x2a, 0xe1, 0xce, 0xe7, 0x37,
  1018  	0xac, 0x39, 0x5f, 0xae, 0x72, 0xec, 0xc3, 0xec, 0x28, 0x4f, 0xca, 0x4a, 0x17, 0x1f, 0x46, 0x6d,
  1019  	0xf6, 0xc6, 0x84, 0xd7, 0xe7, 0x95, 0x31, 0x0f, 0x26, 0xdf, 0x9b, 0x59, 0x6d, 0xb9, 0x21, 0xcf,
  1020  	0x15, 0xcb, 0x30, 0xa3, 0xc4, 0xcf, 0xdf, 0x23, 0x80, 0x5a, 0xed, 0x1a, 0x05, 0x84, 0x4f, 0xc3,
  1021  	0x7f, 0xa3, 0x3c, 0xb4, 0xe0, 0x4f, 0xe9,
  1022  }
  1023  
  1024  func TestMalformedDNSOhGodMakeItStop(t *testing.T) {
  1025  	p := gopacket.NewPacket(testMalformedDNSOhGodMakeItStop, LinkTypeEthernet, testDecodeOptions)
  1026  	if errLayer := p.ErrorLayer(); errLayer == nil {
  1027  		t.Error("No error layer on invalid DNS name")
  1028  	} else if err := errLayer.Error(); !strings.Contains(err.Error(), "offset pointer too high") {
  1029  		t.Errorf("unexpected error message: %v", err)
  1030  	}
  1031  }
  1032  
  1033  var testMalformedDNSOPT = []byte{
  1034  	0x00, 0x90, 0x0b, 0x12, 0x91, 0xc1, 0x00, 0x1c, 0xc0, 0x93, 0x33, 0xfb, 0x08, 0x00, 0x45, 0x00,
  1035  	0x00, 0x5A, 0xce, 0x58, 0x00, 0x00, 0x40, 0x11, 0x67, 0xe2, 0xac, 0x10, 0x01, 0xc7, 0x4b, 0x4b,
  1036  	0x4b, 0x4b, 0xd6, 0x00, 0x00, 0x35, 0x00, 0x46, 0x44, 0xb0, 0x50, 0x12, 0x01, 0x00, 0x00, 0x01,
  1037  	0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x77, 0x77, 0x77, 0x04, 0x69, 0x65, 0x74, 0x66, 0x03,
  1038  	0x6f, 0x72, 0x67, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x29, 0x10, 0x00, 0x00, 0x00, 0x80,
  1039  	0x00, 0x00, 0x13, 0x69, 0x42, 0x00, 0x10, 0x4F, 0x70, 0x65, 0x6E, 0x44, 0x4E, 0x53, 0x01, 0x23,
  1040  	0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
  1041  }
  1042  
  1043  func TestMalformedDNSOPT(t *testing.T) {
  1044  	p := gopacket.NewPacket(testMalformedDNSOPT, LinkTypeEthernet, testDecodeOptions)
  1045  	if errLayer := p.ErrorLayer(); errLayer == nil {
  1046  		t.Error("No error layer on invalid DNS name")
  1047  	} else if err := errLayer.Error(); !strings.Contains(err.Error(), "Malformed DNSOPT record") {
  1048  		t.Errorf("unexpected error message: %v", err)
  1049  	}
  1050  }
  1051  
  1052  // testPacketDNSPanic7 is the packet:
  1053  //
  1054  //	07:56:25.174747 IP 10.77.0.11.53 > 10.1.0.67.55777: 41808*-| 3/7/0 TXT "google-site-verification=DC2uC-T8kD33lINhNzfo0bNBrw-vrCXs5BPF5BXY56g", TXT "v=spf1 include:spf-a.outlook.com include:spf-b.outlook.com ip4:157.55.9.128/25 include:spf.protection.outlook.com include:spf-a.hotmail.com include:_spf-ssg-b.microsoft.com include:_spf-ssg-c.microsoft.com ~all", TXT "google-site-verification=0iLWhIMhXEkeWwWfFU4ursTn-_OvoOjaA0Lr7Pg1sEM" (512)
  1055  //		0x0000:  0055 22af c637 0022 55ac deac 0800 4500  .U"..7."U.....E.
  1056  //		0x0010:  021c b5ca 4000 fa11 b46a 0a4d 000b 0a01  ....@....j.M....
  1057  //		0x0020:  0043 0035 d9e1 0208 afd6 a350 8600 0001  .C.5.......P....
  1058  //		0x0030:  0003 0007 0000 076f 7574 6c6f 6f6b 0363  .......outlook.c
  1059  //		0x0040:  6f6d 0000 1000 01c0 0c00 1000 0100 0001  om..............
  1060  //		0x0050:  2c00 4544 676f 6f67 6c65 2d73 6974 652d  ,.EDgoogle-site-
  1061  //		0x0060:  7665 7269 6669 6361 7469 6f6e 3d44 4332  verification=DC2
  1062  //		0x0070:  7543 2d54 386b 4433 336c 494e 684e 7a66  uC-T8kD33lINhNzf
  1063  //		0x0080:  6f30 624e 4272 772d 7672 4358 7335 4250  o0bNBrw-vrCXs5BP
  1064  //		0x0090:  4635 4258 5935 3667 c00c 0010 0001 0000  F5BXY56g........
  1065  //		0x00a0:  012c 00d3 d276 3d73 7066 3120 696e 636c  .,...v=spf1.incl
  1066  //		0x00b0:  7564 653a 7370 662d 612e 6f75 746c 6f6f  ude:spf-a.outloo
  1067  //		0x00c0:  6b2e 636f 6d20 696e 636c 7564 653a 7370  k.com.include:sp
  1068  //		0x00d0:  662d 622e 6f75 746c 6f6f 6b2e 636f 6d20  f-b.outlook.com.
  1069  //		0x00e0:  6970 343a 3135 372e 3535 2e39 2e31 3238  ip4:157.55.9.128
  1070  //		0x00f0:  2f32 3520 696e 636c 7564 653a 7370 662e  /25.include:spf.
  1071  //		0x0100:  7072 6f74 6563 7469 6f6e 2e6f 7574 6c6f  protection.outlo
  1072  //		0x0110:  6f6b 2e63 6f6d 2069 6e63 6c75 6465 3a73  ok.com.include:s
  1073  //		0x0120:  7066 2d61 2e68 6f74 6d61 696c 2e63 6f6d  pf-a.hotmail.com
  1074  //		0x0130:  2069 6e63 6c75 6465 3a5f 7370 662d 7373  .include:_spf-ss
  1075  //		0x0140:  672d 622e 6d69 6372 6f73 6f66 742e 636f  g-b.microsoft.co
  1076  //		0x0150:  6d20 696e 636c 7564 653a 5f73 7066 2d73  m.include:_spf-s
  1077  //		0x0160:  7367 2d63 2e6d 6963 726f 736f 6674 2e63  sg-c.microsoft.c
  1078  //		0x0170:  6f6d 207e 616c 6cc0 0c00 1000 0100 0001  om.~all.........
  1079  //		0x0180:  2c00 4544 676f 6f67 6c65 2d73 6974 652d  ,.EDgoogle-site-
  1080  //		0x0190:  7665 7269 6669 6361 7469 6f6e 3d30 694c  verification=0iL
  1081  //		0x01a0:  5768 494d 6858 456b 6557 7757 6646 5534  WhIMhXEkeWwWfFU4
  1082  //		0x01b0:  7572 7354 6e2d 5f4f 766f 4f6a 6141 304c  ursTn-_OvoOjaA0L
  1083  //		0x01c0:  7237 5067 3173 454d c00c 0002 0001 0002  r7Pg1sEM........
  1084  //		0x01d0:  a300 000e 036e 7332 046d 7366 7403 6e65  .....ns2.msft.ne
  1085  //		0x01e0:  7400 c00c 0002 0001 0002 a300 0006 036e  t..............n
  1086  //		0x01f0:  7334 c1ae c00c 0002 0001 0002 a300 0006  s4..............
  1087  //		0x0200:  036e 7331 c1ae c00c 0002 0001 0002 a300  .ns1............
  1088  //		0x0210:  0006 036e 7333 c1ae c00c 0002 0001 0002  ...ns3..........
  1089  //		0x0220:  a300 0015 046e 7331 610d                 .....ns1a.
  1090  var testPacketDNSPanic7 = []byte{
  1091  	0x00, 0x55, 0x22, 0xaf, 0xc6, 0x37, 0x00, 0x22, 0x55, 0xac, 0xde, 0xac, 0x08, 0x00, 0x45, 0x00,
  1092  	0x02, 0x1c, 0xb5, 0xca, 0x40, 0x00, 0xfa, 0x11, 0xb4, 0x6a, 0x0a, 0x4d, 0x00, 0x0b, 0x0a, 0x01,
  1093  	0x00, 0x43, 0x00, 0x35, 0xd9, 0xe1, 0x02, 0x08, 0xaf, 0xd6, 0xa3, 0x50, 0x86, 0x00, 0x00, 0x01,
  1094  	0x00, 0x03, 0x00, 0x07, 0x00, 0x00, 0x07, 0x6f, 0x75, 0x74, 0x6c, 0x6f, 0x6f, 0x6b, 0x03, 0x63,
  1095  	0x6f, 0x6d, 0x00, 0x00, 0x10, 0x00, 0x01, 0xc0, 0x0c, 0x00, 0x10, 0x00, 0x01, 0x00, 0x00, 0x01,
  1096  	0x2c, 0x00, 0x45, 0x44, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2d, 0x73, 0x69, 0x74, 0x65, 0x2d,
  1097  	0x76, 0x65, 0x72, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x3d, 0x44, 0x43, 0x32,
  1098  	0x75, 0x43, 0x2d, 0x54, 0x38, 0x6b, 0x44, 0x33, 0x33, 0x6c, 0x49, 0x4e, 0x68, 0x4e, 0x7a, 0x66,
  1099  	0x6f, 0x30, 0x62, 0x4e, 0x42, 0x72, 0x77, 0x2d, 0x76, 0x72, 0x43, 0x58, 0x73, 0x35, 0x42, 0x50,
  1100  	0x46, 0x35, 0x42, 0x58, 0x59, 0x35, 0x36, 0x67, 0xc0, 0x0c, 0x00, 0x10, 0x00, 0x01, 0x00, 0x00,
  1101  	0x01, 0x2c, 0x00, 0xd3, 0xd2, 0x76, 0x3d, 0x73, 0x70, 0x66, 0x31, 0x20, 0x69, 0x6e, 0x63, 0x6c,
  1102  	0x75, 0x64, 0x65, 0x3a, 0x73, 0x70, 0x66, 0x2d, 0x61, 0x2e, 0x6f, 0x75, 0x74, 0x6c, 0x6f, 0x6f,
  1103  	0x6b, 0x2e, 0x63, 0x6f, 0x6d, 0x20, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x65, 0x3a, 0x73, 0x70,
  1104  	0x66, 0x2d, 0x62, 0x2e, 0x6f, 0x75, 0x74, 0x6c, 0x6f, 0x6f, 0x6b, 0x2e, 0x63, 0x6f, 0x6d, 0x20,
  1105  	0x69, 0x70, 0x34, 0x3a, 0x31, 0x35, 0x37, 0x2e, 0x35, 0x35, 0x2e, 0x39, 0x2e, 0x31, 0x32, 0x38,
  1106  	0x2f, 0x32, 0x35, 0x20, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x65, 0x3a, 0x73, 0x70, 0x66, 0x2e,
  1107  	0x70, 0x72, 0x6f, 0x74, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x6f, 0x75, 0x74, 0x6c, 0x6f,
  1108  	0x6f, 0x6b, 0x2e, 0x63, 0x6f, 0x6d, 0x20, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x65, 0x3a, 0x73,
  1109  	0x70, 0x66, 0x2d, 0x61, 0x2e, 0x68, 0x6f, 0x74, 0x6d, 0x61, 0x69, 0x6c, 0x2e, 0x63, 0x6f, 0x6d,
  1110  	0x20, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x65, 0x3a, 0x5f, 0x73, 0x70, 0x66, 0x2d, 0x73, 0x73,
  1111  	0x67, 0x2d, 0x62, 0x2e, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x73, 0x6f, 0x66, 0x74, 0x2e, 0x63, 0x6f,
  1112  	0x6d, 0x20, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x65, 0x3a, 0x5f, 0x73, 0x70, 0x66, 0x2d, 0x73,
  1113  	0x73, 0x67, 0x2d, 0x63, 0x2e, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x73, 0x6f, 0x66, 0x74, 0x2e, 0x63,
  1114  	0x6f, 0x6d, 0x20, 0x7e, 0x61, 0x6c, 0x6c, 0xc0, 0x0c, 0x00, 0x10, 0x00, 0x01, 0x00, 0x00, 0x01,
  1115  	0x2c, 0x00, 0x45, 0x44, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2d, 0x73, 0x69, 0x74, 0x65, 0x2d,
  1116  	0x76, 0x65, 0x72, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x3d, 0x30, 0x69, 0x4c,
  1117  	0x57, 0x68, 0x49, 0x4d, 0x68, 0x58, 0x45, 0x6b, 0x65, 0x57, 0x77, 0x57, 0x66, 0x46, 0x55, 0x34,
  1118  	0x75, 0x72, 0x73, 0x54, 0x6e, 0x2d, 0x5f, 0x4f, 0x76, 0x6f, 0x4f, 0x6a, 0x61, 0x41, 0x30, 0x4c,
  1119  	0x72, 0x37, 0x50, 0x67, 0x31, 0x73, 0x45, 0x4d, 0xc0, 0x0c, 0x00, 0x02, 0x00, 0x01, 0x00, 0x02,
  1120  	0xa3, 0x00, 0x00, 0x0e, 0x03, 0x6e, 0x73, 0x32, 0x04, 0x6d, 0x73, 0x66, 0x74, 0x03, 0x6e, 0x65,
  1121  	0x74, 0x00, 0xc0, 0x0c, 0x00, 0x02, 0x00, 0x01, 0x00, 0x02, 0xa3, 0x00, 0x00, 0x06, 0x03, 0x6e,
  1122  	0x73, 0x34, 0xc1, 0xae, 0xc0, 0x0c, 0x00, 0x02, 0x00, 0x01, 0x00, 0x02, 0xa3, 0x00, 0x00, 0x06,
  1123  	0x03, 0x6e, 0x73, 0x31, 0xc1, 0xae, 0xc0, 0x0c, 0x00, 0x02, 0x00, 0x01, 0x00, 0x02, 0xa3, 0x00,
  1124  	0x00, 0x06, 0x03, 0x6e, 0x73, 0x33, 0xc1, 0xae, 0xc0, 0x0c, 0x00, 0x02, 0x00, 0x01, 0x00, 0x02,
  1125  	0xa3, 0x00, 0x00, 0x15, 0x04, 0x6e, 0x73, 0x31, 0x61, 0x0d,
  1126  }
  1127  
  1128  func TestPacketDNSPanic7(t *testing.T) {
  1129  	p := gopacket.NewPacket(testPacketDNSPanic7, LinkTypeEthernet, testDecodeOptions)
  1130  	if errLayer := p.ErrorLayer(); errLayer == nil {
  1131  		t.Error("No error layer on invalid DNS name")
  1132  	} else if err := errLayer.Error(); !strings.Contains(err.Error(), "resource record length exceeds data") {
  1133  		t.Errorf("unexpected error message: %v", err)
  1134  	}
  1135  }
  1136  
  1137  func TestDNSPacketWriteAnswer(t *testing.T) {
  1138  	dns := &DNS{ID: 0x1234, QR: true, OpCode: DNSOpCodeQuery, ResponseCode: DNSResponseCodeNoErr, Answers: []DNSResourceRecord{
  1139  		DNSResourceRecord{
  1140  			Name:  []byte("www.example.com"),
  1141  			Type:  DNSTypeA,
  1142  			Class: DNSClassIN,
  1143  			IP:    net.IPv4(127, 0, 0, 1),
  1144  		},
  1145  		DNSResourceRecord{
  1146  			Name:  []byte("www.example.com"),
  1147  			Type:  DNSTypeAAAA,
  1148  			Class: DNSClassIN,
  1149  			IP:    net.IP{15: 1},
  1150  		},
  1151  	}}
  1152  	buf := gopacket.NewSerializeBuffer()
  1153  	opts := gopacket.SerializeOptions{ComputeChecksums: true, FixLengths: true}
  1154  	if err := gopacket.SerializeLayers(buf, opts, dns); err != nil {
  1155  		t.Fatal(err)
  1156  	}
  1157  	dns2 := &DNS{}
  1158  	if err := dns2.DecodeFromBytes(buf.Bytes(), gopacket.NilDecodeFeedback); err != nil {
  1159  		t.Fatalf("could not decode: %v", err)
  1160  	}
  1161  	if want, got := 2, len(dns2.Answers); want != got {
  1162  		t.Fatalf("num answers, want %d got %d", want, got)
  1163  	} else if got, want := string(dns2.Answers[0].Name), "www.example.com"; got != want {
  1164  		t.Fatalf("unexpected first answer name %q, want %q", got, want)
  1165  	} else if got, want := string(dns2.Answers[1].Name), "www.example.com"; got != want {
  1166  		t.Fatalf("unexpected second answer name %q, want %q", got, want)
  1167  	}
  1168  	t.Log(gopacket.LayerString(dns2))
  1169  	if want, got := 86, len(buf.Bytes()); want != got {
  1170  		t.Fatalf("Encoded size, want %d got %d", want, got)
  1171  	}
  1172  }