原文链接:https://github.com/mdlayher/genetlink
[root@wangjq test]# cat genetlink.go package main import ( "fmt" "github.com/mdlayher/genetlink" ) func Conn_listFamilies() { c, err := genetlink.Dial(nil) if err != nil { fmt.Println("failed to dial generic netlink: ", err) } defer c.Close() families, err := c.ListFamilies() if err != nil { fmt.Println("failed to query for families: ", err) } for i, f := range families { fmt.Println("#%02d", i, ": %+v", f) } } func main() { Conn_listFamilies() }
运行测试:
[root@wangjq test]# go run genetlink.go #%02d 0 : %+v {16 2 nlctrl [{16 notify}]} #%02d 1 : %+v {17 1 VFS_DQUOT [{17 events}]} #%02d 2 : %+v {19 3 NLBL_MGMT []} #%02d 3 : %+v {20 3 NLBL_CIPSOv4 []} #%02d 4 : %+v {21 3 NLBL_CALIPSO []} #%02d 5 : %+v {22 3 NLBL_UNLBL []} #%02d 6 : %+v {23 1 acpi_event [{2 acpi_mc_group}]} #%02d 7 : %+v {24 1 thermal_event [{3 thermal_mc_grp}]} #%02d 8 : %+v {25 1 tcp_metrics []} #%02d 9 : %+v {26 2 NET_DM [{1 events}]} #%02d 10 : %+v {27 1 SEG6 []} #%02d 11 : %+v {28 1 TASKSTATS []} #%02d 12 : %+v {29 1 devlink [{4 config}]}