Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

NativeMethods.cs 2.7 KiB

há 8 anos
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
  2. *
  3. * Permission is hereby granted, free of charge, to any person obtaining a copy
  4. * of this software and associated documentation files (the "Software"), to deal
  5. * in the Software without restriction, including without limitation the rights
  6. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. * copies of the Software, and to permit persons to whom the Software is
  8. * furnished to do so, subject to the following conditions:
  9. *
  10. * The above copyright notice and this permission notice shall be included in
  11. * all copies or substantial portions of the Software.
  12. *
  13. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. * THE SOFTWARE.
  20. */
  21. using System;
  22. using System.Diagnostics.CodeAnalysis;
  23. using System.Globalization;
  24. using System.Net;
  25. namespace Alphaleonis.Win32.Network
  26. {
  27. internal static partial class NativeMethods
  28. {
  29. #region Constants
  30. /// <summary>A constant of type DWORD that is set to –1. This value is valid as an input parameter to any method in section 3.1.4 that takes a PreferedMaximumLength parameter. When specified as an input parameter, this value indicates that the method MUST allocate as much space as the data requires.</summary>
  31. /// <remarks>MSDN "2.2.2.2 MAX_PREFERRED_LENGTH": http://msdn.microsoft.com/en-us/library/cc247107.aspx </remarks>
  32. internal const int MaxPreferredLength = -1;
  33. #endregion // Constants
  34. #region GetComputerDomain
  35. internal static readonly string ComputerDomain = GetComputerDomain();
  36. [SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")]
  37. private static string GetComputerDomain(bool fdqn = false)
  38. {
  39. string domain = Environment.UserDomainName;
  40. string machine = Environment.MachineName.ToUpper(CultureInfo.InvariantCulture);
  41. try
  42. {
  43. if (fdqn)
  44. {
  45. domain = Dns.GetHostEntry("LocalHost").HostName.ToUpper(CultureInfo.InvariantCulture).Replace(machine + ".", string.Empty);
  46. domain = domain.Replace(machine, string.Empty);
  47. }
  48. }
  49. catch
  50. {
  51. }
  52. return domain;
  53. }
  54. #endregion // GetComputerDomain
  55. }
  56. }