Exemple #1
0
func getNetInterfaceConfigWithSigar(sigar *C.sigar_t) (result []*InterfaceConfigInfo) {

	goInterfacesNames, length, closeable := getNetInterfaceNamesWithSigar(sigar)
	defer closeable(sigar)
	result = make([]*InterfaceConfigInfo, length)

	var sigarNetInterfaceConfig C.sigar_net_interface_config_t
	for i := 0; i < length; i++ {

		//		fmt.Println("interface name: ", &goInterfacesNames[i])
		C.sigar_net_interface_config_get(sigar, goInterfacesNames[i], &sigarNetInterfaceConfig)

		result[i] = &InterfaceConfigInfo{
			Name:          C.GoString(&sigarNetInterfaceConfig.name[0]),
			Type:          C.GoString(&sigarNetInterfaceConfig._type[0]),
			Description:   C.GoString(&sigarNetInterfaceConfig.description[0]),
			Hwaddr:        GetNetAddress(sigar, sigarNetInterfaceConfig.hwaddr),
			Address:       GetNetAddress(sigar, sigarNetInterfaceConfig.address),
			Destination:   GetNetAddress(sigar, sigarNetInterfaceConfig.destination),
			Broadcast:     GetNetAddress(sigar, sigarNetInterfaceConfig.broadcast),
			Netmask:       GetNetAddress(sigar, sigarNetInterfaceConfig.netmask),
			Address6:      GetNetAddress(sigar, sigarNetInterfaceConfig.address6),
			Prefix6Length: int(sigarNetInterfaceConfig.prefix6_length),
			Scope6:        int(sigarNetInterfaceConfig.scope6),
			Flags:         uint64(sigarNetInterfaceConfig.flags),
			Mtu:           uint64(sigarNetInterfaceConfig.mtu),
			Metric:        uint64(sigarNetInterfaceConfig.metric),
			TxQueueLen:    int(sigarNetInterfaceConfig.tx_queue_len),
		}
	}

	return result
}
Exemple #2
0
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
}