From: Nick Rosbrook Date: Mon, 16 Dec 2019 18:08:03 +0000 (+0000) Subject: golang/xenlight: define Mac builtin type X-Git-Tag: 4.14.0-rc1~938 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=1db777e5e407ec12906deeac9c90e673e66865d8;p=xen.git golang/xenlight: define Mac builtin type Define Mac as [6]byte and implement fromC, toC, and String functions. Signed-off-by: Nick Rosbrook Reviewed-by: George Dunlap --- diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go index 72afc3cf14..17d146771e 100644 --- a/tools/golang/xenlight/xenlight.go +++ b/tools/golang/xenlight/xenlight.go @@ -181,6 +181,39 @@ func (d *Defbool) toC() (C.libxl_defbool, error) { return c, nil } +// Mac represents a libxl_mac, or simply a MAC address. +type Mac [6]byte + +// String formats a Mac address to string representation. +func (mac Mac) String() string { + s := "%02x:%02x:%02x:%02x:%02x:%02x" + opts := make([]interface{}, 6) + + for i, v := range mac { + opts[i] = v + } + + return fmt.Sprintf(s, opts...) +} + +func (mac *Mac) fromC(cmac *C.libxl_mac) error { + for i := range *mac { + mac[i] = byte(cmac[i]) + } + + return nil +} + +func (mac Mac) toC() (C.libxl_mac, error) { + var cmac C.libxl_mac + + for i, v := range mac { + cmac[i] = C.uint8_t(v) + } + + return cmac, nil +} + type Context struct { ctx *C.libxl_ctx logger *C.xentoollog_logger_stdiostream