// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+using System.IO;
using System.Net.Sockets;
using System.Net.Test.Common;
using System.Runtime.InteropServices;
using Xunit;
+using Xunit.Abstractions;
namespace System.Net.NameResolution.PalTests
{
public class NameResolutionPalTests
{
- static NameResolutionPalTests()
+ private ITestOutputHelper _output;
+
+ public NameResolutionPalTests(ITestOutputHelper output)
{
NameResolutionPal.EnsureSocketsAreInitialized();
+ _output = output;
+ }
+
+ private void LogUnixInfo()
+ {
+ _output.WriteLine("--- /etc/hosts ---");
+ _output.WriteLine(File.ReadAllText("/etc/hosts"));
+ _output.WriteLine("--- /etc/resolv.conf ---");
+ _output.WriteLine(File.ReadAllText("/etc/resolv.conf"));
+ _output.WriteLine("------");
}
[Fact]
SocketError error;
int nativeErrorCode;
string name = NameResolutionPal.TryGetNameInfo(new IPAddress(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }), out error, out nativeErrorCode);
+ if (SocketError.Success != error && Environment.OSVersion.Platform == PlatformID.Unix)
+ {
+ LogUnixInfo();
+ }
+
Assert.Equal(SocketError.Success, error);
Assert.NotNull(name);
}
SocketError error;
int nativeErrorCode;
string name = NameResolutionPal.TryGetNameInfo(new IPAddress(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }), out error, out nativeErrorCode);
+ if (SocketError.Success != error && Environment.OSVersion.Platform == PlatformID.Unix)
+ {
+ LogUnixInfo();
+ }
+
Assert.Equal(SocketError.Success, error);
Assert.NotNull(name);
IPHostEntry hostEntry;
error = NameResolutionPal.TryGetAddrInfo(name, out hostEntry, out nativeErrorCode);
+ if (SocketError.Success != error && Environment.OSVersion.Platform == PlatformID.Unix)
+ {
+ LogUnixInfo();
+ }
+
Assert.Equal(SocketError.Success, error);
Assert.NotNull(hostEntry);
}