示例#1
0
func packetDump(addr net.Addr, data []byte, cache TemplateCache) {
	p, err := nf9packet.Decode(data)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		return
	}

	templateList := p.TemplateRecords()
	flowSets := p.DataFlowSets()

	for _, t := range templateList {
		templateKey := fmt.Sprintf("%s|%b|%v", addr.String(), p.SourceId, t.TemplateId)
		cache[templateKey] = t
	}

	for _, set := range flowSets {
		templateKey := fmt.Sprintf("%s|%b|%v", addr.String(), p.SourceId, set.Id)
		template, ok := cache[templateKey]
		if !ok {
			// We do not have template for this Data FlowSet yet
			continue
		}

		records := template.DecodeFlowSet(&set)
		if records == nil {
			// Error in decoding Data FlowSet
			continue
		}
		printTable(template, records)
	}
}
示例#2
0
func packetDump(addr net.Addr, data []byte) {
	p, err := nf9packet.Decode(data)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		return
	}

	templateList := p.TemplateRecords()
	optTemplateList := p.OptionsTemplateRecords()

	for _, t := range templateList {
		fmt.Printf("==== %v, SourceId: %v, TemplateId: %v ====\n", addr, p.SourceId, t.TemplateId)
		fmt.Print("--- Field name (actual length / default length) description ---\n")
		for _, f := range t.Fields {
			fmt.Printf("%-24s (%2v / %2v) %s\n", f.Name(), f.Length, f.DefaultLength(), f.Description())
		}
		fmt.Print("\n")
	}

	for _, t := range optTemplateList {
		fmt.Printf("==== %v, SourceId: %v, OptionsTemplateId: %v ====\n", addr, p.SourceId, t.TemplateId)
		fmt.Print("--- Scopes ---\n")
		for _, f := range t.Scopes {
			fmt.Printf("%-24s (%2v / %2v) %s\n", f.ScopeName(), f.Length, f.ScopeDefaultLength(), f.ScopeDescription())
		}
		fmt.Print("--- Options ---\n")
		for _, f := range t.Options {
			fmt.Printf("%-24s (%2v / %2v) %s\n", f.Name(), f.Length, f.DefaultLength(), f.Description())
		}
		fmt.Print("\n")
	}
}
示例#3
0
func packetDump(addr net.Addr, data []byte) {
	fmt.Fprintln(os.Stderr, "Got packet from: ", addr)
	p, err := nf9packet.Decode(data)

	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		return
	}

	if *dumpJson {
		json, _ := json.MarshalIndent(p, "", "\t")
		fmt.Printf("%s\n", json)
	} else {
		nf9packet.Dump(p, os.Stdout)
		fmt.Print("\n")
	}
}