func FlowToConnStat(cs *ConnectionStats, flow *driver.PerFlowData, enableMonotonicCounts bool) {
	var (
		family         ConnectionFamily
		srcAddr        util.Address
		dstAddr        util.Address
		connectionType ConnectionType
	)
	family = connFamily(flow.AddressFamily)
	connectionType = connType(flow.Protocol)

	// V4 Address
	if family == AFINET {
		srcAddr, dstAddr = convertV4Addr(flow.LocalAddress), convertV4Addr(flow.RemoteAddress)
	} else {
		// V6 Address
		srcAddr, dstAddr = convertV6Addr(flow.LocalAddress), convertV6Addr(flow.RemoteAddress)
	}

	cs.Source = srcAddr
	cs.Dest = dstAddr
	// after lengthy discussion, use the transport bytes in/out.  monotonic
	// RecvBytes/SentBytes includes the size of the IP header and transport
	// header, transportBytes is the raw transport data.  At present,
	// the linux probe only reports the raw transport data.  So do that by default.
	cs.MonotonicSentBytes = monotonicOrTransportBytes(enableMonotonicCounts, flow.MonotonicSentBytes, flow.TransportBytesOut)
	cs.MonotonicRecvBytes = monotonicOrTransportBytes(enableMonotonicCounts, flow.MonotonicRecvBytes, flow.TransportBytesIn)
	cs.MonotonicSentPackets = flow.PacketsOut
	cs.MonotonicRecvPackets = flow.PacketsIn
	cs.LastUpdateEpoch = flow.Timestamp
	cs.Pid = uint32(flow.ProcessId)
	cs.SPort = flow.LocalPort
	cs.DPort = flow.RemotePort
	cs.Type = connectionType
	cs.Family = family
	cs.Direction = connDirection(flow.Flags)
	cs.SPortIsEphemeral = isPortInEphemeralRange(cs.Family, cs.Type, cs.SPort)

	// reset other fields to default values
	cs.NetNS = 0
	cs.IPTranslation = nil
	cs.IntraHost = false
	cs.DNSSuccessfulResponses = 0
	cs.DNSFailedResponses = 0
	cs.DNSTimeouts = 0
	cs.DNSSuccessLatencySum = 0
	cs.DNSFailureLatencySum = 0
	cs.DNSCountByRcode = nil
	cs.LastSentBytes = 0
	cs.LastRecvBytes = 0
	cs.MonotonicRetransmits = 0
	cs.LastRetransmits = 0
	cs.MonotonicTCPEstablished = 0
	cs.LastTCPEstablished = 0
	cs.MonotonicTCPClosed = 0
	cs.LastTCPClosed = 0
	cs.RTT = 0
	cs.RTTVar = 0

	if connectionType == TCP {
		tf := flow.TCPFlow()
		if tf != nil {
			cs.MonotonicRetransmits = uint32(tf.RetransmitCount)
			cs.RTT = uint32(tf.SRTT)
			cs.RTTVar = uint32(tf.RttVariance)
		}

		if isTCPFlowEstablished(flow.Flags) {
			cs.MonotonicTCPEstablished = 1
		}
		if isFlowClosed(flow.Flags) {
			cs.MonotonicTCPClosed = 1
		}
	}
}
// FlowToConnStat converts a driver.PerFlowData into a ConnectionStats struct for use with the tracer
FlowToConnStat converts a driver.PerFlowData into a ConnectionStats struct for use with the tracer
// FlowToConnStat converts a driver . PerFlowData into a ConnectionStats struct for use with the tracer
func FlowToConnStat(cs *ConnectionStats, flow *driver.PerFlowData, enableMonotonicCounts bool) {
	var (
		family         ConnectionFamily
		srcAddr        util.Address
		dstAddr        util.Address
		connectionType ConnectionType
	)
	family = connFamily(flow.AddressFamily)
	connectionType = connType(flow.Protocol)
	if family == AFINET {
		srcAddr, dstAddr = convertV4Addr(flow.LocalAddress), convertV4Addr(flow.RemoteAddress)
	} else {
		srcAddr, dstAddr = convertV6Addr(flow.LocalAddress), convertV6Addr(flow.RemoteAddress)
	}
	cs.Source = srcAddr
	cs.Dest = dstAddr
	cs.MonotonicSentBytes = monotonicOrTransportBytes(enableMonotonicCounts, flow.MonotonicSentBytes, flow.TransportBytesOut)
	cs.MonotonicRecvBytes = monotonicOrTransportBytes(enableMonotonicCounts, flow.MonotonicRecvBytes, flow.TransportBytesIn)
	cs.MonotonicSentPackets = flow.PacketsOut
	cs.MonotonicRecvPackets = flow.PacketsIn
	cs.LastUpdateEpoch = flow.Timestamp
	cs.Pid = uint32(flow.ProcessId)
	cs.SPort = flow.LocalPort
	cs.DPort = flow.RemotePort
	cs.Type = connectionType
	cs.Family = family
	cs.Direction = connDirection(flow.Flags)
	cs.SPortIsEphemeral = isPortInEphemeralRange(cs.Family, cs.Type, cs.SPort)
	cs.NetNS = 0
	cs.IPTranslation = nil
	cs.IntraHost = false
	cs.DNSSuccessfulResponses = 0
	cs.DNSFailedResponses = 0
	cs.DNSTimeouts = 0
	cs.DNSSuccessLatencySum = 0
	cs.DNSFailureLatencySum = 0
	cs.DNSCountByRcode = nil
	cs.LastSentBytes = 0
	cs.LastRecvBytes = 0
	cs.MonotonicRetransmits = 0
	cs.LastRetransmits = 0
	cs.MonotonicTCPEstablished = 0
	cs.LastTCPEstablished = 0
	cs.MonotonicTCPClosed = 0
	cs.LastTCPClosed = 0
	cs.RTT = 0
	cs.RTTVar = 0
	if connectionType == TCP {
		tf := flow.TCPFlow()
		if tf != nil {
			cs.MonotonicRetransmits = uint32(tf.RetransmitCount)
			cs.RTT = uint32(tf.SRTT)
			cs.RTTVar = uint32(tf.RttVariance)
		}
		if isTCPFlowEstablished(flow.Flags) {
			cs.MonotonicTCPEstablished = 1
		}
		if isFlowClosed(flow.Flags) {
			cs.MonotonicTCPClosed = 1
		}
	}
}
func FlowToConnStat ( cs * ConnectionStats , flow * driver . PerFlowData , enableMonotonicCounts bool ) { var ( family ConnectionFamily srcAddr util . Address dstAddr util . Address connectionType ConnectionType ) family = connFamily ( flow . AddressFamily ) connectionType = connType ( flow . Protocol ) if family == AFINET { srcAddr , dstAddr = convertV4Addr ( flow . LocalAddress ) , convertV4Addr ( flow . RemoteAddress ) } else { srcAddr , dstAddr = convertV6Addr ( flow . LocalAddress ) , convertV6Addr ( flow . RemoteAddress ) } cs . Source = srcAddr cs . Dest = dstAddr cs . MonotonicSentBytes = monotonicOrTransportBytes ( enableMonotonicCounts , flow . MonotonicSentBytes , flow . TransportBytesOut ) cs . MonotonicRecvBytes = monotonicOrTransportBytes ( enableMonotonicCounts , flow . MonotonicRecvBytes , flow . TransportBytesIn ) cs . MonotonicSentPackets = flow . PacketsOut cs . MonotonicRecvPackets = flow . PacketsIn cs . LastUpdateEpoch = flow . Timestamp cs . Pid = uint32 ( flow . ProcessId ) cs . SPort = flow . LocalPort cs . DPort = flow . RemotePort cs . Type = connectionType cs . Family = family cs . Direction = connDirection ( flow . Flags ) cs . SPortIsEphemeral = isPortInEphemeralRange ( cs . Family , cs . Type , cs . SPort ) cs . NetNS = 0 cs . IPTranslation = nil cs . IntraHost = false cs . DNSSuccessfulResponses = 0 cs . DNSFailedResponses = 0 cs . DNSTimeouts = 0 cs . DNSSuccessLatencySum = 0 cs . DNSFailureLatencySum = 0 cs . DNSCountByRcode = nil cs . LastSentBytes = 0 cs . LastRecvBytes = 0 cs . MonotonicRetransmits = 0 cs . LastRetransmits = 0 cs . MonotonicTCPEstablished = 0 cs . LastTCPEstablished = 0 cs . MonotonicTCPClosed = 0 cs . LastTCPClosed = 0 cs . RTT = 0 cs . RTTVar = 0 if connectionType == TCP { tf := flow . TCPFlow ( ) if tf != nil { cs . MonotonicRetransmits = uint32 ( tf . RetransmitCount ) cs . RTT = uint32 ( tf . SRTT ) cs . RTTVar = uint32 ( tf . RttVariance ) } if isTCPFlowEstablished ( flow . Flags ) { cs . MonotonicTCPEstablished = 1 } if isFlowClosed ( flow . Flags ) { cs . MonotonicTCPClosed = 1 } } }
FlowToConnStat converts a driver.PerFlowData into a ConnectionStats struct for use with the tracer
FlowToConnStat converts a driver . PerFlowData into a ConnectionStats struct for use with the tracer
// V4 Address // V6 Address // after lengthy discussion, use the transport bytes in/out.  monotonic // RecvBytes/SentBytes includes the size of the IP header and transport // header, transportBytes is the raw transport data.  At present, // the linux probe only reports the raw transport data.  So do that by default. // reset other fields to default values