Ejemplo n.º 1
0
func TestGetField(t *testing.T) {
	file := "1.pcap"
	err := golibwireshark.ReOpenInputFile(file)
	if err != nil {
		t.Fatalf("%s", err)
	}

	var p golibwireshark.Packet

	p.GetPacket()
	if p.Edt == nil {
		fmt.Println("can't find packet")
		os.Exit(1)
	}

	buf := make([]byte, 100, 200)
	w := bytes.NewBuffer(buf)

	if p.GetField("ip") {
		fmt.Fprintln(w, p)
	}

	p.FreePacket()
	golibwireshark.CloseInputFile()

	len := w.Len()
	wanted_len := 644
	if len != wanted_len {
		t.Fatalf("wanted: (%d), get: (%d)", wanted_len, len)
	}
}
Ejemplo n.º 2
0
func TestWriteToFile(t *testing.T) {
	file := "1.pcap"
	err := golibwireshark.ReOpenInputFile(file)
	if err != nil {
		t.Fatalf("%s", err)
	}

	err = golibwireshark.ReOpenOutputFile("o.pcap")
	if err != nil {
		t.Fatalf("%s", err)
	}

	var p golibwireshark.Packet

	p.GetPacket()
	if p.Edt == nil {
		fmt.Println("can't find packet")
		os.Exit(1)
	}

	err = p.WriteToFile()
	if err != nil {
		t.Errorf("%s", err)
	}

	p.FreePacket()
	golibwireshark.CloseInputFile()
	golibwireshark.CloseOutputFile()
}
Ejemplo n.º 3
0
func TestIskey(t *testing.T) {
	file := "1.pcap"
	err := golibwireshark.ReOpenInputFile(file)
	if err != nil {
		t.Fatalf("%s", err)
	}

	var p golibwireshark.Packet

	p.GetPacket()
	if p.Edt == nil {
		fmt.Println("can't find packet")
		os.Exit(1)
	}

	key := "ip.addr"
	get, _ := p.IsKey(key)

	p.FreePacket()
	golibwireshark.CloseInputFile()

	wanted := []string{"10.128.229.6", "10.128.228.50"}
	if get[0] != wanted[0] {
		t.Fatalf("wanted: (%s), get: (%s)", wanted[0], get[0])
	}
	if get[1] != wanted[1] {
		t.Fatalf("wanted: (%s), get: (%s)", wanted[1], get[1])
	}

}