Example #1
0
func (c *cmdSoupbin2memh) ParsingFinished() (err error) {
	if !c.shouldExecute {
		return
	}
	inputFile, err := os.OpenFile(c.InputFileName, os.O_RDONLY, 0644)
	errs.CheckE(err)
	defer inputFile.Close()

	printer, err := rec.NewMemhRecorder(c.DestDirName)
	errs.CheckE(err)
	defer func() { errs.CheckE(printer.Close()) }()
	printer.AddDummy()

	var buf []byte
	for i := 0; i < c.Limit || c.Limit == 0; i++ {
		var header struct {
			Size uint16
			Type byte
		}
		err := binary.Read(inputFile, binary.BigEndian, &header)
		if err == io.EOF {
			break
		}
		errs.CheckE(err)
		payloadSize := header.Size - 1
		sendSize := int(payloadSize) + 2
		if sendSize > cap(buf) {
			buf = make([]byte, sendSize)
		}
		buf = buf[:sendSize]
		n, err := inputFile.Read(buf[2:])
		errs.CheckE(err)
		errs.Check(n == int(payloadSize), n, payloadSize)
		binary.BigEndian.PutUint16(buf, payloadSize)
		if header.Type == 'S' {
			errs.CheckE(printer.AddData(buf))
		} else {
			log.Printf("record type '%c' != 'S'\n", header.Type)
		}
	}
	return
}
Example #2
0
func (c *cmdPcap2memh) ParsingFinished() (err error) {
	if !c.shouldExecute {
		return
	}
	handle, err := pcap.OpenOffline(c.InputFileName)
	errs.CheckE(err)
	defer handle.Close()

	printer, err := rec.NewMemhRecorder(c.DestDirName)
	errs.CheckE(err)
	defer func() { errs.CheckE(printer.Close()) }()
	printer.AddDummy()

	pp := processor.NewProcessor()
	pp.LimitPacketNumber(c.PacketNumLimit)
	pp.SetObtainer(handle)
	pp.SetHandler(printer)
	errs.CheckE(pp.ProcessAll())
	return
}