All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nick Rosbrook <rosbrookn@gmail.com>
To: xen-devel@lists.xenproject.org
Cc: Nick Rosbrook <rosbrookn@ainfosec.com>,
	Ian Jackson <ian.jackson@eu.citrix.com>,
	kerriganb@ainfosec.com, George Dunlap <george.dunlap@citrix.com>,
	Wei Liu <wl@xen.org>
Subject: [Xen-devel] [PATCH v2 07/22] golang/xenlight: define Mac builtin type
Date: Fri, 15 Nov 2019 14:44:14 -0500	[thread overview]
Message-ID: <64a78d4802d2aa4f43cf2959fa0d0d884631761e.1573840474.git.rosbrookn@ainfosec.com> (raw)
In-Reply-To: <cover.1573840473.git.rosbrookn@ainfosec.com>

From: Nick Rosbrook <rosbrookn@ainfosec.com>

Define Mac as [6]byte and implement fromC, toC, and String functions.

Signed-off-by: Nick Rosbrook <rosbrookn@ainfosec.com>
---
Changes in v2:
- Fix the format string in String function to use %02x.
- Use a value reciever for the toC function.

 tools/golang/xenlight/xenlight.go | 35 +++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go
index 72afc3cf14..eb0d309543 100644
--- a/tools/golang/xenlight/xenlight.go
+++ b/tools/golang/xenlight/xenlight.go
@@ -181,6 +181,41 @@ 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 {
+	b := (*[6]C.uint8_t)(unsafe.Pointer(cmac))
+
+	for i, v := range b {
+		mac[i] = byte(v)
+	}
+
+	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
-- 
2.19.1


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  parent reply	other threads:[~2019-11-15 19:45 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-15 19:44 [Xen-devel] [PATCH v2 00/22] generated Go libxl bindings using IDL Nick Rosbrook
2019-11-15 19:44 ` [Xen-devel] [PATCH v2 01/22] golang/xenlight: generate enum types from IDL Nick Rosbrook
2019-12-03 18:11   ` George Dunlap
2019-12-04 15:58   ` George Dunlap
2019-12-05 15:02   ` George Dunlap
2019-12-05 17:00     ` Nick Rosbrook
2019-11-15 19:44 ` [Xen-devel] [PATCH v2 02/22] golang/xenlight: define Defbool builtin type Nick Rosbrook
2019-12-04 15:50   ` George Dunlap
2019-12-05 15:23     ` Nick Rosbrook
2019-12-05 15:27       ` George Dunlap
2019-11-15 19:44 ` [Xen-devel] [PATCH v2 03/22] golang/xenlight: define Devid type as int Nick Rosbrook
2019-11-15 19:44 ` [Xen-devel] [PATCH v2 04/22] golang/xenlight: define KeyValueList as empty struct Nick Rosbrook
2019-12-04 16:08   ` George Dunlap
2019-11-15 19:44 ` [Xen-devel] [PATCH v2 05/22] golang/xenlight: re-name Bitmap marshaling functions Nick Rosbrook
2019-11-15 19:44 ` [Xen-devel] [PATCH v2 06/22] golang/xenlight: define StringList builtin type Nick Rosbrook
2019-12-04 16:15   ` George Dunlap
2019-11-15 19:44 ` Nick Rosbrook [this message]
2019-12-04 16:18   ` [Xen-devel] [PATCH v2 07/22] golang/xenlight: define Mac " George Dunlap
2019-11-15 19:44 ` [Xen-devel] [PATCH v2 08/22] golang/xenlight: define MsVmGenid " Nick Rosbrook
2019-12-04 17:00   ` George Dunlap
2019-11-15 19:44 ` [Xen-devel] [PATCH v2 09/22] golang/xenlight: define EvLink builtin as empty struct Nick Rosbrook
2019-11-15 19:44 ` [Xen-devel] [PATCH v2 10/22] golang/xenlight: define CpuidPolicyList builtin type Nick Rosbrook
2019-12-04 16:48   ` George Dunlap
2019-11-15 19:44 ` [Xen-devel] [PATCH v2 11/22] golang/xenlight: re-factor Uuid type implementation Nick Rosbrook
2019-12-04 17:02   ` George Dunlap
2019-11-15 19:44 ` [Xen-devel] [PATCH v2 12/22] golang/xenlight: re-factor Hwcap " Nick Rosbrook
2019-12-04 17:07   ` George Dunlap
2019-12-05 15:35     ` Nick Rosbrook
2019-11-15 19:44 ` [Xen-devel] [PATCH v2 13/22] golang/xenlight: generate structs from the IDL Nick Rosbrook
2019-12-04 17:25   ` George Dunlap
2019-11-15 19:44 ` [Xen-devel] [PATCH v2 14/22] golang/xenlight: remove no-longer used type MemKB Nick Rosbrook
2019-11-15 19:44 ` [Xen-devel] [PATCH v2 15/22] golang/xenlight: begin C to Go type marshaling Nick Rosbrook
2019-12-04 18:07   ` George Dunlap
2019-12-05 16:38     ` Nick Rosbrook
2019-12-05 18:00       ` George Dunlap
2019-12-05 18:32         ` Nick Rosbrook
2019-11-15 19:44 ` [Xen-devel] [PATCH v2 16/22] golang/xenlight: implement keyed union C to Go marshaling Nick Rosbrook
2019-12-04 18:40   ` George Dunlap
2019-12-05 12:22     ` George Dunlap
2019-12-05 16:53       ` Nick Rosbrook
2019-12-05 17:33         ` George Dunlap
2019-12-05 18:39           ` Nick Rosbrook
2019-12-06 10:46             ` George Dunlap
2019-12-06 15:39               ` Nick Rosbrook
2019-11-15 19:44 ` [Xen-devel] [PATCH v2 17/22] golang/xenlight: implement array " Nick Rosbrook
2019-11-15 19:44 ` [Xen-devel] [PATCH v2 18/22] golang/xenlight: begin Go to C type marshaling Nick Rosbrook
2019-11-15 19:44 ` [Xen-devel] [PATCH v2 19/22] golang/xenlight: implement keyed union Go to C marshaling Nick Rosbrook
2019-11-15 19:44 ` [Xen-devel] [PATCH v2 20/22] golang/xenlight: implement array " Nick Rosbrook
2019-11-15 19:44 ` [Xen-devel] [PATCH v2 21/22] golang/xenlight: revise use of Context type Nick Rosbrook
2019-11-15 19:44 ` [Xen-devel] [PATCH v2 22/22] golang/xenlight: add error return type to Context.Cpupoolinfo Nick Rosbrook

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=64a78d4802d2aa4f43cf2959fa0d0d884631761e.1573840474.git.rosbrookn@ainfosec.com \
    --to=rosbrookn@gmail.com \
    --cc=george.dunlap@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=kerriganb@ainfosec.com \
    --cc=rosbrookn@ainfosec.com \
    --cc=wl@xen.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.