From patchwork Mon Oct 7 15:12:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Rosbrook X-Patchwork-Id: 11177785 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8CCAF139A for ; Mon, 7 Oct 2019 15:15:08 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6694F21655 for ; Mon, 7 Oct 2019 15:15:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ItZvXRSt" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6694F21655 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iHUhy-0006wQ-A0; Mon, 07 Oct 2019 15:13:58 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iHUhw-0006vi-N6 for xen-devel@lists.xenproject.org; Mon, 07 Oct 2019 15:13:56 +0000 X-Inumbo-ID: 02433816-e915-11e9-9bee-bc764e2007e4 Received: from mail-qk1-x741.google.com (unknown [2607:f8b0:4864:20::741]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 02433816-e915-11e9-9bee-bc764e2007e4; Mon, 07 Oct 2019 15:13:25 +0000 (UTC) Received: by mail-qk1-x741.google.com with SMTP id u22so12880653qkk.11 for ; Mon, 07 Oct 2019 08:13:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=HAvGISQ6Hj/ngZwWekmPgCL2zhfgRNQEGjJgKrLszak=; b=ItZvXRStLPiJaiwubiuFCppj/IPOZ9MNMXmcKn6ljBwlV6kULoAURJ2HhKdo1jyVah mn7p3Axl9DoEoo5uXYQfQQiyaozttI6kL2xtNM2lhfrPVJkz1/wn99mxjqxcuFefo+jx gMfyjwEqlLToqCipAyIVvFCzsXR6LkXHe6brkoPyYq5Qw2j3Z/Vn8dzuQ2OW8govHRvs iVAopQt/bUjhZwTr0oDFpkBfdZJ5ow9GzFVgui0LvAFLdpEQm3tnF8JrS1wpfYmqZn3b QSp4tAeSzLA9u67WZA9A0//9fk6uMfz85WiFqGWkZBmRB/JMz87QRZvFUZn4vN1JWdGw 2lyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HAvGISQ6Hj/ngZwWekmPgCL2zhfgRNQEGjJgKrLszak=; b=nj+ttLMJDW8SQ2oiAti2BrYMugPsKWM0auQVFL/9WtBrvmwUljj7/sVud1g2neukz8 NOKy8lZS4h2Agavvh1EPXPJIjqZ9BqLVQZl/YrdyDtX2FdAw7wdjmZE4KmnuJkG25RXZ qmmFlEFAvABYZncHESRsfy+YzLS09IVzRoRbKheZNteJaQgJtzCAbapC3fHAUsDhdJY6 8eKr9vIhh0B8HWz4g2SBilDwCdC1S0AQhRIACVOw+u3tW3ZEcfAQAOCRMj5fUodJ1gpY HLBZSxrSnRctVii6I6Ju9QWIlZxUHjCIVc4zGtbQEzal07WdEF/bPJEN0VDoVYVo/l7z omag== X-Gm-Message-State: APjAAAXIuAzUeHT8L25is2P49gIqeRR7EFEG62Pp/yStQ5RUqDueDQ2a qrXB3xceVKNhDKCYWFxyEE6abBHN X-Google-Smtp-Source: APXvYqwOrh3eWMn2yfCqFXSG2w+ztOflgE+1c8MnNwX9tU/HIqErc3YMQ6CCpUv/VyMnC+nsiDqrdg== X-Received: by 2002:a37:684f:: with SMTP id d76mr8217403qkc.415.1570461204706; Mon, 07 Oct 2019 08:13:24 -0700 (PDT) Received: from five.crux.rad.ainfosec.com (209-217-208-226.northland.net. [209.217.208.226]) by smtp.googlemail.com with ESMTPSA id c185sm8354313qkg.74.2019.10.07.08.13.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Oct 2019 08:13:24 -0700 (PDT) From: Nick Rosbrook To: xen-devel@lists.xenproject.org Date: Mon, 7 Oct 2019 11:12:55 -0400 Message-Id: X-Mailer: git-send-email 2.19.1 In-Reply-To: References: MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 08/24] golang/xenlight: define Mac builtin type X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Nick Rosbrook , Ian Jackson , kerriganb@ainfosec.com, George Dunlap , Wei Liu Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" From: Nick Rosbrook Define Mac as [6]byte and implement fromC, toC, and String functions. Signed-off-by: Nick Rosbrook --- Cc: George Dunlap Cc: Ian Jackson Cc: Wei Liu 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 a3a1836d31..3b7824b284 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 := "%x:%x:%x:%x:%x:%x" + 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