gosnmp
/
marshal_test.go
2042 строки · 64.0 Кб
1// Copyright 2012 The GoSNMP Authors. All rights reserved. Use of this
2// source code is governed by a BSD-style license that can be found in the
3// LICENSE file.
4
5//go:build all || marshal
6// +build all marshal
7
8package gosnmp9
10import (11"bytes"12"encoding/hex"13"fmt"14"io"15"log"16"net"17"reflect"18"runtime"19"strconv"20"strings"21"testing"22"time"23
24"github.com/stretchr/testify/assert"25)
26
27// Tests in alphabetical order of function being tested
28
29// -- Enmarshal ----------------------------------------------------------------
30
31// "Enmarshal" not "Marshal" - easier to select tests via a regex
32
33type testsEnmarshalVarbindPosition struct {34oid string35
36/*37start and finish position of bytes are calculated with application layer
38starting at byte 0. There are two ways to understand Wireshark dumps,
39switch between them:
40
411) the standard decode of the full packet - easier to understand
42what's actually happening
43
442) for counting byte positions: select "Simple Network Management
45Protocol" line in Wiresharks middle pane, then right click and choose
46"Export Packet Bytes..." (as .raw). Open the capture in wireshark, it
47will decode as "BER Encoded File". Click on each varbind and the
48"packet bytes" window will highlight the corresponding bytes, then the
49start and end positions can be found.
50*/
51
52/*53go-bindata has changed output format. Old style is needed:
54
55go get -u github.com/jteeuwen/go-bindata/...
56git co 79847ab
57rm ~/go/bin/go-bindata # belts and braces
58go install
59~/go/bin/go-bindata -uncompressed *.pcap
60*/
61
62start int63finish int64pduType Asn1BER
65pduValue interface{}66}
67
68type testsEnmarshalT struct {69version SnmpVersion
70community string71requestType PDUType
72requestid uint3273msgid uint3274// function and function name returning bytes from tcpdump75goodBytes func() []byte76funcName string // could do this via reflection77// start position of the pdu78pduStart int79// start position of the vbl80vblStart int81// finish position of pdu, vbl and message - all the same82finish int83// a slice of positions containing start and finish of each varbind84vbPositions []testsEnmarshalVarbindPosition85}
86
87var testsEnmarshal = []testsEnmarshalT{88{89Version2c,90"public",91GetRequest,921871507044,930,94kyoceraRequestBytes,95"kyocera_request",960x0e, // pdu start970x1d, // vbl start980xa0, // finish99[]testsEnmarshalVarbindPosition{100{".1.3.6.1.2.1.1.7.0", 0x20, 0x2d, Null, nil},101{".1.3.6.1.2.1.2.2.1.10.1", 0x2e, 0x3d, Null, nil},102{".1.3.6.1.2.1.2.2.1.5.1", 0x3e, 0x4d, Null, nil},103{".1.3.6.1.2.1.1.4.0", 0x4e, 0x5b, Null, nil},104{".1.3.6.1.2.1.43.5.1.1.15.1", 0x5c, 0x6c, Null, nil},105{".1.3.6.1.2.1.4.21.1.1.127.0.0.1", 0x6d, 0x7f, Null, nil},106{".1.3.6.1.4.1.23.2.5.1.1.1.4.2", 0x80, 0x92, Null, nil},107{".1.3.6.1.2.1.1.3.0", 0x93, 0xa0, Null, nil},108},109},110{111Version1,112"privatelab",113SetRequest,114526895288,1150,116portOnOutgoing1,117"portOnOutgoing1",1180x11, // pdu start1190x1f, // vbl start1200x36, // finish121[]testsEnmarshalVarbindPosition{122{".1.3.6.1.4.1.318.1.1.4.4.2.1.3.5", 0x21, 0x36, Integer, 1},123},124},125{126Version1,127"privatelab",128SetRequest,1291826072803,1300,131portOffOutgoing1,132"portOffOutgoing1",1330x11, // pdu start1340x1f, // vbl start1350x36, // finish136[]testsEnmarshalVarbindPosition{137{".1.3.6.1.4.1.318.1.1.4.4.2.1.3.5", 0x21, 0x36, Integer, 2},138},139},140// MrSpock Set stuff141{142Version2c,143"private",144SetRequest,145756726019,1460,147setOctet1,148"setOctet1",1490x0e, // pdu start1500x1c, // vbl start1510x32, // finish152[]testsEnmarshalVarbindPosition{153{".1.3.6.1.4.1.2863.205.1.1.75.1.0",1540x1e, 0x32, OctetString, []byte{0x80}},155},156},157{158Version2c,159"private",160SetRequest,1611000552357,1620,163setOctet2,164"setOctet2",1650x0e, // pdu start1660x1c, // vbl start1670x37, // finish168[]testsEnmarshalVarbindPosition{169{".1.3.6.1.4.1.2863.205.1.1.75.2.0",1700x1e, 0x36, OctetString, []byte("telnet")},171},172},173// MrSpock Set stuff174{175Version2c,176"private",177SetRequest,1781664317637,1790,180setInteger1,181"setInteger1",1820x0e, // pdu start1830x1c, // vbl start1840x7f, // finish185[]testsEnmarshalVarbindPosition{186{".1.3.6.1.4.1.2863.205.10.1.33.2.5.1.2.2", 0x1e, 0x36, Integer, 5001},187{".1.3.6.1.4.1.2863.205.10.1.33.2.5.1.3.2", 0x37, 0x4f, Integer, 5001},188{".1.3.6.1.4.1.2863.205.10.1.33.2.5.1.4.2", 0x50, 0x67, Integer, 2},189{".1.3.6.1.4.1.2863.205.10.1.33.2.5.1.5.2", 0x68, 0x7f, Integer, 1},190},191},192// Issue 35, empty responses.193{194Version2c,195"public",196GetRequest,1971883298028,1980,199emptyErrRequest,200"emptyErrRequest",2010x0d, // pdu start2020x1b, // vbl start2030x1c, // finish204[]testsEnmarshalVarbindPosition{},205},206// trap - TimeTicks207// snmptrap different with timetick 2, integer 5208
209// trap1 - capture is from frame - less work, decode easier210// varbinds - because Wireshark is decoding as BER's, need to subtract 2211// from start of varbinds212{213Version2c,214"public",215SNMPv2Trap,2161918693186,2170,218trap1,219"trap1",2200x0e, // pdu start2210x1c, // vbl start2220x82, // finish223[]testsEnmarshalVarbindPosition{224{".1.3.6.1.2.1.1.3.0", 0x1e, 0x2f, TimeTicks, uint32(18542501)},225{".1.3.6.1.6.3.1.1.4.1.0", 0x30, 0x45, ObjectIdentifier, ".1.3.6.1.2.1.1"},226{".1.3.6.1.2.1.1.1.0", 0x46, 0x59, OctetString, "red laptop"},227{".1.3.6.1.2.1.1.7.0", 0x5e, 0x6c, Integer, 5},228{".1.3.6.1.2.1.1.2", 0x6d, 0x82, ObjectIdentifier, ".1.3.6.1.4.1.2.3.4.5"},229},230},231}
232
233// helpers for Enmarshal tests
234
235// vbPosPdus returns a slice of oids in the given test
236func vbPosPdus(test testsEnmarshalT) (pdus []SnmpPDU) {237for _, vbp := range test.vbPositions {238pdu := SnmpPDU{Name: vbp.oid, Type: vbp.pduType, Value: vbp.pduValue}239pdus = append(pdus, pdu)240}241return242}
243
244// checkByteEquality walks the bytes in testBytes, and compares them to goodBytes
245func checkByteEquality(t *testing.T, test testsEnmarshalT, testBytes []byte,246start int, finish int) {247
248testBytesLen := len(testBytes)249
250goodBytes := test.goodBytes()251goodBytes = goodBytes[start : finish+1]252for cursor := range goodBytes {253if testBytesLen < cursor {254t.Errorf("%s: testBytesLen (%d) < cursor (%d)", test.funcName,255testBytesLen, cursor)256break257}258if testBytes[cursor] != goodBytes[cursor] {259t.Errorf("%s: cursor %d: testBytes != goodBytes:\n%s\n%s",260test.funcName,261cursor,262dumpBytes2("good", goodBytes, cursor),263dumpBytes2("test", testBytes, cursor))264break265}266}267}
268
269// Enmarshal tests in order that should be used for troubleshooting
270// ie check each varbind is working, then the varbind list, etc
271
272func TestEnmarshalVarbind(t *testing.T) {273Default.Logger = NewLogger(log.New(io.Discard, "", 0))274
275for _, test := range testsEnmarshal {276for j, test2 := range test.vbPositions {277snmppdu := &SnmpPDU{Name: test2.oid, Type: test2.pduType, Value: test2.pduValue}278testBytes, err := marshalVarbind(snmppdu)279if err != nil {280t.Errorf("#%s:%d:%s err returned: %v",281test.funcName, j, test2.oid, err)282}283
284checkByteEquality(t, test, testBytes, test2.start, test2.finish)285}286}287}
288
289func TestEnmarshalVBL(t *testing.T) {290Default.Logger = NewLogger(log.New(io.Discard, "", 0))291
292for _, test := range testsEnmarshal {293x := &SnmpPacket{294Community: test.community,295Version: test.version,296RequestID: test.requestid,297Variables: vbPosPdus(test),298}299
300testBytes, err := x.marshalVBL()301if err != nil {302t.Errorf("#%s: marshalVBL() err returned: %v", test.funcName, err)303}304
305checkByteEquality(t, test, testBytes, test.vblStart, test.finish)306}307}
308
309func TestEnmarshalPDU(t *testing.T) {310Default.Logger = NewLogger(log.New(io.Discard, "", 0))311
312for _, test := range testsEnmarshal {313x := &SnmpPacket{314Community: test.community,315Version: test.version,316PDUType: test.requestType,317RequestID: test.requestid,318Variables: vbPosPdus(test),319}320
321testBytes, err := x.marshalPDU()322if err != nil {323t.Errorf("#%s: marshalPDU() err returned: %v", test.funcName, err)324}325
326checkByteEquality(t, test, testBytes, test.pduStart, test.finish)327}328}
329
330func TestEnmarshalMsg(t *testing.T) {331Default.Logger = NewLogger(log.New(io.Discard, "", 0))332
333for _, test := range testsEnmarshal {334x := &SnmpPacket{335Community: test.community,336Version: test.version,337PDUType: test.requestType,338RequestID: test.requestid,339MsgID: test.msgid,340Variables: vbPosPdus(test),341}342
343testBytes, err := x.marshalMsg()344if err != nil {345t.Errorf("#%s: marshal() err returned: %v", test.funcName, err)346}347checkByteEquality(t, test, testBytes, 0, test.finish)348t.Run(fmt.Sprintf("TestEnmarshalMsgUnmarshal/PDU[%v]/RequestID[%v]", test.requestType, test.requestid), func(t *testing.T) {349vhandle := GoSNMP{}350vhandle.Logger = Default.Logger351result, err := vhandle.SnmpDecodePacket(testBytes)352if err != nil {353t.Errorf("#%s: SnmpDecodePacket() err returned: %v", test.funcName, err)354}355newResultTestBytes, err := result.marshalMsg()356if err != nil {357t.Errorf("#%s: marshal() err returned: %v", test.funcName, err)358}359if len(newResultTestBytes) == 0 {360t.Errorf("#%s: marshal() length of result is 0 : %v", test.funcName, (newResultTestBytes))361return362}363checkByteEquality(t, test, newResultTestBytes, 0, test.finish)364})365}366}
367
368// -- Unmarshal -----------------------------------------------------------------
369
370var testsUnmarshalErr = []struct {371in func() []byte372}{373{374panicUnmarshalHeader,375},376{377panicUnmarshalV3Header,378},379{380panicUnmarshalUserSecurityModelPacketLen,381},382{383panicUnmarshalV3HeaderFlagLen,384},385{386panicUnmarshalParseFloat32,387},388{389panicUnmarshalParseFloat64,390},391{392panicUnmarshalParseRawFieldTimeTicks,393},394{395panicUnmarshalDecryptPacketIndex,396},397{398panicUnmarshalDecryptNoPriv,399},400}
401
402var testsUnmarshal = []struct {403in func() []byte404out *SnmpPacket405}{406{kyoceraResponseBytes,407&SnmpPacket{408Version: Version2c,409Community: "public",410PDUType: GetResponse,411RequestID: 1066889284,412Error: 0,413ErrorIndex: 0,414Variables: []SnmpPDU{415{416Name: ".1.3.6.1.2.1.1.7.0",417Type: Integer,418Value: 104,419},420{421Name: ".1.3.6.1.2.1.2.2.1.10.1",422Type: Counter32,423Value: 271070065,424},425{426Name: ".1.3.6.1.2.1.2.2.1.5.1",427Type: Gauge32,428Value: 100000000,429},430{431Name: ".1.3.6.1.2.1.1.4.0",432Type: OctetString,433Value: []byte("Administrator"),434},435{436Name: ".1.3.6.1.2.1.43.5.1.1.15.1",437Type: Null,438Value: nil,439},440{441Name: ".1.3.6.1.2.1.4.21.1.1.127.0.0.1",442Type: IPAddress,443Value: "127.0.0.1",444},445{446Name: ".1.3.6.1.4.1.23.2.5.1.1.1.4.2",447Type: OctetString,448Value: []byte{0x00, 0x15, 0x99, 0x37, 0x76, 0x2b},449},450{451Name: ".1.3.6.1.2.1.1.3.0",452Type: TimeTicks,453Value: uint32(318870100),454},455},456},457},458{ciscoResponseBytes,459&SnmpPacket{460Version: Version2c,461Community: "public",462PDUType: GetResponse,463RequestID: 4876669,464Error: 0,465ErrorIndex: 0,466Variables: []SnmpPDU{467{468Name: ".1.3.6.1.2.1.1.7.0",469Type: Integer,470Value: 78,471},472{473Name: ".1.3.6.1.2.1.2.2.1.2.6",474Type: OctetString,475Value: []byte("GigabitEthernet0"),476},477{478Name: ".1.3.6.1.2.1.2.2.1.5.3",479Type: Gauge32,480Value: uint(4294967295),481},482{483Name: ".1.3.6.1.2.1.2.2.1.7.2",484Type: NoSuchInstance,485Value: nil,486},487{488Name: ".1.3.6.1.2.1.2.2.1.9.3",489Type: TimeTicks,490Value: uint32(2970),491},492{493Name: ".1.3.6.1.2.1.3.1.1.2.10.1.10.11.0.17",494Type: OctetString,495Value: []byte{0x00, 0x07, 0x7d, 0x4d, 0x09, 0x00},496},497{498Name: ".1.3.6.1.2.1.3.1.1.3.10.1.10.11.0.2",499Type: IPAddress,500Value: "10.11.0.2",501},502{503Name: ".1.3.6.1.2.1.4.20.1.1.110.143.197.1",504Type: IPAddress,505Value: "110.143.197.1",506},507{508Name: ".1.3.6.1.66.1",509Type: NoSuchObject,510Value: nil,511},512{513Name: ".1.3.6.1.2.1.1.2.0",514Type: ObjectIdentifier,515Value: ".1.3.6.1.4.1.9.1.1166",516},517},518},519},520{portOnIncoming1,521&SnmpPacket{522Version: Version1,523Community: "privatelab",524PDUType: GetResponse,525RequestID: 526895288,526Error: 0,527ErrorIndex: 0,528Variables: []SnmpPDU{529{530Name: ".1.3.6.1.4.1.318.1.1.4.4.2.1.3.5",531Type: Integer,532Value: 1,533},534},535},536},537{portOffIncoming1,538&SnmpPacket{539Version: Version1,540Community: "privatelab",541PDUType: GetResponse,542RequestID: 1826072803,543Error: 0,544ErrorIndex: 0,545Variables: []SnmpPDU{546{547Name: ".1.3.6.1.4.1.318.1.1.4.4.2.1.3.5",548Type: Integer,549Value: 2,550},551},552},553},554{ciscoGetnextResponseBytes,555&SnmpPacket{556Version: Version2c,557Community: "public",558PDUType: GetResponse,559RequestID: 1528674030,560Error: 0,561ErrorIndex: 0,562Variables: []SnmpPDU{563{564Name: ".1.3.6.1.2.1.3.1.1.3.2.1.192.168.104.2",565Type: IPAddress,566Value: "192.168.104.2",567},568{569Name: ".1.3.6.1.2.1.92.1.2.1.0",570Type: Counter32,571Value: 0,572},573{574Name: ".1.3.6.1.2.1.1.9.1.3.3",575Type: OctetString,576Value: []byte("The MIB module for managing IP and ICMP implementations"),577},578{579Name: ".1.3.6.1.2.1.1.9.1.4.2",580Type: TimeTicks,581Value: 21,582},583{584Name: ".1.3.6.1.2.1.2.1.0",585Type: Integer,586Value: 3,587},588{589Name: ".1.3.6.1.2.1.1.2.0",590Type: ObjectIdentifier,591Value: ".1.3.6.1.4.1.8072.3.2.10",592},593},594},595},596{ciscoGetbulkResponseBytes,597&SnmpPacket{598Version: Version2c,599Community: "public",600PDUType: GetResponse,601RequestID: 250000266,602NonRepeaters: 0,603MaxRepetitions: 10,604Variables: []SnmpPDU{605{606Name: ".1.3.6.1.2.1.1.9.1.4.1",607Type: TimeTicks,608Value: 21,609},610{611Name: ".1.3.6.1.2.1.1.9.1.4.2",612Type: TimeTicks,613Value: 21,614},615{616Name: ".1.3.6.1.2.1.1.9.1.4.3",617Type: TimeTicks,618Value: 21,619},620{621Name: ".1.3.6.1.2.1.1.9.1.4.4",622Type: TimeTicks,623Value: 21,624},625{626Name: ".1.3.6.1.2.1.1.9.1.4.5",627Type: TimeTicks,628Value: 21,629},630{631Name: ".1.3.6.1.2.1.1.9.1.4.6",632Type: TimeTicks,633Value: 23,634},635{636Name: ".1.3.6.1.2.1.1.9.1.4.7",637Type: TimeTicks,638Value: 23,639},640{641Name: ".1.3.6.1.2.1.1.9.1.4.8",642Type: TimeTicks,643Value: 23,644},645{646Name: ".1.3.6.1.2.1.2.1.0",647Type: Integer,648Value: 3,649},650{651Name: ".1.3.6.1.2.1.2.2.1.1.1",652Type: Integer,653Value: 1,654},655},656},657},658{emptyErrResponse,659&SnmpPacket{660Version: Version2c,661Community: "public",662PDUType: GetResponse,663RequestID: 1883298028,664Error: 0,665Variables: []SnmpPDU{},666},667},668{counter64Response,669&SnmpPacket{670Version: Version2c,671Community: "public",672PDUType: GetResponse,673RequestID: 190378322,674Error: 0,675ErrorIndex: 0,676Variables: []SnmpPDU{677{678Name: ".1.3.6.1.2.1.31.1.1.1.10.1",679Type: Counter64,680Value: uint64(1527943),681},682},683},684},685{opaqueFloatResponse,686&SnmpPacket{687Version: Version2c,688Community: "public",689PDUType: GetResponse,690RequestID: 601216773,691Error: 0,692ErrorIndex: 0,693Variables: []SnmpPDU{694{695Name: ".1.3.6.1.4.1.6574.4.2.12.1.0",696Type: OpaqueFloat,697Value: float32(10.0),698},699},700},701},702{opaqueResponse,703&SnmpPacket{704Version: Version1,705Community: "public",706PDUType: GetResponse,707RequestID: 2033938493,708Error: 0,709ErrorIndex: 0,710Variables: []SnmpPDU{711{712Name: ".1.3.6.1.4.1.34187.74195.2.1.24590",713Type: Opaque,714Value: []byte{0x41, 0xf0, 0x00, 0x00},715},716},717},718},719{opaqueDoubleResponse,720&SnmpPacket{721Version: Version2c,722Community: "public",723PDUType: GetResponse,724RequestID: 601216773,725Error: 0,726ErrorIndex: 0,727Variables: []SnmpPDU{728{729Name: ".1.3.6.1.4.1.6574.4.2.12.1.0",730Type: OpaqueDouble,731Value: float64(10.0),732},733},734},735},736{snmpv3HelloRequest,737&SnmpPacket{738Version: Version3,739PDUType: GetRequest,740MsgID: 91040642,741RequestID: 1157240545,742Error: 0,743ErrorIndex: 0,744Variables: []SnmpPDU{},745},746},747{snmpv3HelloResponse,748&SnmpPacket{749Version: Version3,750PDUType: Report,751MsgID: 91040642,752RequestID: 1157240545,753Error: 0,754ErrorIndex: 0,755Variables: []SnmpPDU{756{757Name: ".1.3.6.1.6.3.15.1.1.4.0",758Type: Counter32,759Value: 21,760},761},762},763},764}
765
766func TestUnmarshalErrors(t *testing.T) {767Default.Logger = NewLogger(log.New(io.Discard, "", 0))768
769for i, test := range testsUnmarshalErr {770funcName := runtime.FuncForPC(reflect.ValueOf(test.in).Pointer()).Name()771splitedFuncName := strings.Split(funcName, ".")772funcName = splitedFuncName[len(splitedFuncName)-1]773t.Run(fmt.Sprintf("%v-%v", i, funcName), func(t *testing.T) {774vhandle := GoSNMP{}775vhandle.Logger = Default.Logger776testBytes := test.in()777_, err := vhandle.SnmpDecodePacket(testBytes)778if err == nil {779t.Errorf("#%s: SnmpDecodePacket() err expected, but not returned", funcName)780}781})782}783}
784
785func FuzzUnmarshal(f *testing.F) {786for _, test := range testsUnmarshalErr {787f.Add(test.in())788}789
790for _, test := range testsUnmarshal {791f.Add(test.in())792}793
794vhandle := GoSNMP{}795vhandle.Logger = Default.Logger796f.Fuzz(func(t *testing.T, data []byte) {797stime := time.Now()798_, _ = vhandle.SnmpDecodePacket(data)799
800if e := time.Since(stime); e > (time.Second * 1) {801t.Errorf("SnmpDecodePacket() took too long: %s", e)802}803})804}
805
806func TestUnmarshal(t *testing.T) {807Default.Logger = NewLogger(log.New(io.Discard, "", 0))808
809for i, test := range testsUnmarshal {810funcName := runtime.FuncForPC(reflect.ValueOf(test.in).Pointer()).Name()811splitedFuncName := strings.Split(funcName, ".")812funcName = splitedFuncName[len(splitedFuncName)-1]813t.Run(fmt.Sprintf("%v-%v", i, funcName), func(t *testing.T) {814vhandle := GoSNMP{}815vhandle.Logger = Default.Logger816testBytes := test.in()817res, err := vhandle.SnmpDecodePacket(testBytes)818if err != nil {819t.Errorf("#%s: SnmpDecodePacket() err returned: %v", funcName, err)820}821t.Run("unmarshal", func(t *testing.T) {822// test "header" fields823if res.Version != test.out.Version {824t.Errorf("#%d Version result: %v, test: %v", i, res.Version, test.out.Version)825}826if res.Community != test.out.Community {827t.Errorf("#%d Community result: %v, test: %v", i, res.Community, test.out.Community)828}829if res.PDUType != test.out.PDUType {830t.Errorf("#%d PDUType result: %v, test: %v", i, res.PDUType, test.out.PDUType)831}832if res.RequestID != test.out.RequestID {833t.Errorf("#%d RequestID result: %v, test: %v", i, res.RequestID, test.out.RequestID)834}835if res.Error != test.out.Error {836t.Errorf("#%d Error result: %v, test: %v", i, res.Error, test.out.Error)837}838if res.ErrorIndex != test.out.ErrorIndex {839t.Errorf("#%d ErrorIndex result: %v, test: %v", i, res.ErrorIndex, test.out.ErrorIndex)840}841
842// test varbind values843for n, vb := range test.out.Variables {844if len(res.Variables) < n {845t.Errorf("#%d:%d ran out of varbind results", i, n)846return847}848vbr := res.Variables[n]849
850if vbr.Name != vb.Name {851t.Errorf("#%d:%d Name result: %v, test: %v", i, n, vbr.Name, vb.Name)852}853if vbr.Type != vb.Type {854t.Errorf("#%d:%d Type result: %v, test: %v", i, n, vbr.Type, vb.Type)855}856
857switch vb.Type {858case Integer, Gauge32, Counter32, TimeTicks, Counter64:859vbval := ToBigInt(vb.Value)860vbrval := ToBigInt(vbr.Value)861if vbval.Cmp(vbrval) != 0 {862t.Errorf("#%d:%d Value result: %v, test: %v", i, n, vbr.Value, vb.Value)863}864case OctetString, Opaque:865if !bytes.Equal(vb.Value.([]byte), vbr.Value.([]byte)) {866t.Errorf("#%d:%d Value result: %v, test: %v", i, n, vbr.Value, vb.Value)867}868case IPAddress, ObjectIdentifier:869if vb.Value != vbr.Value {870t.Errorf("#%d:%d Value result: %v, test: %v", i, n, vbr.Value, vb.Value)871}872case Null, NoSuchObject, NoSuchInstance:873if (vb.Value != nil) || (vbr.Value != nil) {874t.Errorf("#%d:%d Value result: %v, test: %v", i, n, vbr.Value, vb.Value)875}876case OpaqueFloat:877if vb.Value.(float32) != vbr.Value.(float32) {878t.Errorf("#%d:%d Value result: %v, test: %v", i, n, vbr.Value, vb.Value)879}880case OpaqueDouble:881if vb.Value.(float64) != vbr.Value.(float64) {882t.Errorf("#%d:%d Value result: %v, test: %v", i, n, vbr.Value, vb.Value)883}884default:885t.Errorf("#%d:%d Unhandled case result: %v, test: %v", i, n, vbr.Value, vb.Value)886}887
888}889})890t.Run("remarshal", func(t *testing.T) {891result, err := res.marshalMsg()892if err != nil {893t.Fatalf("#%s: marshalMsg() err returned: %v", funcName, err)894}895resNew, err := vhandle.SnmpDecodePacket(result)896if err != nil {897t.Fatalf("#%s: SnmpDecodePacket() err returned: %v", funcName, err)898}899assert.EqualValues(t, res, resNew)900
901})902})903
904}905}
906
907// -----------------------------------------------------------------------------
908
909/*
910
911* byte dumps generated using tcpdump and github.com/jteeuwen/go-bindata eg
912`sudo tcpdump -s 0 -i eth0 -w cisco.pcap host 203.50.251.17 and port 161`
913
914* Frame, Ethernet II, IP and UDP layers removed from generated bytes
915*/
916
917/*
918panicUnmarshalHeader tests a boundary condition that results in a panic
919when unmarshalling the SNMP header (see also https://github.com/gosnmp/gosnmp/issues/440)
920*/
921func panicUnmarshalHeader() []byte {922return []byte("0\x04\x02\x020\x03")923}
924
925/*
926panicUnmarshalV3Header tests a boundary condition that results in a panic
927when unmarshalling the SNMPv3.
928*/
929func panicUnmarshalV3Header() []byte {930return []byte{9310x30, 0x81, 0x95, 0x02, 0x01, 0x03, 0x30, 0x30, 0x43, 0x04, 0x30, 0x30, 0x30, 0x30, 0x43, 0x03,9320x30, 0x30, 0x30, 0x04, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,9330x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,9340x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,9350x30, 0x30, 0x30, 0x30, 0x30, 0x04, 0x51, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,9360x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,9370x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,9380x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,9390x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,9400x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,941}942}
943
944/*
945panicUnmarshalUserSecurityModelPacketLen() tests a boundary condition that results in a panic
946when indexing into the packet when processing the User Security Model.
947*/
948func panicUnmarshalUserSecurityModelPacketLen() []byte {949return []byte{9500x30, 0x81, 0x95, 0x02, 0x01, 0x03, 0x30, 0x30, 0x43, 0x04, 0x30, 0x30, 0x30, 0x30, 0x43, 0x03,9510x30, 0x30, 0x30, 0x43, 0x01, 0x30, 0x43, 0x01, 0x30, 0x04, 0xfd, 0x30, 0x30, 0x30, 0x30, 0x30,9520x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,9530x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,9540x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,9550x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,9560x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,9570x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,9580x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,9590x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,960}961}
962
963/*
964panicUnmarshalV3HeaderFlagLen tests a boundary condition that results in a panic
965when indexing into Flags without checking the length.
966*/
967func panicUnmarshalV3HeaderFlagLen() []byte {968return []byte{9690x30, 0x7e, 0x02, 0x01, 0x03, 0x30, 0x30, 0x43, 0x04, 0x30, 0x30, 0x30, 0x30, 0x43, 0x03, 0x30,9700x30, 0x30, 0x04, 0x00, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,9710x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,9720x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,9730x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,9740x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,9750x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,9760x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,977}978}
979
980/*
981panicUnmarshalParseFloat32() tests a boundary condition that results in a panic
982in parseFloat32 when handling malformed data.
983*/
984func panicUnmarshalParseFloat32() []byte {985return []byte{9860x30, 0x34, 0x43, 0x01, 0x30, 0x43, 0x06, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0xa2, 0x27, 0x43,9870x04, 0x30, 0x30, 0x30, 0x30, 0x43, 0x01, 0x30, 0x43, 0x01, 0x30, 0x30, 0x19, 0x30, 0x30, 0x06,9880x0c, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x44, 0x07, 0x9f,9890x78, 0x00, 0x30, 0x30, 0x30, 0x30,990}991}
992
993/*
994panicUnmarshalParseFloat64() tests a boundary condition that results in a panic
995in parseFloat64 when handling malformed data.
996*/
997func panicUnmarshalParseFloat64() []byte {998return []byte{9990x30, 0x38, 0x43, 0x01, 0x30, 0x43, 0x06, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0xa2, 0x2b, 0x43,10000x04, 0x30, 0x30, 0x30, 0x30, 0x43, 0x01, 0x30, 0x43, 0x01, 0x30, 0x30, 0x1d, 0x30, 0x30, 0x06,10010x0c, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x44, 0x0b, 0x9f,10020x79, 0x80, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,1003}1004}
1005
1006/*
1007panicUnmarshalParseRawFieldTimeTicks() tests a boundary condition that results in a panic
1008in parseRawField TimeTicks type when parseLength overflows the length value returning a value
1009for cursor that is higher than length.
1010*/
1011func panicUnmarshalParseRawFieldTimeTicks() []byte {1012return []byte{10130x30, 0x81, 0xc5, 0x43, 0x01, 0x30, 0x43, 0x06, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0xa2, 0x81,10140xb7, 0x43, 0x04, 0x30, 0x30, 0x30, 0x30, 0x43, 0x01, 0x30, 0x43, 0xeb, 0x30, 0x30, 0x30, 0x30,10150x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,10160x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,10170x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,10180x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,10190x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,10200x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0xff,10210xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,10220x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,10230x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,10240x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,10250x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,1026}1027}
1028
1029/*
1030panicUnmarshalDecryptPacketIndex() tests a boundary condition that results in a panic
1031in decryptPacket when handling malformed data.
1032*/
1033func panicUnmarshalDecryptPacketIndex() []byte {1034return []byte{10350x30, 0x52, 0x02, 0x01, 0x03, 0x30, 0x30, 0x43, 0x04, 0x30, 0x30, 0x30, 0x30, 0x43, 0x03, 0x30,10360x30, 0x30, 0x43, 0x01, 0x30, 0x43, 0x01, 0x30, 0x04, 0x30, 0x30, 0x30, 0x43, 0x00, 0x43, 0x01,10370x30, 0x43, 0x01, 0x30, 0x43, 0x00, 0x43, 0x00, 0x04, 0x2a, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,10380x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,10390x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,10400x30, 0x30, 0x30, 0x30,1041}1042}
1043
1044/*
1045panicUnmarshalDecryptPacketIndex() tests a boundary condition that results in a panic
1046in UsmSecurityParameters.decryptPacket() when handling malformed data.
1047*/
1048func panicUnmarshalDecryptNoPriv() []byte {1049return []byte{10500x30, 0x52, 0x02, 0x01, 0x03, 0x30, 0x30, 0x43, 0x04, 0x30, 0x30, 0x30, 0x30, 0x43, 0x03, 0x30,10510x30, 0x30, 0x43, 0x01, 0x30, 0x43, 0x01, 0x30, 0x04, 0x30, 0x30, 0x30, 0x43, 0x00, 0x43, 0x01,10520x30, 0x43, 0x01, 0x30, 0x43, 0x00, 0x43, 0x00, 0x43, 0x00, 0x04, 0x30, 0x30, 0x30, 0x30, 0x30,10530x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,10540x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,10550x30, 0x30, 0x30, 0x30,1056}1057}
1058
1059/*
1060kyoceraResponseBytes corresponds to the response section of this snmpget
1061
1062Simple Network Management Protocol
1063version: v2c (1)
1064community: public
1065data: get-response (2)
1066get-response
1067request-id: 1066889284
1068error-status: noError (0)
1069error-index: 0
1070variable-bindings: 8 items
10711.3.6.1.2.1.1.7.0: 104
10721.3.6.1.2.1.2.2.1.10.1: 271070065
10731.3.6.1.2.1.2.2.1.5.1: 100000000
10741.3.6.1.2.1.1.4.0: 41646d696e6973747261746f72
10751.3.6.1.2.1.43.5.1.1.15.1: Value (Null)
10761.3.6.1.2.1.4.21.1.1.127.0.0.1: 127.0.0.1 (127.0.0.1)
10771.3.6.1.4.1.23.2.5.1.1.1.4.2: 00159937762b
10781.3.6.1.2.1.1.3.0: 318870100
1079*/
1080
1081func kyoceraResponseBytes() []byte {1082return []byte{10830x30, 0x81, 0xc2, 0x02, 0x01, 0x01, 0x04, 0x06, 0x70, 0x75, 0x62, 0x6c,10840x69, 0x63, 0xa2, 0x81, 0xb4, 0x02, 0x04, 0x3f, 0x97, 0x70, 0x44, 0x02,10850x01, 0x00, 0x02, 0x01, 0x00, 0x30, 0x81, 0xa5, 0x30, 0x0d, 0x06, 0x08,10860x2b, 0x06, 0x01, 0x02, 0x01, 0x01, 0x07, 0x00, 0x02, 0x01, 0x68, 0x30,10870x12, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x02, 0x01, 0x02, 0x02, 0x01, 0x0a,10880x01, 0x41, 0x04, 0x10, 0x28, 0x33, 0x71, 0x30, 0x12, 0x06, 0x0a, 0x2b,10890x06, 0x01, 0x02, 0x01, 0x02, 0x02, 0x01, 0x05, 0x01, 0x42, 0x04, 0x05,10900xf5, 0xe1, 0x00, 0x30, 0x19, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x02, 0x01,10910x01, 0x04, 0x00, 0x04, 0x0d, 0x41, 0x64, 0x6d, 0x69, 0x6e, 0x69, 0x73,10920x74, 0x72, 0x61, 0x74, 0x6f, 0x72, 0x30, 0x0f, 0x06, 0x0b, 0x2b, 0x06,10930x01, 0x02, 0x01, 0x2b, 0x05, 0x01, 0x01, 0x0f, 0x01, 0x05, 0x00, 0x30,10940x15, 0x06, 0x0d, 0x2b, 0x06, 0x01, 0x02, 0x01, 0x04, 0x15, 0x01, 0x01,10950x7f, 0x00, 0x00, 0x01, 0x40, 0x04, 0x7f, 0x00, 0x00, 0x01, 0x30, 0x17,10960x06, 0x0d, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x17, 0x02, 0x05, 0x01, 0x01,10970x01, 0x04, 0x02, 0x04, 0x06, 0x00, 0x15, 0x99, 0x37, 0x76, 0x2b, 0x30,10980x10, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x02, 0x01, 0x01, 0x03, 0x00, 0x43,10990x04, 0x13, 0x01, 0x92, 0x54,1100}1101}
1102
1103/*
1104ciscoResponseBytes corresponds to the response section of this snmpget:
1105
1106% snmpget -On -v2c -c public 203.50.251.17 1.3.6.1.2.1.1.7.0 1.3.6.1.2.1.2.2.1.2.6 1.3.6.1.2.1.2.2.1.5.3 1.3.6.1.2.1.2.2.1.7.2 1.3.6.1.2.1.2.2.1.9.3 1.3.6.1.2.1.3.1.1.2.10.1.10.11.0.17 1.3.6.1.2.1.3.1.1.3.10.1.10.11.0.2 1.3.6.1.2.1.4.20.1.1.110.143.197.1 1.3.6.1.66.1 1.3.6.1.2.1.1.2.0
1107.1.3.6.1.2.1.1.7.0 = INTEGER: 78
1108.1.3.6.1.2.1.2.2.1.2.6 = STRING: GigabitEthernet0
1109.1.3.6.1.2.1.2.2.1.5.3 = Gauge32: 4294967295
1110.1.3.6.1.2.1.2.2.1.7.2 = No Such Instance currently exists at this OID
1111.1.3.6.1.2.1.2.2.1.9.3 = Timeticks: (2970) 0:00:29.70
1112.1.3.6.1.2.1.3.1.1.2.10.1.10.11.0.17 = Hex-STRING: 00 07 7D 4D 09 00
1113.1.3.6.1.2.1.3.1.1.3.10.1.10.11.0.2 = Network Address: 0A:0B:00:02
1114.1.3.6.1.2.1.4.20.1.1.110.143.197.1 = IPAddress: 110.143.197.1
1115.1.3.6.1.66.1 = No Such Object available on this agent at this OID
1116.1.3.6.1.2.1.1.2.0 = OID: .1.3.6.1.4.1.9.1.1166
1117*/
1118
1119func ciscoResponseBytes() []byte {1120return []byte{11210x30, 0x81,11220xf1, 0x02, 0x01, 0x01, 0x04, 0x06, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63,11230xa2, 0x81, 0xe3, 0x02, 0x03, 0x4a, 0x69, 0x7d, 0x02, 0x01, 0x00, 0x02,11240x01, 0x00, 0x30, 0x81, 0xd5, 0x30, 0x0d, 0x06, 0x08, 0x2b, 0x06, 0x01,11250x02, 0x01, 0x01, 0x07, 0x00, 0x02, 0x01, 0x4e, 0x30, 0x1e, 0x06, 0x0a,11260x2b, 0x06, 0x01, 0x02, 0x01, 0x02, 0x02, 0x01, 0x02, 0x06, 0x04, 0x10,11270x47, 0x69, 0x67, 0x61, 0x62, 0x69, 0x74, 0x45, 0x74, 0x68, 0x65, 0x72,11280x6e, 0x65, 0x74, 0x30, 0x30, 0x13, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x02,11290x01, 0x02, 0x02, 0x01, 0x05, 0x03, 0x42, 0x05, 0x00, 0xff, 0xff, 0xff,11300xff, 0x30, 0x0e, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x02, 0x01, 0x02, 0x02,11310x01, 0x07, 0x02, 0x81, 0x00, 0x30, 0x10, 0x06, 0x0a, 0x2b, 0x06, 0x01,11320x02, 0x01, 0x02, 0x02, 0x01, 0x09, 0x03, 0x43, 0x02, 0x0b, 0x9a, 0x30,11330x19, 0x06, 0x0f, 0x2b, 0x06, 0x01, 0x02, 0x01, 0x03, 0x01, 0x01, 0x02,11340x0a, 0x01, 0x0a, 0x0b, 0x00, 0x11, 0x04, 0x06, 0x00, 0x07, 0x7d, 0x4d,11350x09, 0x00, 0x30, 0x17, 0x06, 0x0f, 0x2b, 0x06, 0x01, 0x02, 0x01, 0x03,11360x01, 0x01, 0x03, 0x0a, 0x01, 0x0a, 0x0b, 0x00, 0x02, 0x40, 0x04, 0x0a,11370x0b, 0x00, 0x02, 0x30, 0x17, 0x06, 0x0f, 0x2b, 0x06, 0x01, 0x02, 0x01,11380x04, 0x14, 0x01, 0x01, 0x6e, 0x81, 0x0f, 0x81, 0x45, 0x01, 0x40, 0x04,11390x6e, 0x8f, 0xc5, 0x01, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x06, 0x01, 0x42,11400x01, 0x80, 0x00, 0x30, 0x15, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x02, 0x01,11410x01, 0x02, 0x00, 0x06, 0x09, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x09, 0x01,11420x89, 0x0e,1143}1144}
1145
1146/*
1147kyoceraRequestBytes corresponds to the request section of this snmpget:
1148
1149snmpget -On -v2c -c public 192.168.1.10 1.3.6.1.2.1.1.7.0 1.3.6.1.2.1.2.2.1.10.1 1.3.6.1.2.1.2.2.1.5.1 1.3.6.1.2.1.1.4.0 1.3.6.1.2.1.43.5.1.1.15.1 1.3.6.1.2.1.4.21.1.1.127.0.0.1 1.3.6.1.4.1.23.2.5.1.1.1.4.2 1.3.6.1.2.1.1.3.0
1150.1.3.6.1.2.1.1.7.0 = INTEGER: 104
1151.1.3.6.1.2.1.2.2.1.10.1 = Counter32: 144058856
1152.1.3.6.1.2.1.2.2.1.5.1 = Gauge32: 100000000
1153.1.3.6.1.2.1.1.4.0 = STRING: "Administrator"
1154.1.3.6.1.2.1.43.5.1.1.15.1 = NULL
1155.1.3.6.1.2.1.4.21.1.1.127.0.0.1 = IPAddress: 127.0.0.1
1156.1.3.6.1.4.1.23.2.5.1.1.1.4.2 = Hex-STRING: 00 15 99 37 76 2B
1157.1.3.6.1.2.1.1.3.0 = Timeticks: (120394900) 13 days, 22:25:49.00
1158*/
1159
1160func kyoceraRequestBytes() []byte {1161return []byte{11620x30, 0x81,11630x9e, 0x02, 0x01, 0x01, 0x04, 0x06, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63,11640xa0, 0x81, 0x90, 0x02, 0x04, 0x6f, 0x8c, 0xee, 0x64, 0x02, 0x01, 0x00,11650x02, 0x01, 0x00, 0x30, 0x81, 0x81, 0x30, 0x0c, 0x06, 0x08, 0x2b, 0x06,11660x01, 0x02, 0x01, 0x01, 0x07, 0x00, 0x05, 0x00, 0x30, 0x0e, 0x06, 0x0a,11670x2b, 0x06, 0x01, 0x02, 0x01, 0x02, 0x02, 0x01, 0x0a, 0x01, 0x05, 0x00,11680x30, 0x0e, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x02, 0x01, 0x02, 0x02, 0x01,11690x05, 0x01, 0x05, 0x00, 0x30, 0x0c, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x02,11700x01, 0x01, 0x04, 0x00, 0x05, 0x00, 0x30, 0x0f, 0x06, 0x0b, 0x2b, 0x06,11710x01, 0x02, 0x01, 0x2b, 0x05, 0x01, 0x01, 0x0f, 0x01, 0x05, 0x00, 0x30,11720x11, 0x06, 0x0d, 0x2b, 0x06, 0x01, 0x02, 0x01, 0x04, 0x15, 0x01, 0x01,11730x7f, 0x00, 0x00, 0x01, 0x05, 0x00, 0x30, 0x11, 0x06, 0x0d, 0x2b, 0x06,11740x01, 0x04, 0x01, 0x17, 0x02, 0x05, 0x01, 0x01, 0x01, 0x04, 0x02, 0x05,11750x00, 0x30, 0x0c, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x02, 0x01, 0x01, 0x03,11760x00, 0x05, 0x00,1177}1178}
1179
1180// === snmpset dumps ===
1181
1182/*
1183port_on_*1() correspond to this snmpset and response:
1184
1185snmpset -v 1 -c privatelab 192.168.100.124 .1.3.6.1.4.1.318.1.1.4.4.2.1.3.5 i 1
1186
1187Simple Network Management Protocol
1188version: version-1 (0)
1189community: privatelab
1190data: set-request (3)
1191set-request
1192request-id: 526895288
1193error-status: noError (0)
1194error-index: 0
1195variable-bindings: 1 item
11961.3.6.1.4.1.318.1.1.4.4.2.1.3.5:
1197Object Name: 1.3.6.1.4.1.318.1.1.4.4.2.1.3.5 (iso.3.6.1.4.1.318.1.1.4.4.2.1.3.5)
1198Value (Integer32): 1
1199
1200Simple Network Management Protocol
1201version: version-1 (0)
1202community: privatelab
1203data: get-response (2)
1204get-response
1205request-id: 526895288
1206error-status: noError (0)
1207error-index: 0
1208variable-bindings: 1 item
12091.3.6.1.4.1.318.1.1.4.4.2.1.3.5:
1210Object Name: 1.3.6.1.4.1.318.1.1.4.4.2.1.3.5 (iso.3.6.1.4.1.318.1.1.4.4.2.1.3.5)
1211Value (Integer32): 1
1212*/
1213
1214func portOnOutgoing1() []byte {1215return []byte{12160x30, 0x35, 0x02, 0x01, 0x00, 0x04, 0x0a, 0x70, 0x72, 0x69, 0x76, 0x61,12170x74, 0x65, 0x6c, 0x61, 0x62, 0xa3, 0x24, 0x02, 0x04, 0x1f, 0x67, 0xc8,12180xb8, 0x02, 0x01, 0x00, 0x02, 0x01, 0x00, 0x30, 0x16, 0x30, 0x14, 0x06,12190x0f, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0x3e, 0x01, 0x01, 0x04, 0x04,12200x02, 0x01, 0x03, 0x05, 0x02, 0x01, 0x01,1221}1222}
1223
1224func portOnIncoming1() []byte {1225return []byte{12260x30, 0x82, 0x00, 0x35, 0x02, 0x01, 0x00, 0x04, 0x0a, 0x70, 0x72, 0x69,12270x76, 0x61, 0x74, 0x65, 0x6c, 0x61, 0x62, 0xa2, 0x24, 0x02, 0x04, 0x1f,12280x67, 0xc8, 0xb8, 0x02, 0x01, 0x00, 0x02, 0x01, 0x00, 0x30, 0x16, 0x30,12290x14, 0x06, 0x0f, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0x3e, 0x01, 0x01,12300x04, 0x04, 0x02, 0x01, 0x03, 0x05, 0x02, 0x01, 0x01,1231}1232}
1233
1234/*
1235port_off_*1() correspond to this snmpset and response:
1236
1237snmpset -v 1 -c privatelab 192.168.100.124 .1.3.6.1.4.1.318.1.1.4.4.2.1.3.5 i 2
1238
1239Simple Network Management Protocol
1240version: version-1 (0)
1241community: privatelab
1242data: set-request (3)
1243set-request
1244request-id: 1826072803
1245error-status: noError (0)
1246error-index: 0
1247variable-bindings: 1 item
12481.3.6.1.4.1.318.1.1.4.4.2.1.3.5:
1249Object Name: 1.3.6.1.4.1.318.1.1.4.4.2.1.3.5 (iso.3.6.1.4.1.318.1.1.4.4.2.1.3.5)
1250Value (Integer32): 2
1251
1252Simple Network Management Protocol
1253version: version-1 (0)
1254community: privatelab
1255data: get-response (2)
1256get-response
1257request-id: 1826072803
1258error-status: noError (0)
1259error-index: 0
1260variable-bindings: 1 item
12611.3.6.1.4.1.318.1.1.4.4.2.1.3.5:
1262Object Name: 1.3.6.1.4.1.318.1.1.4.4.2.1.3.5 (iso.3.6.1.4.1.318.1.1.4.4.2.1.3.5)
1263Value (Integer32): 2
1264*/
1265
1266func portOffOutgoing1() []byte {1267return []byte{12680x30, 0x35, 0x02, 0x01, 0x00, 0x04, 0x0a, 0x70, 0x72, 0x69, 0x76, 0x61,12690x74, 0x65, 0x6c, 0x61, 0x62, 0xa3, 0x24, 0x02, 0x04, 0x6c, 0xd7, 0xa8,12700xe3, 0x02, 0x01, 0x00, 0x02, 0x01, 0x00, 0x30, 0x16, 0x30, 0x14, 0x06,12710x0f, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0x3e, 0x01, 0x01, 0x04, 0x04,12720x02, 0x01, 0x03, 0x05, 0x02, 0x01, 0x02,1273}1274}
1275
1276func portOffIncoming1() []byte {1277return []byte{12780x30, 0x82, 0x00, 0x35, 0x02, 0x01, 0x00, 0x04, 0x0a, 0x70, 0x72, 0x69,12790x76, 0x61, 0x74, 0x65, 0x6c, 0x61, 0x62, 0xa2, 0x24, 0x02, 0x04, 0x6c,12800xd7, 0xa8, 0xe3, 0x02, 0x01, 0x00, 0x02, 0x01, 0x00, 0x30, 0x16, 0x30,12810x14, 0x06, 0x0f, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0x3e, 0x01, 0x01,12820x04, 0x04, 0x02, 0x01, 0x03, 0x05, 0x02, 0x01, 0x02,1283}1284}
1285
1286// MrSpock START
1287
1288/*
1289setOctet1:
1290Simple Network Management Protocol
1291version: v2c (1)
1292community: private
1293data: set-request (3)
1294set-request
1295request-id: 756726019
1296error-status: noError (0)
1297error-index: 0
1298variable-bindings: 1 item
12991.3.6.1.4.1.2863.205.1.1.75.1.0: 80
1300Object Name: 1.3.6.1.4.1.2863.205.1.1.75.1.0 (iso.3.6.1.4.1.2863.205.1.1.75.1.0)
1301Value (OctetString): 80
1302
1303setOctet2:
1304Simple Network Management Protocol
1305version: v2c (1)
1306community: private
1307data: set-request (3)
1308set-request
1309request-id: 1000552357
1310error-status: noError (0)
1311error-index: 0
1312variable-bindings: 1 item
13131.3.6.1.4.1.2863.205.1.1.75.2.0: 74656c6e6574
1314Object Name: 1.3.6.1.4.1.2863.205.1.1.75.2.0 (iso.3.6.1.4.1.2863.205.1.1.75.2.0)
1315Value (OctetString): 74656c6e6574 ("telnet")
1316*/
1317
1318func setOctet1() []byte {1319return []byte{13200x30, 0x31, 0x02, 0x01, 0x01, 0x04, 0x07, 0x70, 0x72, 0x69, 0x76, 0x61,13210x74, 0x65, 0xa3, 0x23, 0x02, 0x04, 0x2d, 0x1a, 0xb9, 0x03, 0x02, 0x01,13220x00, 0x02, 0x01, 0x00, 0x30, 0x15, 0x30, 0x13, 0x06, 0x0e, 0x2b, 0x06,13230x01, 0x04, 0x01, 0x96, 0x2f, 0x81, 0x4d, 0x01, 0x01, 0x4b, 0x01, 0x00,13240x04, 0x01, 0x80,1325}1326}
1327
1328func setOctet2() []byte {1329return []byte{13300x30, 0x36, 0x02, 0x01, 0x01, 0x04, 0x07, 0x70, 0x72, 0x69, 0x76, 0x61,13310x74, 0x65, 0xa3, 0x28, 0x02, 0x04, 0x3b, 0xa3, 0x37, 0xa5, 0x02, 0x01,13320x00, 0x02, 0x01, 0x00, 0x30, 0x1a, 0x30, 0x18, 0x06, 0x0e, 0x2b, 0x06,13330x01, 0x04, 0x01, 0x96, 0x2f, 0x81, 0x4d, 0x01, 0x01, 0x4b, 0x02, 0x00,13340x04, 0x06, 0x74, 0x65, 0x6c, 0x6e, 0x65, 0x74,1335}1336}
1337
1338/* setInteger1:
1339snmpset -c private -v2c 10.80.0.14 \
1340.1.3.6.1.4.1.2863.205.10.1.33.2.5.1.2.2 i 5001 \
1341.1.3.6.1.4.1.2863.205.10.1.33.2.5.1.3.2 i 5001 \
1342.1.3.6.1.4.1.2863.205.10.1.33.2.5.1.4.2 i 2 \
1343.1.3.6.1.4.1.2863.205.10.1.33.2.5.1.5.2 i 1
1344
1345Simple Network Management Protocol
1346version: v2c (1)
1347community: private
1348data: set-request (3)
1349set-request
1350request-id: 1664317637
1351error-status: noError (0)
1352error-index: 0
1353variable-bindings: 4 items
13541.3.6.1.4.1.2863.205.10.1.33.2.5.1.2.2:
1355Object Name: 1.3.6.1.4.1.2863.205.10.1.33.2.5.1.2.2 (iso.3.6.1.4.1.2863.205.10.1.33.2.5.1.2.2)
1356Value (Integer32): 5001
13571.3.6.1.4.1.2863.205.10.1.33.2.5.1.3.2:
1358Object Name: 1.3.6.1.4.1.2863.205.10.1.33.2.5.1.3.2 (iso.3.6.1.4.1.2863.205.10.1.33.2.5.1.3.2)
1359Value (Integer32): 5001
13601.3.6.1.4.1.2863.205.10.1.33.2.5.1.4.2:
1361Object Name: 1.3.6.1.4.1.2863.205.10.1.33.2.5.1.4.2 (iso.3.6.1.4.1.2863.205.10.1.33.2.5.1.4.2)
1362Value (Integer32): 2
13631.3.6.1.4.1.2863.205.10.1.33.2.5.1.5.2:
1364Object Name: 1.3.6.1.4.1.2863.205.10.1.33.2.5.1.5.2 (iso.3.6.1.4.1.2863.205.10.1.33.2.5.1.5.2)
1365Value (Integer32): 1
1366*/
1367
1368func setInteger1() []byte {1369return []byte{13700x30, 0x7e, 0x02, 0x01, 0x01, 0x04, 0x07, 0x70, 0x72, 0x69, 0x76, 0x61,13710x74, 0x65, 0xa3, 0x70, 0x02, 0x04, 0x63, 0x33, 0x78, 0xc5, 0x02, 0x01,13720x00, 0x02, 0x01, 0x00, 0x30, 0x62, 0x30, 0x17, 0x06, 0x11, 0x2b, 0x06,13730x01, 0x04, 0x01, 0x96, 0x2f, 0x81, 0x4d, 0x0a, 0x01, 0x21, 0x02, 0x05,13740x01, 0x02, 0x02, 0x02, 0x02, 0x13, 0x89, 0x30, 0x17, 0x06, 0x11, 0x2b,13750x06, 0x01, 0x04, 0x01, 0x96, 0x2f, 0x81, 0x4d, 0x0a, 0x01, 0x21, 0x02,13760x05, 0x01, 0x03, 0x02, 0x02, 0x02, 0x13, 0x89, 0x30, 0x16, 0x06, 0x11,13770x2b, 0x06, 0x01, 0x04, 0x01, 0x96, 0x2f, 0x81, 0x4d, 0x0a, 0x01, 0x21,13780x02, 0x05, 0x01, 0x04, 0x02, 0x02, 0x01, 0x02, 0x30, 0x16, 0x06, 0x11,13790x2b, 0x06, 0x01, 0x04, 0x01, 0x96, 0x2f, 0x81, 0x4d, 0x0a, 0x01, 0x21,13800x02, 0x05, 0x01, 0x05, 0x02, 0x02, 0x01, 0x01,1381}1382}
1383
1384// MrSpock FINISH
1385
1386func ciscoGetnextResponseBytes() []byte {1387return []byte{13880x30, 0x81,13890xc8, 0x02, 0x01, 0x01, 0x04, 0x06, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63,13900xa2, 0x81, 0xba, 0x02, 0x04, 0x5b, 0x1d, 0xb6, 0xee, 0x02, 0x01, 0x00,13910x02, 0x01, 0x00, 0x30, 0x81, 0xab, 0x30, 0x19, 0x06, 0x11, 0x2b, 0x06,13920x01, 0x02, 0x01, 0x03, 0x01, 0x01, 0x03, 0x02, 0x01, 0x81, 0x40, 0x81,13930x28, 0x68, 0x02, 0x40, 0x04, 0xc0, 0xa8, 0x68, 0x02, 0x30, 0x0f, 0x06,13940x0a, 0x2b, 0x06, 0x01, 0x02, 0x01, 0x5c, 0x01, 0x02, 0x01, 0x00, 0x41,13950x01, 0x00, 0x30, 0x45, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x02, 0x01, 0x01,13960x09, 0x01, 0x03, 0x03, 0x04, 0x37, 0x54, 0x68, 0x65, 0x20, 0x4d, 0x49,13970x42, 0x20, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x20, 0x66, 0x6f, 0x72,13980x20, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x69, 0x6e, 0x67, 0x20, 0x49, 0x50,13990x20, 0x61, 0x6e, 0x64, 0x20, 0x49, 0x43, 0x4d, 0x50, 0x20, 0x69, 0x6d,14000x70, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e,14010x73, 0x30, 0x0f, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x02, 0x01, 0x01, 0x09,14020x01, 0x04, 0x02, 0x43, 0x01, 0x15, 0x30, 0x0d, 0x06, 0x08, 0x2b, 0x06,14030x01, 0x02, 0x01, 0x02, 0x01, 0x00, 0x02, 0x01, 0x03, 0x30, 0x16, 0x06,14040x08, 0x2b, 0x06, 0x01, 0x02, 0x01, 0x01, 0x02, 0x00, 0x06, 0x0a, 0x2b,14050x06, 0x01, 0x04, 0x01, 0xbf, 0x08, 0x03, 0x02, 0x0a,1406}1407}
1408
1409func ciscoGetnextRequestBytes() []byte {1410return []byte{14110x30, 0x7e,14120x02, 0x01, 0x01, 0x04, 0x06, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0xa1,14130x71, 0x02, 0x04, 0x5b, 0x1d, 0xb6, 0xee, 0x02, 0x01, 0x00, 0x02, 0x01,14140x00, 0x30, 0x63, 0x30, 0x15, 0x06, 0x11, 0x2b, 0x06, 0x01, 0x02, 0x01,14150x03, 0x01, 0x01, 0x03, 0x02, 0x01, 0x81, 0x40, 0x81, 0x28, 0x68, 0x01,14160x05, 0x00, 0x30, 0x0c, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x02, 0x01, 0x5c,14170x01, 0x02, 0x05, 0x00, 0x30, 0x0e, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x02,14180x01, 0x01, 0x09, 0x01, 0x03, 0x02, 0x05, 0x00, 0x30, 0x0e, 0x06, 0x0a,14190x2b, 0x06, 0x01, 0x02, 0x01, 0x01, 0x09, 0x01, 0x04, 0x01, 0x05, 0x00,14200x30, 0x0e, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x02, 0x01, 0x01, 0x09, 0x01,14210x04, 0x08, 0x05, 0x00, 0x30, 0x0c, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x02,14220x01, 0x01, 0x01, 0x00, 0x05, 0x00,1423}1424}
1425
1426/*
1427cisco getbulk bytes corresponds to this snmpbulkget command:
1428
1429$ snmpbulkget -v2c -cpublic 127.0.0.1:161 1.3.6.1.2.1.1.9.1.3.52
1430iso.3.6.1.2.1.1.9.1.4.1 = Timeticks: (21) 0:00:00.21
1431iso.3.6.1.2.1.1.9.1.4.2 = Timeticks: (21) 0:00:00.21
1432iso.3.6.1.2.1.1.9.1.4.3 = Timeticks: (21) 0:00:00.21
1433iso.3.6.1.2.1.1.9.1.4.4 = Timeticks: (21) 0:00:00.21
1434iso.3.6.1.2.1.1.9.1.4.5 = Timeticks: (21) 0:00:00.21
1435iso.3.6.1.2.1.1.9.1.4.6 = Timeticks: (23) 0:00:00.23
1436iso.3.6.1.2.1.1.9.1.4.7 = Timeticks: (23) 0:00:00.23
1437iso.3.6.1.2.1.1.9.1.4.8 = Timeticks: (23) 0:00:00.23
1438iso.3.6.1.2.1.2.1.0 = INTEGER: 3
1439iso.3.6.1.2.1.2.2.1.1.1 = INTEGER: 1
1440*/
1441func ciscoGetbulkRequestBytes() []byte {1442return []byte{14430x30, 0x2b,14440x02, 0x01, 0x01, 0x04, 0x06, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0xa5,14450x1e, 0x02, 0x04, 0x7d, 0x89, 0x68, 0xda, 0x02, 0x01, 0x00, 0x02, 0x01,14460x0a, 0x30, 0x10, 0x30, 0x0e, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x02, 0x01,14470x01, 0x09, 0x01, 0x03, 0x34, 0x05, 0x00, 0x00,1448}1449}
1450
1451func ciscoGetbulkResponseBytes() []byte {1452return []byte{14530x30, 0x81,14540xc5, 0x02, 0x01, 0x01, 0x04, 0x06, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63,14550xa2, 0x81, 0xb7, 0x02, 0x04, 0x0e, 0xe6, 0xb3, 0x8a, 0x02, 0x01, 0x00,14560x02, 0x01, 0x00, 0x30, 0x81, 0xa8, 0x30, 0x0f, 0x06, 0x0a, 0x2b, 0x06,14570x01, 0x02, 0x01, 0x01, 0x09, 0x01, 0x04, 0x01, 0x43, 0x01, 0x15, 0x30,14580x0f, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x02, 0x01, 0x01, 0x09, 0x01, 0x04,14590x02, 0x43, 0x01, 0x15, 0x30, 0x0f, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x02,14600x01, 0x01, 0x09, 0x01, 0x04, 0x03, 0x43, 0x01, 0x15, 0x30, 0x0f, 0x06,14610x0a, 0x2b, 0x06, 0x01, 0x02, 0x01, 0x01, 0x09, 0x01, 0x04, 0x04, 0x43,14620x01, 0x15, 0x30, 0x0f, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x02, 0x01, 0x01,14630x09, 0x01, 0x04, 0x05, 0x43, 0x01, 0x15, 0x30, 0x0f, 0x06, 0x0a, 0x2b,14640x06, 0x01, 0x02, 0x01, 0x01, 0x09, 0x01, 0x04, 0x06, 0x43, 0x01, 0x17,14650x30, 0x0f, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x02, 0x01, 0x01, 0x09, 0x01,14660x04, 0x07, 0x43, 0x01, 0x17, 0x30, 0x0f, 0x06, 0x0a, 0x2b, 0x06, 0x01,14670x02, 0x01, 0x01, 0x09, 0x01, 0x04, 0x08, 0x43, 0x01, 0x17, 0x30, 0x0d,14680x06, 0x08, 0x2b, 0x06, 0x01, 0x02, 0x01, 0x02, 0x01, 0x00, 0x02, 0x01,14690x03, 0x30, 0x0f, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x02, 0x01, 0x02, 0x02,14700x01, 0x01, 0x01, 0x02, 0x01, 0x01,1471}1472}
1473
1474/*
1475Issue 35, empty responses.
1476Simple Network Management Protocol
1477
1478version: v2c (1)
1479community: public
1480data: get-request (0)
1481get-request
1482request-id: 1883298028
1483error-status: noError (0)
1484error-index: 0
1485variable-bindings: 0 items
1486*/
1487func emptyErrRequest() []byte {1488return []byte{14890x30, 0x1b, 0x02, 0x01, 0x01, 0x04, 0x06, 0x70, 0x75, 0x62, 0x6c, 0x69,14900x63, 0xa0, 0x0e, 0x02, 0x04, 0x70, 0x40, 0xd8, 0xec, 0x02, 0x01, 0x00,14910x02, 0x01, 0x00, 0x30, 0x00,1492}1493}
1494
1495/*
1496Issue 35, empty responses.
1497
1498Simple Network Management Protocol
1499
1500version: v2c (1)
1501community: public
1502data: get-response (2)
1503get-response
1504request-id: 1883298028
1505error-status: noError (0)
1506error-index: 0
1507variable-bindings: 0 items
1508*/
1509func emptyErrResponse() []byte {1510return []byte{15110x30, 0x1b, 0x02, 0x01, 0x01, 0x04, 0x06, 0x70, 0x75, 0x62, 0x6c, 0x69,15120x63, 0xa2, 0x0e, 0x02, 0x04, 0x70, 0x40, 0xd8, 0xec, 0x02, 0x01, 0x00,15130x02, 0x01, 0x00, 0x30, 0x00,1514}1515}
1516
1517/*
1518Issue 15, test Counter64.
1519
1520Simple Network Management Protocol
1521
1522version: v2c (1)
1523community: public
1524data: get-response (2)
1525get-response
1526request-id: 190378322
1527error-status: noError (0)
1528error-index: 0
1529variable-bindings: 1 item
15301.3.6.1.2.1.31.1.1.1.10.1: 1527943
1531Object Name: 1.3.6.1.2.1.31.1.1.1.10.1 (iso.3.6.1.2.1.31.1.1.1.10.1)
1532Value (Counter64): 1527943
1533*/
1534func counter64Response() []byte {1535return []byte{15360x30, 0x2f, 0x02, 0x01, 0x01, 0x04, 0x06, 0x70, 0x75, 0x62, 0x6c, 0x69,15370x63, 0xa2, 0x22, 0x02, 0x04, 0x0b, 0x58, 0xf1, 0x52, 0x02, 0x01, 0x00,15380x02, 0x01, 0x00, 0x30, 0x14, 0x30, 0x12, 0x06, 0x0b, 0x2b, 0x06, 0x01,15390x02, 0x01, 0x1f, 0x01, 0x01, 0x01, 0x0a, 0x01, 0x46, 0x03, 0x17, 0x50,15400x87,1541}1542}
1543
1544/*
1545Issue 370, test Opaque.
1546
1547Simple Network Management Protocol
1548
1549version: 1 (1)
1550community: public
1551data: get-response (2)
1552get-response
1553request-id: 2033938493
1554error-status: noError (0)
1555error-index: 0
1556variable-bindings: 1 item
15571.3.6.1.4.1.34187.74195.2.1.24590: 41f00000
1558Object Name: 1.3.6.1.4.1.34187.74195.2.1.24590 (iso.3.6.1.4.1.34187.74195.2.1.24590)
1559Value (Opaque): 41f00000
1560*/
1561func opaqueResponse() []byte {1562return []byte{15630x30, 0x35, 0x02, 0x01, 0x00, 0x04, 0x06, 0x70, 0x75, 0x62, 0x6c, 0x69,15640x63, 0xa2, 0x28, 0x02, 0x04, 0x79, 0x3b, 0x70, 0x3d, 0x02, 0x01, 0x00,15650x02, 0x01, 0x00, 0x30, 0x1a, 0x30, 0x18, 0x06, 0x10, 0x2b, 0x06, 0x01,15660x04, 0x01, 0x82, 0x8b, 0x0b, 0x84, 0xc3, 0x53, 0x02, 0x01, 0x81, 0xc0,15670x0e, 0x44, 0x04, 0x41, 0xf0, 0x00, 0x00,1568}1569}
1570
1571/*
1572Opaque Float, observed from Synology NAS UPS MIB
1573
1574snmpget -v 2c -c public host 1.3.6.1.4.1.6574.4.2.12.1.0
1575*/
1576func opaqueFloatResponse() []byte {1577return []byte{15780x30, 0x34, 0x02, 0x01, 0x01, 0x04, 0x06, 0x70, 0x75, 0x62, 0x6c, 0x69,15790x63, 0xa2, 0x27, 0x02, 0x04, 0x23, 0xd5, 0xd7, 0x05, 0x02, 0x01, 0x00,15800x02, 0x01, 0x00, 0x30, 0x19, 0x30, 0x17, 0x06, 0x0c, 0x2b, 0x06, 0x01,15810x04, 0x01, 0xb3, 0x2e, 0x04, 0x02, 0x0c, 0x01, 0x00, 0x44, 0x07, 0x9f,15820x78, 0x04, 0x41, 0x20, 0x00, 0x00,1583}1584}
1585
1586/*
1587Opaque Double, not observed, crafted based on description:
1588
1589https://tools.ietf.org/html/draft-perkins-float-00
1590*/
1591func opaqueDoubleResponse() []byte {1592return []byte{15930x30, 0x38, 0x02, 0x01, 0x01, 0x04, 0x06, 0x70, 0x75, 0x62, 0x6c, 0x69,15940x63, 0xa2, 0x2b, 0x02, 0x04, 0x23, 0xd5, 0xd7, 0x05, 0x02, 0x01, 0x00,15950x02, 0x01, 0x00, 0x30, 0x1d, 0x30, 0x1b, 0x06, 0x0c, 0x2b, 0x06, 0x01,15960x04, 0x01, 0xb3, 0x2e, 0x04, 0x02, 0x0c, 0x01, 0x00, 0x44, 0x0b, 0x9f,15970x79, 0x08, 0x40, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,1598}1599}
1600
1601func TestUnmarshalEmptyPanic(t *testing.T) {1602var in = []byte{}1603var res = new(SnmpPacket)1604
1605_, err := Default.unmarshalHeader(in, res)1606if err == nil {1607t.Errorf("unmarshalHeader did not gracefully detect empty packet")1608}1609}
1610
1611func TestV3USMInitialPacket(t *testing.T) {1612logger := NewLogger(log.New(io.Discard, "", 0))1613var emptyPdus []SnmpPDU1614blankPacket := &SnmpPacket{1615Version: Version3,1616MsgFlags: Reportable | NoAuthNoPriv,1617SecurityModel: UserSecurityModel,1618SecurityParameters: &UsmSecurityParameters{Logger: logger},1619PDUType: GetRequest,1620Logger: logger,1621Variables: emptyPdus,1622}1623iBytes, err := blankPacket.marshalMsg()1624if err != nil {1625t.Errorf("#TestV3USMInitialPacket: marshalMsg() err returned: %v", err)1626}1627engine := GoSNMP{Logger: Default.Logger}1628pktNew, errDecode := engine.SnmpDecodePacket(iBytes)1629if errDecode != nil {1630t.Logf("-->Bytes=%v", iBytes)1631t.Logf("-->Expect=%v", blankPacket)1632t.Logf("-->got=%v", pktNew)1633t.Errorf("#TestV3USMInitialPacket: SnmpDecodePacket() err returned: %v. ", errDecode)1634}1635
1636}
1637
1638func TestSendOneRequest_dups(t *testing.T) {1639srvr, err := net.ListenUDP("udp4", &net.UDPAddr{})1640if err != nil {1641t.Fatalf("udp4 error listening: %s", err)1642}1643defer srvr.Close()1644
1645x := &GoSNMP{1646Version: Version2c,1647Target: srvr.LocalAddr().(*net.UDPAddr).IP.String(),1648Port: uint16(srvr.LocalAddr().(*net.UDPAddr).Port),1649Timeout: time.Millisecond * 100,1650Retries: 2,1651}1652if err := x.Connect(); err != nil {1653t.Fatalf("error connecting: %s", err)1654}1655
1656go func() {1657buf := make([]byte, 256)1658for {1659n, addr, err := srvr.ReadFrom(buf)1660if err != nil {1661return1662}1663buf := buf[:n]1664
1665var reqPkt SnmpPacket1666var cursor int1667cursor, err = x.unmarshalHeader(buf, &reqPkt)1668if err != nil {1669t.Errorf("error: %s", err)1670}1671// if x.Version == Version3 {1672// buf, cursor, err = x.decryptPacket(buf, cursor, &reqPkt)1673// if err != nil {1674// t.Errorf("error: %s", err)1675// }1676//}1677err = x.unmarshalPayload(buf, cursor, &reqPkt)1678if err != nil {1679t.Errorf("error: %s", err)1680}1681
1682rspPkt := x.mkSnmpPacket(GetResponse, []SnmpPDU{1683{1684Name: ".1.2",1685Type: Integer,1686Value: 123,1687},1688}, 0, 0)1689rspPkt.RequestID = reqPkt.RequestID1690outBuf, err := rspPkt.marshalMsg()1691if err != nil {1692t.Errorf("ERR: %s", err)1693}1694srvr.WriteTo(outBuf, addr)1695for i := 0; i <= x.Retries; i++ {1696srvr.WriteTo(outBuf, addr)1697}1698}1699}()1700
1701pdus := []SnmpPDU{{Name: ".1.2", Type: Null}}1702// This is not actually a GetResponse, but we need something our test server can unmarshal.1703reqPkt := x.mkSnmpPacket(GetResponse, pdus, 0, 0)1704
1705_, err = x.sendOneRequest(reqPkt, true)1706if err != nil {1707t.Errorf("error: %s", err)1708return1709}1710
1711_, err = x.sendOneRequest(reqPkt, true)1712if err != nil {1713t.Errorf("error: %s", err)1714return1715}1716}
1717
1718func BenchmarkSendOneRequest(b *testing.B) {1719b.StopTimer()1720
1721srvr, err := net.ListenUDP("udp4", &net.UDPAddr{})1722if err != nil {1723b.Fatalf("udp4 error listening: %s", err)1724}1725defer srvr.Close()1726
1727x := &GoSNMP{1728Version: Version2c,1729Target: srvr.LocalAddr().(*net.UDPAddr).IP.String(),1730Port: uint16(srvr.LocalAddr().(*net.UDPAddr).Port),1731Timeout: time.Millisecond * 100,1732Retries: 2,1733}1734if err := x.Connect(); err != nil {1735b.Fatalf("error connecting: %s", err)1736}1737
1738go func() {1739buf := make([]byte, 256)1740outBuf := counter64Response()1741for {1742_, addr, err := srvr.ReadFrom(buf)1743if err != nil {1744return1745}1746
1747copy(outBuf[17:21], buf[11:15]) // evil: copy request ID1748srvr.WriteTo(outBuf, addr)1749}1750}()1751
1752pdus := []SnmpPDU{{Name: ".1.3.6.1.2.1.31.1.1.1.10.1", Type: Null}}1753reqPkt := x.mkSnmpPacket(GetRequest, pdus, 0, 0)1754
1755// make sure everything works before starting the test1756_, err = x.sendOneRequest(reqPkt, true)1757if err != nil {1758b.Fatalf("Precheck failed: %s", err)1759}1760
1761b.StartTimer()1762
1763for n := 0; n < b.N; n++ {1764_, err = x.sendOneRequest(reqPkt, true)1765if err != nil {1766b.Fatalf("error: %s", err)1767return1768}1769}1770}
1771
1772func TestUnconnectedSocket_fail(t *testing.T) {1773withUnconnectedSocket(t, false)1774}
1775
1776func TestUnconnectedSocket_success(t *testing.T) {1777withUnconnectedSocket(t, true)1778}
1779
1780func withUnconnectedSocket(t *testing.T, enable bool) {1781srvr, err := net.ListenUDP("udp", &net.UDPAddr{})1782if err != nil {1783t.Fatalf("udp error listening: %s", err)1784}1785defer srvr.Close()1786
1787x := &GoSNMP{1788Version: Version2c,1789Target: srvr.LocalAddr().(*net.UDPAddr).IP.String(),1790Port: uint16(srvr.LocalAddr().(*net.UDPAddr).Port),1791Timeout: time.Millisecond * 100,1792Retries: 2,1793UseUnconnectedUDPSocket: enable,1794LocalAddr: "0.0.0.0:",1795}1796if err := x.Connect(); err != nil {1797t.Fatalf("error connecting: %s", err)1798}1799defer x.Conn.Close()1800
1801go func() {1802buf := make([]byte, 256)1803for {1804n, addr, err := srvr.ReadFrom(buf)1805if err != nil {1806return1807}1808buf := buf[:n]1809
1810var reqPkt SnmpPacket1811var cursor int1812cursor, err = x.unmarshalHeader(buf, &reqPkt)1813if err != nil {1814t.Errorf("error: %s", err)1815}1816err = x.unmarshalPayload(buf, cursor, &reqPkt)1817if err != nil {1818t.Errorf("error: %s", err)1819}1820
1821rspPkt := x.mkSnmpPacket(GetResponse, []SnmpPDU{1822{1823Name: ".1.2",1824Type: Integer,1825Value: 123,1826},1827}, 0, 0)1828rspPkt.RequestID = reqPkt.RequestID1829outBuf, err := rspPkt.marshalMsg()1830if err != nil {1831t.Errorf("ERR: %s", err)1832}1833// Temporary socket will use different source port, it's enough to break1834// connected socket reply filters.1835nsock, err := net.ListenUDP("udp", nil)1836if err != nil {1837t.Errorf("can't create temporary reply socket: %v", err)1838}1839nsock.WriteTo(outBuf, addr)1840nsock.Close()1841}1842}()1843
1844pdus := []SnmpPDU{{Name: ".1.2", Type: Null}}1845// This is not actually a GetResponse, but we need something our test server can unmarshal.1846reqPkt := x.mkSnmpPacket(GetResponse, pdus, 0, 0)1847
1848_, err = x.sendOneRequest(reqPkt, true)1849if err != nil && enable {1850t.Errorf("with unconnected socket enabled got unexpected error: %v", err)1851} else if err == nil && !enable {1852t.Errorf("with unconnected socket disabled didn't get an error")1853}1854}
1855
1856/*
1857$ snmptrap -v 2c -c public 192.168.1.10 '' SNMPv2-MIB::system SNMPv2-MIB::sysDescr.0 s "red laptop" SNMPv2-MIB::sysServices.0 i "5"
1858
1859Simple Network Management Protocol
1860version: v2c (1)
1861community: public
1862data: snmpV2-trap (7)
1863snmpV2-trap
1864request-id: 1271509950
1865error-status: noError (0)
1866error-index: 0
1867variable-bindings: 5 items
18681.3.6.1.2.1.1.3.0: 1034156
1869Object Name: 1.3.6.1.2.1.1.3.0 (iso.3.6.1.2.1.1.3.0)
1870Value (Timeticks): 1034156
18711.3.6.1.6.3.1.1.4.1.0: 1.3.6.1.2.1.1 (iso.3.6.1.2.1.1)
1872Object Name: 1.3.6.1.6.3.1.1.4.1.0 (iso.3.6.1.6.3.1.1.4.1.0)
1873Value (OID): 1.3.6.1.2.1.1 (iso.3.6.1.2.1.1)
18741.3.6.1.2.1.1.1.0: 726564206c6170746f70
1875Object Name: 1.3.6.1.2.1.1.1.0 (iso.3.6.1.2.1.1.1.0)
1876Value (OctetString): 726564206c6170746f70
1877Variable-binding-string: red laptop
18781.3.6.1.2.1.1.7.0:
1879Object Name: 1.3.6.1.2.1.1.7.0 (iso.3.6.1.2.1.1.7.0)
1880Value (Integer32): 5
18811.3.6.1.2.1.1.2: 1.3.6.1.4.1.2.3.4.5 (iso.3.6.1.4.1.2.3.4.5)
1882Object Name: 1.3.6.1.2.1.1.2 (iso.3.6.1.2.1.1.2)
1883Value (OID): 1.3.6.1.4.1.2.3.4.5 (iso.3.6.1.4.1.2.3.4.5)
1884*/
1885
1886func trap1() []byte {1887return []byte{18880x30, 0x81, 0x80, 0x02, 0x01, 0x01, 0x04, 0x06, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0xa7, 0x73,18890x02, 0x04, 0x72, 0x5c, 0xef, 0x42, 0x02, 0x01, 0x00, 0x02, 0x01, 0x00, 0x30, 0x65, 0x30, 0x10,18900x06, 0x08, 0x2b, 0x06, 0x01, 0x02, 0x01, 0x01, 0x03, 0x00, 0x43, 0x04, 0x01, 0x1a, 0xef, 0xa5,18910x30, 0x14, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x06, 0x03, 0x01, 0x01, 0x04, 0x01, 0x00, 0x06, 0x06,18920x2b, 0x06, 0x01, 0x02, 0x01, 0x01, 0x30, 0x16, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x02, 0x01, 0x01,18930x01, 0x00, 0x04, 0x0a, 0x72, 0x65, 0x64, 0x20, 0x6c, 0x61, 0x70, 0x74, 0x6f, 0x70, 0x30, 0x0d,18940x06, 0x08, 0x2b, 0x06, 0x01, 0x02, 0x01, 0x01, 0x07, 0x00, 0x02, 0x01, 0x05, 0x30, 0x14, 0x06,18950x07, 0x2b, 0x06, 0x01, 0x02, 0x01, 0x01, 0x02, 0x06, 0x09, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x02,18960x03, 0x04, 0x05, 0x00, 0x00, 0x00, 0xd0, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x68, 0x00,18970x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x74, 0x3a, 0x05, 0x00, 0xa1, 0x27, 0x42, 0x0c, 0x46, 0x00,18980x00, 0x00, 0x46, 0x00, 0x00, 0x00, 0x10, 0x4a, 0x7d, 0x34, 0x3a, 0xa5, 0x74, 0xda, 0x38, 0x4d,18990x6c, 0x6c, 0x08, 0x00, 0x45, 0x00, 0x00, 0x38, 0xcc, 0xdb, 0x40, 0x00, 0xff, 0x01, 0x2b, 0x74,19000xc0, 0xa8, 0x01, 0x0a, 0xc0, 0xa8, 0x01, 0x1a, 0x03, 0x03, 0x11, 0x67, 0x00, 0x00, 0x00, 0x00,19010x45, 0x00, 0x00, 0x9f, 0xe6, 0x8f, 0x40, 0x00, 0x40, 0x11, 0x00, 0x00, 0xc0, 0xa8, 0x01, 0x1a,19020xc0, 0xa8, 0x01, 0x0a, 0xaf, 0x78, 0x00, 0xa2, 0x00, 0x8b, 0x0b, 0x3a, 0x00, 0x00, 0x68, 0x00,19030x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x6c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x74, 0x3a,19040x05, 0x00, 0xca, 0x94, 0x67, 0x0c, 0x01, 0x00, 0x1c, 0x00, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x65,19050x72, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x64, 0x20, 0x62, 0x79, 0x20, 0x64,19060x75, 0x6d, 0x70, 0x63, 0x61, 0x70, 0x02, 0x00, 0x08, 0x00, 0x74, 0x3a, 0x05, 0x00, 0xdf, 0xba,19070x27, 0x0c, 0x03, 0x00, 0x08, 0x00, 0x74, 0x3a, 0x05, 0x00, 0x18, 0x94, 0x67, 0x0c, 0x04, 0x00,19080x08, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x08, 0x00, 0x00, 0x00,19090x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6c, 0x00, 0x00, 0x00}1910}
1911
1912// Simple Network Management Protocol
1913// msgVersion: snmpv3 (3)
1914// msgGlobalData
1915// msgID: 91040642
1916// msgMaxSize: 65507
1917// msgFlags: 04
1918// msgSecurityModel: USM (3)
1919// msgAuthoritativeEngineID: <MISSING>
1920// msgAuthoritativeEngineBoots: 0
1921// msgAuthoritativeEngineTime: 0
1922// msgUserName:
1923// msgAuthenticationParameters: <MISSING>
1924// msgPrivacyParameters: <MISSING>
1925// msgData: plaintext (0)
1926// plaintext
1927
1928func snmpv3HelloRequest() []byte {1929return []byte{0x30, 0x52, 0x02, 0x01, 0x03, 0x30, 0x11, 0x02,19300x04, 0x05, 0x6d, 0x2b, 0x82, 0x02, 0x03, 0x00,19310xff, 0xe3, 0x04, 0x01, 0x04, 0x02, 0x01, 0x03,19320x04, 0x10, 0x30, 0x0e, 0x04, 0x00, 0x02, 0x01,19330x00, 0x02, 0x01, 0x00, 0x04, 0x00, 0x04, 0x00,19340x04, 0x00, 0x30, 0x28, 0x04, 0x00, 0x04, 0x14,19350x66, 0x6f, 0x72, 0x65, 0x69, 0x67, 0x6e, 0x66,19360x6f, 0x72, 0x6d, 0x61, 0x74, 0x73, 0x2f, 0x6c,19370x69, 0x6e, 0x75, 0x78, 0xa0, 0x0e, 0x02, 0x04,19380x44, 0xfa, 0x16, 0xe1, 0x02, 0x01, 0x00, 0x02,19390x01, 0x00, 0x30, 0x00}1940}
1941
1942// msgData: plaintext (0)
1943// plaintext
1944// contextEngineID: 80004fb8054445534b544f502d4a3732533245343ab63bc8
1945// 1... .... = Engine ID Conformance: RFC3411 (SNMPv3)
1946// Engine Enterprise ID: pysnmp (20408)
1947// Engine ID Format: Octets, administratively assigned (5)
1948// Engine ID Data: 4445534b544f502d4a3732533245343ab63bc8
1949// contextName: foreignformats/linux
1950// data: report (8)
1951// report
1952// request-id: 1157240545
1953// error-status: noError (0)
1954// error-index: 0
1955// variable-bindings: 1 item
1956// 1.3.6.1.6.3.15.1.1.4.0: 21
1957// Object Name: 1.3.6.1.6.3.15.1.1.4.0 (iso.3.6.1.6.3.15.1.1.4.0)
1958// Value (Counter32): 21
1959
1960func snmpv3HelloResponse() []byte {1961return []byte{19620x30, 0x81, 0x95, 0x02, 0x01, 0x03, 0x30, 0x11,19630x02, 0x04, 0x05, 0x6d, 0x2b, 0x82, 0x02, 0x03,19640x00, 0xff, 0xe3, 0x04, 0x01, 0x00, 0x02, 0x01,19650x03, 0x04, 0x2a, 0x30, 0x28, 0x04, 0x18, 0x80,19660x00, 0x4f, 0xb8, 0x05, 0x44, 0x45, 0x53, 0x4b,19670x54, 0x4f, 0x50, 0x2d, 0x4a, 0x37, 0x32, 0x53,19680x32, 0x45, 0x34, 0x3a, 0xb6, 0x3b, 0xc8, 0x02,19690x01, 0x02, 0x02, 0x03, 0x00, 0xc4, 0x7a, 0x04,19700x00, 0x04, 0x00, 0x04, 0x00, 0x30, 0x51, 0x04,19710x18, 0x80, 0x00, 0x4f, 0xb8, 0x05, 0x44, 0x45,19720x53, 0x4b, 0x54, 0x4f, 0x50, 0x2d, 0x4a, 0x37,19730x32, 0x53, 0x32, 0x45, 0x34, 0x3a, 0xb6, 0x3b,19740xc8, 0x04, 0x14, 0x66, 0x6f, 0x72, 0x65, 0x69,19750x67, 0x6e, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74,19760x73, 0x2f, 0x6c, 0x69, 0x6e, 0x75, 0x78, 0xa8,19770x1f, 0x02, 0x04, 0x44, 0xfa, 0x16, 0xe1, 0x02,19780x01, 0x00, 0x02, 0x01, 0x00, 0x30, 0x11, 0x30,19790x0f, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x06, 0x03,19800x0f, 0x01, 0x01, 0x04, 0x00, 0x41, 0x01, 0x15,1981}1982}
1983
1984// dump bytes in a format similar to Wireshark
1985func dumpBytes1(data []byte, msg string, maxlength int) {1986var buffer bytes.Buffer1987buffer.WriteString(msg)1988length := maxlength1989if len(data) < maxlength {1990length = len(data)1991}1992length *= 2 //One Byte Symbols Two Hex1993hexStr := hex.EncodeToString(data)1994for i := 0; length >= i+16; i += 16 {1995buffer.WriteString("\n")1996buffer.WriteString(strconv.Itoa(i / 2))1997buffer.WriteString("\t")1998buffer.WriteString(hexStr[i : i+2])1999buffer.WriteString(" ")2000buffer.WriteString(hexStr[i+2 : i+4])2001buffer.WriteString(" ")2002buffer.WriteString(hexStr[i+4 : i+6])2003buffer.WriteString(" ")2004buffer.WriteString(hexStr[i+6 : i+8])2005buffer.WriteString(" ")2006buffer.WriteString(hexStr[i+8 : i+10])2007buffer.WriteString(" ")2008buffer.WriteString(hexStr[i+10 : i+12])2009buffer.WriteString(" ")2010buffer.WriteString(hexStr[i+12 : i+14])2011buffer.WriteString(" ")2012buffer.WriteString(hexStr[i+14 : i+16])2013}2014leftOver := length % 162015if leftOver != 0 {2016buffer.WriteString("\n")2017buffer.WriteString(strconv.Itoa((length - leftOver) / 2))2018buffer.WriteString("\t")2019for i := 0; leftOver >= i+2; i += 2 {2020buffer.WriteString(hexStr[i : i+2])2021buffer.WriteString(" ")2022}2023}2024buffer.WriteString("\n")2025}
2026
2027// dump bytes in one row, up to about screen width. Returns a string
2028// rather than (dumpBytes1) writing to debugging log.
2029func dumpBytes2(desc string, bb []byte, cursor int) string {2030cursor = cursor - 4 // give some context to dump2031if cursor < 0 {2032cursor = 02033}2034result := desc2035for i, b := range bb[cursor:] {2036if i > 30 { // about screen width...2037break2038}2039result += fmt.Sprintf(" %02x", b)2040}2041return result2042}
2043