+
+/* converts a string representing an ether HW address
+ * to a guint8 array.
+ *
+ * Returns 0 on failure, 1 on success.
+ */
+static int
+ether_str_to_guint8_array(const char *s, guint8 *mac)
+{
+ char ether_str[18]; /* 2+1+2+1+2+1+2+1+2+1+2 + 1 */
+ char *p, *str;
+ int i = 0;
+
+ if (strlen(s) > 17) {
+ return 0;
+ }
+ strcpy(ether_str, s); /* local copy of string */
+ str = ether_str;
+ while ((p = strtok(str, "-:."))) {
+ /* catch short strings with too many hex bytes: 0.0.0.0.0.0.0 */
+ if (i > 5) {
+ return 0;
+ }
+ mac[i] = (guint8) strtoul(p, NULL, 16);
+ i++;
+ /* subsequent calls to strtok() require NULL as arg 1 */
+ str = NULL;
+ }
+ if (i != 6)
+ return 0; /* failed to read 6 hex pairs */
+ else
+ return 1; /* read exactly 6 hex pairs */
+}
+