util/virhashcode.c util/virhashcode.h \
util/virkeycode.c util/virkeycode.h \
util/virkeymaps.h \
+ util/virmacaddr.h util/virmacaddr.c \
util/virnetdev.h util/virnetdev.c \
util/virnetdevbandwidth.h util/virnetdevbandwidth.c \
util/virnetdevbridge.h util/virnetdevbridge.c \
# define __VIR_CAPABILITIES_H
# include "internal.h"
-# include "util.h"
# include "buf.h"
# include "cpu_conf.h"
+# include "virmacaddr.h"
# include <libxml/xpath.h>
# include "virsocketaddr.h"
# include "virnetdevbandwidth.h"
# include "virnetdevvportprofile.h"
-# include "util.h"
+# include "virmacaddr.h"
enum virNetworkForwardType {
VIR_NETWORK_FORWARD_NONE = 0,
virIndexToDiskName;
virIsDevMapperDevice;
virKillProcess;
-virMacAddrCompare;
-virMacAddrFormat;
-virMacAddrGenerate;
-virMacAddrParse;
virParseNumber;
virParseVersionString;
virPipeReadUntilEOF;
virKeycodeValueTranslate;
+# virmacaddr.h
+virMacAddrCompare;
+virMacAddrFormat;
+virMacAddrGenerate;
+virMacAddrParse;
+
+
# virnetclient.h
virNetClientHasPassFD;
#include "command.h"
#include "nonblocking.h"
#include "passfd.h"
-#include "virrandom.h"
#ifndef NSIG
# define NSIG 32
return virStrncpy(dest, src, strlen(src), destbytes);
}
-/* Compare two MAC addresses, ignoring differences in case,
- * as well as leading zeros.
- */
-int
-virMacAddrCompare (const char *p, const char *q)
-{
- unsigned char c, d;
- do {
- while (*p == '0' && c_isxdigit (p[1]))
- ++p;
- while (*q == '0' && c_isxdigit (q[1]))
- ++q;
- c = c_tolower (*p);
- d = c_tolower (*q);
-
- if (c == 0 || d == 0)
- break;
-
- ++p;
- ++q;
- } while (c == d);
-
- if (UCHAR_MAX <= INT_MAX)
- return c - d;
-
- /* On machines where 'char' and 'int' are types of the same size, the
- difference of two 'unsigned char' values - including the sign bit -
- doesn't fit in an 'int'. */
- return (c > d ? 1 : c < d ? -1 : 0);
-}
-
-/**
- * virMacAddrParse:
- * @str: string representation of MAC address, e.g., "0:1E:FC:E:3a:CB"
- * @addr: 6-byte MAC address
- *
- * Parse a MAC address
- *
- * Return 0 upon success, or -1 in case of error.
- */
-int
-virMacAddrParse(const char* str, unsigned char *addr)
-{
- int i;
-
- errno = 0;
- for (i = 0; i < VIR_MAC_BUFLEN; i++) {
- char *end_ptr;
- unsigned long result;
-
- /* This is solely to avoid accepting the leading
- * space or "+" that strtoul would otherwise accept.
- */
- if (!c_isxdigit(*str))
- break;
-
- result = strtoul(str, &end_ptr, 16);
-
- if ((end_ptr - str) < 1 || 2 < (end_ptr - str) ||
- (errno != 0) ||
- (0xFF < result))
- break;
-
- addr[i] = (unsigned char) result;
-
- if ((i == 5) && (*end_ptr == '\0'))
- return 0;
- if (*end_ptr != ':')
- break;
-
- str = end_ptr + 1;
- }
-
- return -1;
-}
-
-void virMacAddrFormat(const unsigned char *addr,
- char *str)
-{
- snprintf(str, VIR_MAC_STRING_BUFLEN,
- "%02X:%02X:%02X:%02X:%02X:%02X",
- addr[0], addr[1], addr[2],
- addr[3], addr[4], addr[5]);
- str[VIR_MAC_STRING_BUFLEN-1] = '\0';
-}
-
-void virMacAddrGenerate(const unsigned char *prefix,
- unsigned char *addr)
-{
- addr[0] = prefix[0];
- addr[1] = prefix[1];
- addr[2] = prefix[2];
- addr[3] = virRandomBits(8);
- addr[4] = virRandomBits(8);
- addr[5] = virRandomBits(8);
-}
-
-
int virEnumFromString(const char *const*types,
unsigned int ntypes,
const char *type)
int virHexToBin(unsigned char c);
-int virMacAddrCompare (const char *mac1, const char *mac2);
-
void virSkipSpaces(const char **str) ATTRIBUTE_NONNULL(1);
void virSkipSpacesAndBackslash(const char **str) ATTRIBUTE_NONNULL(1);
void virTrimSpaces(char *str, char **endp) ATTRIBUTE_NONNULL(1);
ATTRIBUTE_RETURN_CHECK;
# define virStrcpyStatic(dest, src) virStrcpy((dest), (src), sizeof(dest))
-# define VIR_MAC_BUFLEN 6
-# define VIR_MAC_PREFIX_BUFLEN 3
-# define VIR_MAC_STRING_BUFLEN VIR_MAC_BUFLEN * 3
-
-int virMacAddrParse(const char* str,
- unsigned char *addr) ATTRIBUTE_RETURN_CHECK;
-void virMacAddrFormat(const unsigned char *addr,
- char *str);
-void virMacAddrGenerate(const unsigned char *prefix,
- unsigned char *addr);
-
int virDiskNameToIndex(const char* str);
char *virIndexToDiskName(int idx, const char *prefix);
--- /dev/null
+/*
+ * virmacaddr.c: MAC address handling
+ *
+ * Copyright (C) 2006-2012 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Authors:
+ * Daniel P. Berrange <berrange@redhat.com>
+ */
+
+#include <config.h>
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "c-ctype.h"
+#include "virmacaddr.h"
+#include "virrandom.h"
+
+/* Compare two MAC addresses, ignoring differences in case,
+ * as well as leading zeros.
+ */
+int
+virMacAddrCompare(const char *p, const char *q)
+{
+ unsigned char c, d;
+ do {
+ while (*p == '0' && c_isxdigit(p[1]))
+ ++p;
+ while (*q == '0' && c_isxdigit(q[1]))
+ ++q;
+ c = c_tolower(*p);
+ d = c_tolower(*q);
+
+ if (c == 0 || d == 0)
+ break;
+
+ ++p;
+ ++q;
+ } while (c == d);
+
+ if (UCHAR_MAX <= INT_MAX)
+ return c - d;
+
+ /* On machines where 'char' and 'int' are types of the same size, the
+ difference of two 'unsigned char' values - including the sign bit -
+ doesn't fit in an 'int'. */
+ return (c > d ? 1 : c < d ? -1 : 0);
+}
+
+/**
+ * virMacAddrParse:
+ * @str: string representation of MAC address, e.g., "0:1E:FC:E:3a:CB"
+ * @addr: 6-byte MAC address
+ *
+ * Parse a MAC address
+ *
+ * Return 0 upon success, or -1 in case of error.
+ */
+int
+virMacAddrParse(const char* str, unsigned char *addr)
+{
+ int i;
+
+ errno = 0;
+ for (i = 0; i < VIR_MAC_BUFLEN; i++) {
+ char *end_ptr;
+ unsigned long result;
+
+ /* This is solely to avoid accepting the leading
+ * space or "+" that strtoul would otherwise accept.
+ */
+ if (!c_isxdigit(*str))
+ break;
+
+ result = strtoul(str, &end_ptr, 16);
+
+ if ((end_ptr - str) < 1 || 2 < (end_ptr - str) ||
+ (errno != 0) ||
+ (0xFF < result))
+ break;
+
+ addr[i] = (unsigned char) result;
+
+ if ((i == 5) && (*end_ptr == '\0'))
+ return 0;
+ if (*end_ptr != ':')
+ break;
+
+ str = end_ptr + 1;
+ }
+
+ return -1;
+}
+
+void virMacAddrFormat(const unsigned char *addr,
+ char *str)
+{
+ snprintf(str, VIR_MAC_STRING_BUFLEN,
+ "%02X:%02X:%02X:%02X:%02X:%02X",
+ addr[0], addr[1], addr[2],
+ addr[3], addr[4], addr[5]);
+ str[VIR_MAC_STRING_BUFLEN-1] = '\0';
+}
+
+void virMacAddrGenerate(const unsigned char *prefix,
+ unsigned char *addr)
+{
+ addr[0] = prefix[0];
+ addr[1] = prefix[1];
+ addr[2] = prefix[2];
+ addr[3] = virRandomBits(8);
+ addr[4] = virRandomBits(8);
+ addr[5] = virRandomBits(8);
+}
--- /dev/null
+/*
+ * virmacaddr.h: MAC address handling
+ *
+ * Copyright (C) 2006-2012 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Authors:
+ * Daniel P. Berrange <berrange@redhat.com>
+ */
+
+#ifndef __VIR_MACADDR_H__
+# define __VIR_MACADDR_H__
+
+# include "internal.h"
+
+# define VIR_MAC_BUFLEN 6
+# define VIR_MAC_PREFIX_BUFLEN 3
+# define VIR_MAC_STRING_BUFLEN VIR_MAC_BUFLEN * 3
+
+int virMacAddrCompare(const char *mac1, const char *mac2);
+void virMacAddrFormat(const unsigned char *addr,
+ char *str);
+void virMacAddrGenerate(const unsigned char *prefix,
+ unsigned char *addr);
+int virMacAddrParse(const char* str,
+ unsigned char *addr) ATTRIBUTE_RETURN_CHECK;
+
+#endif /* __VIR_MACADDR_H__ */
#include <config.h>
#include "virnetdev.h"
+#include "virmacaddr.h"
#include "virfile.h"
#include "virterror_internal.h"
#include "command.h"
#include <config.h>
-
#include "virnetdevmacvlan.h"
+#include "virmacaddr.h"
#include "util.h"
#include "virterror_internal.h"