File tree 5 files changed +37
-7
lines changed
src/Smdn.Net.AddressResolution
5 files changed +37
-7
lines changed Original file line number Diff line number Diff line change @@ -40,7 +40,17 @@ This library also provides a functionality for referencing the system's address
40
40
<PackageReference Include =" Microsoft.Bcl.HashCode" />
41
41
<PackageReference Include =" Microsoft.Extensions.DependencyInjection.Abstractions" Version =" 6.0.0" />
42
42
<PackageReference Include =" Microsoft.Extensions.Logging.Abstractions" Version =" 6.0.0" />
43
- <PackageReference Include =" Vanara.PInvoke.IpHlpApi" Version =" 3.4.13" />
43
+ <PackageReference Include =" Vanara.Core" Version =" 4.1.1" >
44
+ <!--
45
+ `Vanara.Core` imports code analysis attributes such as `NotNullWhenAttributes` for backward compatibility.
46
+ Therefore, depending on the configuration of <TargetFramework>s, this may conflict with
47
+ type names imported from the assembly `netstandard`.
48
+ So, define separate namespaces with the Aliases property, and allow names imported from each
49
+ assembly to be referenced separately by using `extern aliases`.
50
+ -->
51
+ <Aliases >VanaraCore</Aliases >
52
+ </PackageReference >
53
+ <PackageReference Include =" Vanara.PInvoke.IpHlpApi" Version =" 4.1.1" />
44
54
</ItemGroup >
45
55
46
56
<ItemGroup >
Original file line number Diff line number Diff line change 1
1
// SPDX-FileCopyrightText: 2023 smdn <smdn@smdn.jp>
2
2
// SPDX-License-Identifier: MIT
3
3
using System ;
4
+ using System . Runtime . InteropServices ;
4
5
5
6
namespace Smdn . Net . AddressTables ;
6
7
@@ -11,7 +12,7 @@ public static IAddressTable Create(
11
12
IServiceProvider ? serviceProvider = null
12
13
)
13
14
{
14
- if ( IpHlpApiAddressTable . IsSupported )
15
+ if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) && IpHlpApiAddressTable . IsSupported )
15
16
return new IpHlpApiAddressTable ( serviceProvider ) ;
16
17
17
18
if ( ProcfsArpAddressTable . IsSupported )
Original file line number Diff line number Diff line change 6
6
#if SYSTEM_RUNTIME_EXCEPTIONSERVICES_EXCEPTIONDISPATCHINFO_SETCURRENTSTACKTRACE
7
7
using System . Runtime . ExceptionServices ;
8
8
#endif
9
+ #if SYSTEM_RUNTIME_VERSIONING_SUPPORTEDOSPLATFORMATTRIBUTE
10
+ using System . Runtime . Versioning ;
11
+ #endif
9
12
using System . Threading ;
10
13
using System . Threading . Tasks ;
11
14
17
20
18
21
namespace Smdn . Net . AddressTables ;
19
22
23
+ #if SYSTEM_RUNTIME_VERSIONING_SUPPORTEDOSPLATFORMATTRIBUTE
24
+ [ SupportedOSPlatform ( "windows" ) ]
25
+ #endif
20
26
public sealed class IpHlpApiAddressTable : AddressTable {
21
27
public static bool IsSupported => LazyIsSupported . Value ;
22
28
@@ -50,6 +56,9 @@ [EnumeratorCancellation] CancellationToken cancellationToken
50
56
{
51
57
using var table = await GetIpNetTable2Async ( ) . ConfigureAwait ( false ) ;
52
58
59
+ if ( table . Table is null )
60
+ yield break ;
61
+
53
62
foreach ( var ipnetRow2 in table . Table ) {
54
63
cancellationToken . ThrowIfCancellationRequested ( ) ;
55
64
@@ -82,7 +91,7 @@ ValueTask<MIB_IPNET_TABLE2> GetIpNetTable2Async()
82
91
83
92
table . Dispose ( ) ;
84
93
85
- var ex = ret . GetException ( ) ;
94
+ var ex = ret . GetException ( ) ?? new InvalidOperationException ( $ "GetIpNetTable2 failed: { ret } " ) ;
86
95
87
96
#if SYSTEM_RUNTIME_EXCEPTIONSERVICES_EXCEPTIONDISPATCHINFO_SETCURRENTSTACKTRACE
88
97
ex = ExceptionDispatchInfo . SetCurrentStackTrace ( ex ) ;
Original file line number Diff line number Diff line change 2
2
// SPDX-License-Identifier: MIT
3
3
using System ;
4
4
using System . Collections . Generic ;
5
- #if NULL_STATE_STATIC_ANALYSIS_ATTRIBUTES
6
- using System . Diagnostics . CodeAnalysis ;
7
- #endif
8
5
using System . Globalization ;
9
6
using System . IO ;
10
7
using System . Net ;
15
12
using Microsoft . Extensions . DependencyInjection ;
16
13
using Microsoft . Extensions . Logging ;
17
14
15
+ #if NULL_STATE_STATIC_ANALYSIS_ATTRIBUTES
16
+ // `Vanara.Core` imports code analysis attributes such as `NotNullWhenAttributes`.
17
+ // Since there is a name conflict between `Vanara.Core` and `netstandard`, assign a different
18
+ // alias to `Vanara.Core` in csproj and refer to the netstandard name by the global alias here.
19
+ using NotNullWhenAttribute = global ::System . Diagnostics . CodeAnalysis . NotNullWhenAttribute ;
20
+ #endif
21
+
18
22
namespace Smdn . Net . AddressTables ;
19
23
20
24
public sealed class ProcfsArpAddressTable : AddressTable {
Original file line number Diff line number Diff line change 6
6
#if SYSTEM_RUNTIME_EXCEPTIONSERVICES_EXCEPTIONDISPATCHINFO_SETCURRENTSTACKTRACE
7
7
using System . Runtime . ExceptionServices ;
8
8
#endif
9
+ #if SYSTEM_RUNTIME_VERSIONING_SUPPORTEDOSPLATFORMATTRIBUTE
10
+ using System . Runtime . Versioning ;
11
+ #endif
9
12
using System . Threading ;
10
13
using System . Threading . Tasks ;
11
14
19
22
20
23
namespace Smdn . Net . NetworkScanning ;
21
24
25
+ #if SYSTEM_RUNTIME_VERSIONING_SUPPORTEDOSPLATFORMATTRIBUTE
26
+ [ SupportedOSPlatform ( "windows" ) ]
27
+ #endif
22
28
public sealed class IpHlpApiNetworkScanner : NetworkScanner {
23
29
// ref:
24
30
// https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src/wpd_sdk/error-constants.md
@@ -125,7 +131,7 @@ IPAddress address
125
131
126
132
Logger ? . LogWarning ( "ResolveIpNetEntry2({Address}) {Result}" , address , ret . ToString ( ) ) ;
127
133
128
- var ex = ret . GetException ( ) ;
134
+ var ex = ret . GetException ( ) ?? new InvalidOperationException ( $ "ResolveIpNetEntry2( { address } ) failed: { ret } " ) ;
129
135
130
136
#if SYSTEM_RUNTIME_EXCEPTIONSERVICES_EXCEPTIONDISPATCHINFO_SETCURRENTSTACKTRACE
131
137
ex = ExceptionDispatchInfo . SetCurrentStackTrace ( ex ) ;
You can’t perform that action at this time.
0 commit comments