WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] [xen-unstable] libxl: add and use parse_mac helper funct

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] libxl: add and use parse_mac helper function
From: Xen patchbot-unstable <patchbot@xxxxxxx>
Date: Fri, 07 Oct 2011 00:22:25 +0100
Delivery-date: Thu, 06 Oct 2011 16:25:01 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Ian Campbell <ian.campbell@xxxxxxxxxx>
# Date 1317923381 -3600
# Node ID 98e8b894927b59f5ad4046f591d63f77f556b692
# Parent  3bf246beb950a6f400952480b50628953fbbf2f5
libxl: add and use parse_mac helper function

rather than open coding a bunch it a bunch of times.

Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
Acked-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
Committed-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
---


diff -r 3bf246beb950 -r 98e8b894927b tools/libxl/libxl_internal.c
--- a/tools/libxl/libxl_internal.c      Thu Oct 06 18:43:03 2011 +0100
+++ b/tools/libxl/libxl_internal.c      Thu Oct 06 18:49:41 2011 +0100
@@ -277,6 +277,23 @@
        return ERROR_FAIL;
 }
 
+_hidden int libxl__parse_mac(const char *s, libxl_mac mac)
+{
+    const char *tok;
+    char *endptr;
+    int i;
+
+    for (i = 0, tok = s; *tok && (i < 6); ++i, tok += 3) {
+        mac[i] = strtol(tok, &endptr, 16);
+        if (endptr != (tok + 2) || (*endptr != '\0' && *endptr != ':') )
+            return ERROR_INVAL;
+    }
+    if ( i != 6 )
+        return ERROR_INVAL;
+
+    return 0;
+}
+
 int libxl__fd_set_cloexec(int fd)
 {
     int flags = 0;
diff -r 3bf246beb950 -r 98e8b894927b tools/libxl/libxl_internal.h
--- a/tools/libxl/libxl_internal.h      Thu Oct 06 18:43:03 2011 +0100
+++ b/tools/libxl/libxl_internal.h      Thu Oct 06 18:49:41 2011 +0100
@@ -416,6 +416,8 @@
 
 _hidden int libxl__e820_alloc(libxl_ctx *ctx, uint32_t domid, 
libxl_domain_config *d_config);
 
+_hidden int libxl__parse_mac(const char *s, libxl_mac mac);
+
 #define STRINGIFY(x) #x
 #define TOSTRING(x) STRINGIFY(x)
 
diff -r 3bf246beb950 -r 98e8b894927b tools/libxl/libxl_utils.c
--- a/tools/libxl/libxl_utils.c Thu Oct 06 18:43:03 2011 +0100
+++ b/tools/libxl/libxl_utils.c Thu Oct 06 18:49:41 2011 +0100
@@ -452,22 +452,19 @@
                             const char *mac, libxl_device_nic *nic)
 {
     libxl_nicinfo *nics;
-    unsigned int nb, i;
+    unsigned int nb, rc, i;
     int found;
-    uint8_t mac_n[6];
+    libxl_mac mac_n;
     uint8_t *a, *b;
-    const char *tok;
-    char *endptr;
+
+    rc = libxl__parse_mac(mac, mac_n);
+    if (rc)
+           return rc;
 
     nics = libxl_list_nics(ctx, domid, &nb);
     if (!nics)
         return ERROR_FAIL;
 
-    for (i = 0, tok = mac; *tok && (i < 6); ++i, tok += 3) {
-        mac_n[i] = strtol(tok, &endptr, 16);
-        if (endptr != (tok + 2))
-            return ERROR_INVAL;
-    }
     memset(nic, 0, sizeof (libxl_device_nic));
     found = 0;
     for (i = 0; i < nb; ++i) {
@@ -494,9 +491,8 @@
                               const char *devid, libxl_device_nic *nic)
 {
     libxl__gc gc = LIBXL_INIT_GC(ctx);
-    char *tok, *val;
+    char *val;
     char *dompath, *nic_path_fe, *nic_path_be;
-    unsigned int i;
     int rc = ERROR_FAIL;
 
     memset(nic, 0, sizeof (libxl_device_nic));
@@ -515,10 +511,10 @@
     nic->devid = strtoul(devid, NULL, 10);
 
     val = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/mac", 
nic_path_fe));
-    for (i = 0, tok = strtok(val, ":"); tok && (i < 6);
-         ++i, tok = strtok(NULL, ":")) {
-        nic->mac[i] = strtoul(tok, NULL, 16);
-    }
+    rc = libxl__parse_mac(val, nic->mac);
+    if (rc)
+           goto out;
+
     nic->script = xs_read(ctx->xsh, XBT_NULL, libxl__sprintf(&gc, "%s/script", 
nic_path_be), NULL);
     rc = 0;
 out:

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] libxl: add and use parse_mac helper function, Xen patchbot-unstable <=