Esempio n. 1
0
// Stats returns statistics on the underlying pcap handle.
func (p *Handle) Stats() (stat *Stats, err error) {
	var cstats _Ctype_struct_pcap_stat
	if -1 == C.pcap_stats(p.cptr, &cstats) {
		return nil, p.Error()
	}
	return &Stats{
		PacketsReceived:  int(cstats.ps_recv),
		PacketsDropped:   int(cstats.ps_drop),
		PacketsIfDropped: int(cstats.ps_ifdrop),
	}, nil
}
Esempio n. 2
0
func (p *Pcap) Getstats() (stat *Stat, err error) {
	var cstats _Ctype_struct_pcap_stat
	if -1 == C.pcap_stats(p.cptr, &cstats) {
		return nil, p.Geterror()
	}
	stats := new(Stat)
	stats.PacketsReceived = uint32(cstats.ps_recv)
	stats.PacketsDropped = uint32(cstats.ps_drop)
	stats.PacketsIfDropped = uint32(cstats.ps_ifdrop)

	return stats, nil
}
Esempio n. 3
0
func (p *Pcap) Getstats() (stats *Stats) {
	var cstats C.struct_pcap_stat
	if C.pcap_stats(p.cptr, &cstats) == -1 {
		return
	}

	stats = new(Stats)
	stats.Received = uint32(cstats.ps_recv)
	stats.Dropped = uint32(cstats.ps_drop)
	stats.IfDropped = uint32(cstats.ps_ifdrop)

	return
}
Esempio n. 4
0
// Getstats returns a filled in Stat struct.
func (p *Pcap) Getstats() (*stat.Stat, error) {
	var cs C.struct_pcap_stat
	res := C.pcap_stats(p.cptr, &cs)
	if res == C.PCAP_ERROR {
		return nil, p.GetErr()
	}

	s := &stat.Stat{
		Captured:  p.pktCnt,
		Received:  uint32(cs.ps_recv),
		Dropped:   uint32(cs.ps_drop),
		IfDropped: uint32(cs.ps_ifdrop),
	}
	return s, nil
}
Esempio n. 5
0
func (p *Pcap) Getstats() (stat *Stat, err error) {
	var cstats _Ctype_struct_pcap_stat
	if -1 == C.pcap_stats(p.cptr, &cstats) {
		return nil, p.Geterror()
	}
	stats := new(Stat)

	// ps_recv - the number of packets received by the packet capture software.
	stats.PacketsReceived = uint32(cstats.ps_recv)
	// ps_drop - the number of packets dropped by the packet capture software.
	stats.PacketsDropped = uint32(cstats.ps_drop)
	// ps_ifdrop - the number of packets dropped by the network interface.
	stats.PacketsIfDropped = uint32(cstats.ps_ifdrop)

	return stats, nil
}