[ipxe-devel] get mac from ipxe in different format (no delimiter at all)

Torgeir W tor.wulf at gmail.com
Sat May 4 19:15:39 UTC 2013


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:
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..., or if you could call copy/paste with small name 
modifications a patch), but here it goes...

settings.c.patch
--- 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
--- 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



More information about the ipxe-devel mailing list