Changeset 12273
- Timestamp:
- 04/01/15 13:41:01 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Clients.Hive.Slave/3.3/Manager/ConfigManager.cs
r12236 r12273 37 37 private const string vmwareNameString = "VMware"; 38 38 private const string virtualboxNameString = "VirtualBox"; 39 private const int macLength = 12; 39 private const int macLength = 6; 40 private const int macLongLength = 8; 40 41 41 42 public static ConfigManager Instance { … … 196 197 } 197 198 198 string addr = validNic.GetPhysicalAddress().ToString(); 199 if (addr.Length != macLength) { 200 throw new Exception("Error generating slave UID: MAC address has to have " + macLength + " digits. Actual MAC address is: " + addr); 201 } 202 203 byte[] b = new byte[8]; 204 int j = 2; 205 for (int i = 0; i < macLength; i += 2) { 206 b[j++] = (byte)((ParseNybble(addr[i]) << 4) | ParseNybble(addr[i + 1])); 207 } 199 byte[] addr = validNic.GetPhysicalAddress().GetAddressBytes(); 200 if (addr.Length < macLength || addr.Length > macLongLength) { 201 throw new ArgumentException(string.Format("Error generating slave UID: MAC address has to have a length between {0} and {1} bytes. Actual MAC address is: {2}", 202 macLength, macLongLength, addr)); 203 } 204 205 if (addr.Length < macLongLength) { 206 byte[] b = new byte[8]; 207 Array.Copy(addr, 0, b, 2, addr.Length); 208 addr = b; 209 } 210 208 211 // also get machine name and save it to the first 4 bytes 209 Guid guid = new Guid(Environment.MachineName.GetHashCode(), 0, 0, b);212 Guid guid = new Guid(Environment.MachineName.GetHashCode(), 0, 0, addr); 210 213 return guid; 211 }212 213 /// <summary>214 /// return numeric value of a single hex-char215 /// (see: http://stackoverflow.com/questions/854012/how-to-convert-hex-to-a-byte-array)216 /// </summary>217 static int ParseNybble(char c) {218 if (c >= '0' && c <= '9') {219 return c - '0';220 }221 if (c >= 'A' && c <= 'F') {222 return c - 'A' + 10;223 }224 if (c >= 'a' && c <= 'f') {225 return c - 'a' + 10;226 }227 throw new ArgumentException("Invalid hex digit: " + c);228 214 } 229 215
Note: See TracChangeset
for help on using the changeset viewer.