Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 995e5d4

Browse files
committed
Merge pull request #2890 from CIPop/NameResolutionPR
Porting System.Net.NameResolution.
2 parents 89fe66d + de07926 commit 995e5d4

File tree

69 files changed

+10136
-162
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+10136
-162
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System;
5+
using System.Runtime.InteropServices;
6+
7+
using socklen_t = System.UInt32;
8+
9+
internal static partial class Interop
10+
{
11+
internal static partial class libc
12+
{
13+
[DllImport(Libraries.Libc, SetLastError = true, CharSet = CharSet.Ansi)]
14+
public static extern unsafe int gethostbyaddr_r(void* addr, socklen_t len, int type, hostent* ret, byte* buf, IntPtr buflen, hostent** result, int* h_errnop);
15+
}
16+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System;
5+
using System.Runtime.InteropServices;
6+
7+
internal static partial class Interop
8+
{
9+
internal static partial class libc
10+
{
11+
[DllImport(Libraries.Libc, SetLastError = true, CharSet = CharSet.Ansi)]
12+
public static extern unsafe int gethostbyname_r(string name, hostent* ret, byte* buf, IntPtr buflen, hostent** result, int* h_errnop);
13+
}
14+
}

src/Common/src/Interop/OSX/libc/Interop.addrinfo.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,18 @@ internal static partial class Interop
1111
{
1212
internal static partial class libc
1313
{
14+
public const int AI_CANONNAME = 0x0002; // Request for canonical name.
1415
public const int AI_NUMERICHOST = 0x0004; // Don't use name resolution.
1516
public const int AI_NUMERICSERV = 0x1000; // Don't use name resolution.
1617

18+
public const int NI_MAXHOST = 1025;
1719
public const int NI_NUMERICHOST = 2; // Don't try to look up hostname.
20+
public const int NI_NAMEREQD = 4; // Don't return numeric addresses.
1821

22+
public const int EAI_AGAIN = 2; // Temporary failure in name resolution.
1923
public const int EAI_BADFLAGS = 3; // Invalid value for `ai_flags' field.
24+
public const int EAI_FAIL = 4; // Non-recoverable failure in name resolution.
25+
public const int EAI_FAMILY = 5; // 'ai_family' not supported.
2026
public const int EAI_NONAME = 8; // NAME or SERVICE is unknown.
2127

2228
public unsafe struct addrinfo
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System;
5+
using System.Runtime.InteropServices;
6+
7+
using socklen_t = System.UInt32;
8+
9+
internal static partial class Interop
10+
{
11+
internal static partial class libc
12+
{
13+
[DllImport(Libraries.Libc, SetLastError = true, CharSet = CharSet.Ansi)]
14+
public static extern unsafe hostent* gethostbyaddr(void* addr, socklen_t len, int type);
15+
}
16+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System;
5+
using System.Runtime.InteropServices;
6+
7+
internal static partial class Interop
8+
{
9+
internal static partial class libc
10+
{
11+
[DllImport(Libraries.Libc, SetLastError = true, CharSet = CharSet.Ansi)]
12+
public static extern unsafe hostent* gethostbyname(string name);
13+
}
14+
}

src/Common/src/Interop/OSX/libc/Interop.sockaddr.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,17 @@ internal static partial class libc
1717
public const sa_family_t AF_INET = 2; // IP protocol family.
1818
public const sa_family_t AF_INET6 = 30; // IP version 6.
1919

20+
// Disable CS0169 (The field 'Interop.libc.sockaddr_in.padding' is never used) and CS0649
21+
// (Field 'Interop.libc.sockaddr.sa_family' is never assigned to, and will always have its
22+
// default value 0)
23+
#pragma warning disable 169, 649
24+
2025
// NOTE: this type is incomplete, and its values should never be used directly.
2126
// Specific sockaddr types (e.g. sockaddr_in or sockaddr_in6) should be used instead.
2227
public unsafe struct sockaddr
2328
{
24-
// Disable CS0649: Field 'Interop.libc.sockaddr.sa_family' is never assigned to,
25-
// and will always have its default value 0
26-
#pragma warning disable 649
2729
public byte sa_len;
2830
public sa_family_t sa_family;
29-
#pragma warning restore 649
3031
}
3132

3233
public struct in_addr
@@ -42,7 +43,7 @@ public struct sockaddr_in
4243
public sa_family_t sin_family; // Address family: AF_INET
4344
public in_port_t sin_port; // Port in network byte order
4445
public in_addr sin_addr; // Internet address
45-
private ulong padding; // 8 bytes of padding
46+
private ulong padding; // 8 bytes of padding
4647
}
4748

4849
public unsafe struct in6_addr
@@ -61,5 +62,7 @@ public struct sockaddr_in6
6162
public in6_addr sin6_addr; // IPv6 address
6263
public uint sin6_scope_id; // Scope ID
6364
}
65+
66+
#pragma warning restore 169, 649
6467
}
6568
}

