aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJohannes Berg <johannes.berg@intel.com>2011-02-02 15:11:00 (GMT)
committerJouni Malinen <j@w1.fi>2011-02-02 15:11:00 (GMT)
commit0c11c63375b27bc5bedb34b3bb28e066f4f7f620 (patch)
tree1f6cb1dc162ccf32f52f5a15eddbcdb8c19de33a /src
parentd750b7e699bc30cba84d5bebfafabe836682b4ab (diff)
downloadhostap-0c11c63375b27bc5bedb34b3bb28e066f4f7f620.zip
hostap-0c11c63375b27bc5bedb34b3bb28e066f4f7f620.tar.gz
hostap-0c11c63375b27bc5bedb34b3bb28e066f4f7f620.tar.bz2
util: Add compact MAC address formatting/parsing
The P2P DBus interface will use addresses for DBus paths, and uses them without any separators. Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Diffstat (limited to 'src')
-rw-r--r--src/utils/common.c24
-rw-r--r--src/utils/common.h7
2 files changed, 31 insertions, 0 deletions
diff --git a/src/utils/common.c b/src/utils/common.c
index 718be4a..89eca1c 100644
--- a/src/utils/common.c
+++ b/src/utils/common.c
@@ -69,6 +69,30 @@ int hwaddr_aton(const char *txt, u8 *addr)
return 0;
}
+/**
+ * hwaddr_compact_aton - Convert ASCII string to MAC address (no colon delimitors format)
+ * @txt: MAC address as a string (e.g., "001122334455")
+ * @addr: Buffer for the MAC address (ETH_ALEN = 6 bytes)
+ * Returns: 0 on success, -1 on failure (e.g., string not a MAC address)
+ */
+int hwaddr_compact_aton(const char *txt, u8 *addr)
+{
+ int i;
+
+ for (i = 0; i < 6; i++) {
+ int a, b;
+
+ a = hex2num(*txt++);
+ if (a < 0)
+ return -1;
+ b = hex2num(*txt++);
+ if (b < 0)
+ return -1;
+ *addr++ = (a << 4) | b;
+ }
+
+ return 0;
+}
/**
* hwaddr_aton2 - Convert ASCII string to MAC address (in any known format)
diff --git a/src/utils/common.h b/src/utils/common.h
index 620a1bf..780bc04 100644
--- a/src/utils/common.h
+++ b/src/utils/common.h
@@ -402,6 +402,12 @@ void perror(const char *s);
#ifndef MAC2STR
#define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
#define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
+
+/*
+ * Compact form for string representation of MAC address
+ * To be used, e.g., for constructing dbus paths for P2P Devices
+ */
+#define COMPACT_MACSTR "%02x%02x%02x%02x%02x%02x"
#endif
#ifndef BIT
@@ -436,6 +442,7 @@ typedef u64 __bitwise le64;
#endif /* __must_check */
int hwaddr_aton(const char *txt, u8 *addr);
+int hwaddr_compact_aton(const char *txt, u8 *addr);
int hwaddr_aton2(const char *txt, u8 *addr);
int hex2byte(const char *hex);
int hexstr2bin(const char *hex, u8 *buf, size_t len);