iPXE discussion forum
get mac from ipxe in different format (no delimiter at all) - Printable Version

+- iPXE discussion forum (https://forum.ipxe.org)
+-- Forum: iPXE user forums (/forumdisplay.php?fid=1)
+--- Forum: General (/forumdisplay.php?fid=2)
+--- Thread: get mac from ipxe in different format (no delimiter at all) (/showthread.php?tid=6897)



get mac from ipxe in different format (no delimiter at all) - Torgeir - 2013-05-04 12:39

Hi!

I found myself in need of getting the mac from iPXE with no delimiter at all.
Sanboot with the MAC address (no delimited), in an embedded script within iPXE.

Usage:
Code:
iPXE> show mac
net0/mac:hex 00:aa:11:bb:22:cc

iPXE> show mac:hexhyp
net0/mac:hexhyp 00-aa-11-bb-22-cc

# hex no delimiter
iPXE> show mac:hexnd
net0/mac:hexnd 00aa11bb22cc

So I made myself a little patch for this (don't know if anyone else would ever need it...), but here it goes.

settings.c.patch
Code:
--- a/src/core/settings.c    2013-05-04 12:41:09.828764000 +0200
+++ b/src/core/settings.cc    2013-05-04 12:39:54.476391000 +0200
@@ -1770,6 +1770,20 @@
    return format_hex_setting ( raw, raw_len, buf, len, "-" );
}

+/**
+ * Format hex string setting value (using no delimiter)
+ *
+ * @v raw        Raw setting value
+ * @v raw_len        Length of raw setting value
+ * @v buf        Buffer to contain formatted value
+ * @v len        Length of buffer
+ * @ret len        Length of formatted value, or negative error
+ */
+static int format_hex_no_delimiter_setting ( const void *raw, size_t raw_len,
+                       char *buf, size_t len ) {
+    return format_hex_setting ( raw, raw_len, buf, len, "" );
+}
+
/** A hex-string setting (colon-delimited) */
struct setting_type setting_type_hex __setting_type = {
    .name = "hex",
@@ -1784,6 +1798,13 @@
    .format = format_hex_hyphen_setting,
};

+/** A hex-string setting (no delimiter) */
+struct setting_type setting_type_hex_no_delimiter __setting_type = {
+    .name = "hexnd",
+    .parse = parse_hex_setting,
+    .format = format_hex_no_delimiter_setting,
+};
+
/**
  * Parse UUID setting value
  *
settings.h.patch
Code:
--- a/src/ipxe/include/settings.h    2013-05-04 12:41:09.928765000 +0200
+++ b/src/ipxe/include/settings.hh    2013-05-04 12:39:21.272226000 +0200
@@ -322,6 +322,7 @@
extern struct setting_type setting_type_uint32 __setting_type;
extern struct setting_type setting_type_hex __setting_type;
extern struct setting_type setting_type_hexhyp __setting_type;
+extern struct setting_type setting_type_hex_no_delimiter __setting_type;
extern struct setting_type setting_type_uuid __setting_type;

extern struct setting ip_setting __setting ( SETTING_IPv4 );

Torgeir


RE: get mac from ipxe in different format (no delimiter at all) - MultimediaMan - 2013-05-04 14:08

A Good idea!

Since it is still in hex, may I suggest something like "mac:hexnd" (Hex, No Delimiter) to keep the syntax consistent?


RE: get mac from ipxe in different format (no delimiter at all) - Torgeir - 2013-05-04 14:44

Couldn't agree more!
That does sound and look better Smile


RE: get mac from ipxe in different format (no delimiter at all) - robinsmidsrod - 2013-05-04 17:00

Torgeir: I'd suggest you post this patch on the mailing-list, or submit a pull request on the ipxe/ipxe github project. Then it should hopefully be noticed at some point.