src/Common/src/Interop/Unix/libc/Interop.addrinfo.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,19 @@ internal static partial class Interop
1111
{
1212
internal static partial class libc
1313
{
14+
public const int AI_CANONNAME = 0x0002; // Request for canonical name.
1415
public const int AI_NUMERICHOST = 0x0004; // Don't use name resolution.
1516
public const int AI_NUMERICSERV = 0x0400; // Don't use name resolution.
1617

18+
public const int NI_MAXHOST = 1025;
1719
public const int NI_NUMERICHOST = 1; // Don't try to look up hostname.
20+
public const int NI_NAMEREQD = 8; // Don't return numeric addresses.
1821

1922
public const int EAI_BADFLAGS = -1; // Invalid value for `ai_flags' field.
2023
public const int EAI_NONAME = -2; // NAME or SERVICE is unknown.
24+
public const int EAI_AGAIN = -3; // Temporary failure in name resolution.
25+
public const int EAI_FAIL = -4; // Non-recoverable failure in name resolution.
26+
public const int EAI_FAMILY = -5; // 'ai_family' not supported.
2127

2228
public unsafe struct addrinfo
2329
{
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System;
5+
6+
internal static partial class Interop
7+
{
8+
internal static partial class libc
9+
{
10+
public const int HOST_NOT_FOUND = 1;
11+
public const int TRY_AGAIN = 2;
12+
public const int NO_RECOVERY = 3;
13+
public const int NO_DATA = 4;
14+
public const int NO_ADDRESS = NO_DATA;
15+
16+
// Disable CS0169 (The field 'Interop.libc.hostent.h_length' is never used) and CS0649
17+
// (Field 'Interop.libc.hostent.sa_family' is never assigned to, and will always have its
18+
// default value 0)
19+
#pragma warning disable 169, 649
20+
public unsafe struct hostent
21+
{
22+
public byte* h_name; // Official bane of host
23+
public byte** h_aliases; // Alias list
24+
public int h_addrtype; // Host address type
25+
public int h_length; // Length of address
26+
public byte** h_addr_list; // List of addresses from name server
27+
}
28+
#pragma warning restore 169, 649
29+
}
30+
}

src/Common/src/Interop/Unix/libc/Interop.sockaddr.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,16 @@ internal static partial class libc
1717
public const sa_family_t AF_INET = 2; // IP protocol family.
1818
public const sa_family_t AF_INET6 = 10; // IP version 6.
1919

20+
// Disable CS0169 (The field 'Interop.libc.sockaddr_in.padding' is never used) and CS0649
21+
// (Field 'Interop.libc.sockaddr.sa_family' is never assigned to, and will always have its
22+
// default value 0)
23+
#pragma warning disable 169, 649
24+
2025
// NOTE: this type is incomplete, and its values should never be used directly.
2126
// Specific sockaddr types (e.g. sockaddr_in or sockaddr_in6) should be used instead.
2227
public unsafe struct sockaddr
2328
{
24-
// Disable CS0649: Field 'Interop.libc.sockaddr.sa_family' is never assigned to,
25-
// and will always have its default value 0
26-
#pragma warning disable 649
2729
public sa_family_t sa_family;
28-
#pragma warning restore 649
2930
}
3031

3132
public struct in_addr
@@ -58,5 +59,7 @@ public struct sockaddr_in6
5859
public in6_addr sin6_addr; // IPv6 address
5960
public uint sin6_scope_id; // Scope ID
6061
}
62+
63+
#pragma warning restore 169, 649
6164
}
6265
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System;
5+
using System.Runtime.InteropServices;
6+
7+
internal static partial class Interop
8+
{
9+
internal static partial class libc
10+
{
11+
public const int SOCK_DGRAM = 2;
12+
13+
[DllImport(Libraries.Libc, SetLastError = true)]
14+
internal static extern int socket(int domain, int type, int protocol);
15+
}
16+
}

0 commit comments

Comments
 (0)