func GetNetConfig() (C.sigar_net_interface_config_t, []C.sigar_net_interface_config_t, []C.sigar_net_interface_stat_t) { var sigar *C.sigar_t = GetSigarHandle() var netlistconf C.sigar_net_interface_list_t var netconfPrimary C.sigar_net_interface_config_t C.sigar_net_interface_config_primary_get(sigar, &netconfPrimary) C.sigar_net_interface_list_get(sigar, &netlistconf) var length int = int(netlistconf.number) goInterfacesNames := ((*[1 << 30]*C.char)(unsafe.Pointer(netlistconf.data)))[:length] //cinteraces:=GetGoSlice(length, unsafe.Pointer(netlistconf.data)) //goInterfacesNames := *(*[]C.char)(unsafe.Pointer(&cinteraces)) var netconf = make([]C.sigar_net_interface_config_t, length) var netstat = make([]C.sigar_net_interface_stat_t, length) for i := 0; i < length; i++ { C.sigar_net_interface_config_get(sigar, goInterfacesNames[i], &netconf[i]) C.sigar_net_interface_stat_get(sigar, goInterfacesNames[i], &netstat[i]) } C.sigar_net_interface_list_destroy(sigar, &netlistconf) return netconfPrimary, netconf, netstat }
func GetNetIfaceUsageInfo(netIfaceName string) (netifaceInfo *NetIfaceUsageInfo, err error) { defer util.Panic2Error(&err) c_netifaceName := C.CString(netIfaceName) defer Free(c_netifaceName) var c_sigar_net_interface_stat_t C.sigar_net_interface_stat_t if status := int(C.sigar_net_interface_stat_get(GetSigarHandle(), c_netifaceName, &c_sigar_net_interface_stat_t)); status != SIGAR_OK { return nil, fmt.Errorf("Failed to rertieve network interface status for: %v with error: %v", netIfaceName, status) } return &NetIfaceUsageInfo{ RxPackets: uint64(c_sigar_net_interface_stat_t.rx_packets), RxBytes: uint64(c_sigar_net_interface_stat_t.rx_bytes), RxErrors: uint64(c_sigar_net_interface_stat_t.rx_errors), RxDropped: uint64(c_sigar_net_interface_stat_t.rx_dropped), RxOverruns: uint64(c_sigar_net_interface_stat_t.rx_overruns), RxFrame: uint64(c_sigar_net_interface_stat_t.rx_frame), TxPackets: uint64(c_sigar_net_interface_stat_t.tx_packets), TxBytes: uint64(c_sigar_net_interface_stat_t.tx_bytes), TxErrors: uint64(c_sigar_net_interface_stat_t.tx_errors), TxDropped: uint64(c_sigar_net_interface_stat_t.tx_dropped), TxOverruns: uint64(c_sigar_net_interface_stat_t.tx_overruns), TxCollisions: uint64(c_sigar_net_interface_stat_t.tx_collisions), TxCarrier: uint64(c_sigar_net_interface_stat_t.tx_carrier), Speed: uint64(c_sigar_net_interface_stat_t.speed), }, nil }