Uploaded image for project: 'Directory ApacheDS'
  1. Directory ApacheDS
  2. DIRSERVER-1929

HardwareAddress fromString does not parse output of toString

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.0.0-M15
    • None
    • dhcp
    • None

    Description

      fromString parses "1 aa:bb:cc:dd:ee:ff" but toString generates "1/aa:bb:cc:dd:ee:ff"

      Here is code which parses both native and toString values:

      @Nonnull
      public static HardwareAddress fromString(@Nonnull String text) {
      int idx = text.indexOf('/');
      HardwareAddressType hardwareAddressType = HardwareAddressType.Ethernet;
      if (idx != -1) {
      try

      { int hardwareAddressTypeCode = Integer.parseInt(text.substring(0, idx)); hardwareAddressType = HardwareAddressType.forTypeCode(hardwareAddressTypeCode); }

      catch (IllegalArgumentException e)

      { hardwareAddressType = HardwareAddressType.valueOf(text.substring(0, idx)); }

      text = text.substring(idx + 1);
      }

      CharMatcher separator = CharMatcher.BREAKING_WHITESPACE.or(CharMatcher.anyOf(":-"));
      List<String> parts = Splitter.on(separator).omitEmptyStrings().trimResults().splitToList(text);
      byte[] out = new byte[parts.size()];
      for (int i = 0; i < parts.size(); i++)
      out[i] = (byte) Integer.parseInt(parts.get, 16);

      if (hardwareAddressType.getAddressLength() != -1)
      out = Arrays.copyOf(out, hardwareAddressType.getAddressLength());

      return new HardwareAddress(hardwareAddressType.getHardwareType(), (short) out.length, out);
      }

      Attachments

        Activity

          People

            Unassigned Unassigned
            arren Shevek
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: