Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
dotNET Platform
runtime
提交
6d6a3738
R
runtime
项目概览
dotNET Platform
/
runtime
11 个月 前同步成功
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
runtime
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
6d6a3738
编写于
6月 17, 2022
作者:
J
Jan Kotas
提交者:
GitHub
6月 17, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Replace a few instances of PtrToStructure with more efficient marshalling (#70866)
上级
a78211be
变更
9
显示空白变更内容
内联
并排
Showing
9 changed file
with
101 addition
and
101 deletion
+101
-101
src/libraries/Common/src/Interop/Windows/Crypt32/Interop.FindOidInfo.cs
...Common/src/Interop/Windows/Crypt32/Interop.FindOidInfo.cs
+11
-11
src/libraries/Common/src/Interop/Windows/Crypt32/Interop.HashIdAlg.cs
...s/Common/src/Interop/Windows/Crypt32/Interop.HashIdAlg.cs
+8
-13
src/libraries/Common/src/Interop/Windows/IpHlpApi/Interop.NetworkInformation.cs
...rc/Interop/Windows/IpHlpApi/Interop.NetworkInformation.cs
+59
-44
src/libraries/System.Diagnostics.FileVersionInfo/src/System/Diagnostics/FileVersionInfo.Windows.cs
...ionInfo/src/System/Diagnostics/FileVersionInfo.Windows.cs
+2
-2
src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SystemIPInterfaceProperties.cs
...tem/Net/NetworkInformation/SystemIPInterfaceProperties.cs
+2
-2
src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SystemIPv4InterfaceProperties.cs
...m/Net/NetworkInformation/SystemIPv4InterfaceProperties.cs
+3
-4
src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SystemNetworkInterface.cs
...c/System/Net/NetworkInformation/SystemNetworkInterface.cs
+8
-17
src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SystemUnicastIPAddressInformation.cs
...t/NetworkInformation/SystemUnicastIPAddressInformation.cs
+6
-6
src/libraries/System.Security.Principal.Windows/src/System/Security/Principal/SID.cs
...ty.Principal.Windows/src/System/Security/Principal/SID.cs
+2
-2
未找到文件。
src/libraries/Common/src/Interop/Windows/Crypt32/Interop.FindOidInfo.cs
浏览文件 @
6d6a3738
...
...
@@ -48,7 +48,7 @@ internal enum CryptOidInfoKeyType : int
CRYPT_OID_INFO_CNG_SIGN_KEY
=
6
,
}
internal
static
CRYPT_OID_INFO
FindOidInfo
(
CryptOidInfoKeyType
keyType
,
string
key
,
OidGroup
group
,
bool
fallBackToAllGroups
)
internal
static
unsafe
CRYPT_OID_INFO
FindOidInfo
(
CryptOidInfoKeyType
keyType
,
string
key
,
OidGroup
group
,
bool
fallBackToAllGroups
)
{
const
OidGroup
CRYPT_OID_DISABLE_SEARCH_DS_FLAG
=
unchecked
((
OidGroup
)
0x80000000
);
Debug
.
Assert
(
key
!=
null
);
...
...
@@ -75,28 +75,28 @@ internal static CRYPT_OID_INFO FindOidInfo(CryptOidInfoKeyType keyType, string k
if
(!
OidGroupWillNotUseActiveDirectory
(
group
))
{
OidGroup
localGroup
=
group
|
CRYPT_OID_DISABLE_SEARCH_DS_FLAG
;
IntPtr
localOidInfo
=
CryptFindOIDInfo
(
keyType
,
rawKey
,
localGroup
);
if
(
localOidInfo
!=
IntPtr
.
Zero
)
CRYPT_OID_INFO
*
localOidInfo
=
CryptFindOIDInfo
(
keyType
,
rawKey
,
localGroup
);
if
(
localOidInfo
!=
null
)
{
return
Marshal
.
PtrToStructure
<
CRYPT_OID_INFO
>(
localOidInfo
)
;
return
*
localOidInfo
;
}
}
// Attempt to query with a specific group, to make try to avoid an AD lookup if possible
IntPtr
fullOidInfo
=
CryptFindOIDInfo
(
keyType
,
rawKey
,
group
);
if
(
fullOidInfo
!=
IntPtr
.
Zero
)
CRYPT_OID_INFO
*
fullOidInfo
=
CryptFindOIDInfo
(
keyType
,
rawKey
,
group
);
if
(
fullOidInfo
!=
null
)
{
return
Marshal
.
PtrToStructure
<
CRYPT_OID_INFO
>(
fullOidInfo
)
;
return
*
fullOidInfo
;
}
if
(
fallBackToAllGroups
&&
group
!=
OidGroup
.
All
)
{
// Finally, for compatibility with previous runtimes, if we have a group specified retry the
// query with no group
IntPtr
allGroupOidInfo
=
CryptFindOIDInfo
(
keyType
,
rawKey
,
OidGroup
.
All
);
if
(
allGroupOidInfo
!=
IntPtr
.
Zero
)
CRYPT_OID_INFO
*
allGroupOidInfo
=
CryptFindOIDInfo
(
keyType
,
rawKey
,
OidGroup
.
All
);
if
(
allGroupOidInfo
!=
null
)
{
return
Marshal
.
PtrToStructure
<
CRYPT_OID_INFO
>(
allGroupOidInfo
)
;
return
*
allGroupOidInfo
;
}
}
...
...
@@ -125,6 +125,6 @@ private static bool OidGroupWillNotUseActiveDirectory(OidGroup group)
}
[
LibraryImport
(
Interop
.
Libraries
.
Crypt32
)]
private
static
partial
IntPtr
CryptFindOIDInfo
(
CryptOidInfoKeyType
dwKeyType
,
IntPtr
pvKey
,
OidGroup
group
);
private
static
unsafe
partial
CRYPT_OID_INFO
*
CryptFindOIDInfo
(
CryptOidInfoKeyType
dwKeyType
,
IntPtr
pvKey
,
OidGroup
group
);
}
}
src/libraries/Common/src/Interop/Windows/Crypt32/Interop.HashIdAlg.cs
浏览文件 @
6d6a3738
...
...
@@ -13,23 +13,18 @@ internal static partial class Crypt32
/// Version used for a buffer containing a scalar integer (not an IntPtr)
/// </summary>
[
LibraryImport
(
Libraries
.
Crypt32
)]
private
static
unsafe
partial
IntPtr
CryptFindOIDInfo
(
CryptOidInfoKeyType
dwKeyType
,
int
*
pvKey
,
OidGroup
group
);
private
static
unsafe
partial
CRYPT_OID_INFO
*
CryptFindOIDInfo
(
CryptOidInfoKeyType
dwKeyType
,
void
*
pvKey
,
OidGroup
group
);
public
static
CRYPT_OID_INFO
FindAlgIdOidInfo
(
Interop
.
BCrypt
.
ECC_CURVE_ALG_ID_ENUM
algId
)
public
static
unsafe
CRYPT_OID_INFO
FindAlgIdOidInfo
(
Interop
.
BCrypt
.
ECC_CURVE_ALG_ID_ENUM
algId
)
{
int
intAlgId
=
(
int
)
algId
;
IntPtr
fullOidInfo
;
unsafe
{
fullOidInfo
=
CryptFindOIDInfo
(
CRYPT_OID_INFO
*
fullOidInfo
=
CryptFindOIDInfo
(
CryptOidInfoKeyType
.
CRYPT_OID_INFO_ALGID_KEY
,
&
intA
lgId
,
&
a
lgId
,
OidGroup
.
HashAlgorithm
);
}
if
(
fullOidInfo
!=
IntPtr
.
Zero
)
if
(
fullOidInfo
!=
null
)
{
return
Marshal
.
PtrToStructure
<
CRYPT_OID_INFO
>(
fullOidInfo
)
;
return
*
fullOidInfo
;
}
// Otherwise the lookup failed.
...
...
src/libraries/Common/src/Interop/Windows/IpHlpApi/Interop.NetworkInformation.cs
浏览文件 @
6d6a3738
...
...
@@ -76,24 +76,22 @@ internal IPAddress MarshalIPAddress()
// IP_ADAPTER_WINS_SERVER_ADDRESS
// IP_ADAPTER_GATEWAY_ADDRESS
[
StructLayout
(
LayoutKind
.
Sequential
)]
internal
struct
IpAdapterAddress
internal
unsafe
struct
IpAdapterAddress
{
internal
uint
length
;
internal
AdapterAddressFlags
flags
;
internal
I
ntPtr
next
;
internal
I
pAdapterAddress
*
next
;
internal
IpSocketAddress
address
;
internal
static
InternalIPAddressCollection
MarshalIpAddressCollection
(
IntPtr
ptr
)
{
InternalIPAddressCollection
addressList
=
new
InternalIPAddressCollection
();
while
(
ptr
!=
IntPtr
.
Zero
)
IpAdapterAddress
*
pIpAdapterAddress
=
(
IpAdapterAddress
*)
ptr
;
while
(
pIpAdapterAddress
!=
null
)
{
IpAdapterAddress
addressStructure
=
Marshal
.
PtrToStructure
<
IpAdapterAddress
>(
ptr
);
IPAddress
address
=
addressStructure
.
address
.
MarshalIPAddress
();
addressList
.
InternalAdd
(
address
);
ptr
=
addressStructure
.
next
;
addressList
.
InternalAdd
(
pIpAdapterAddress
->
address
.
MarshalIPAddress
());
pIpAdapterAddress
=
pIpAdapterAddress
->
next
;
}
return
addressList
;
...
...
@@ -103,13 +101,12 @@ internal static IPAddressInformationCollection MarshalIpAddressInformationCollec
{
IPAddressInformationCollection
addressList
=
new
IPAddressInformationCollection
();
while
(
ptr
!=
IntPtr
.
Zero
)
IpAdapterAddress
*
pIpAdapterAddress
=
(
IpAdapterAddress
*)
ptr
;
while
(
pIpAdapterAddress
!=
null
)
{
IpAdapterAddress
addressStructure
=
Marshal
.
PtrToStructure
<
IpAdapterAddress
>(
ptr
);
IPAddress
address
=
addressStructure
.
address
.
MarshalIPAddress
();
addressList
.
InternalAdd
(
new
SystemIPAddressInformation
(
address
,
addressStructure
.
flags
));
ptr
=
addressStructure
.
next
;
addressList
.
InternalAdd
(
new
SystemIPAddressInformation
(
pIpAdapterAddress
->
address
.
MarshalIPAddress
(),
pIpAdapterAddress
->
flags
));
pIpAdapterAddress
=
pIpAdapterAddress
->
next
;
}
return
addressList
;
...
...
@@ -117,11 +114,11 @@ internal static IPAddressInformationCollection MarshalIpAddressInformationCollec
}
[
StructLayout
(
LayoutKind
.
Sequential
)]
internal
struct
IpAdapterUnicastAddress
internal
unsafe
struct
IpAdapterUnicastAddress
{
internal
uint
length
;
internal
AdapterAddressFlags
flags
;
internal
I
ntPtr
next
;
internal
I
pAdapterUnicastAddress
*
next
;
internal
IpSocketAddress
address
;
internal
PrefixOrigin
prefixOrigin
;
internal
SuffixOrigin
suffixOrigin
;
...
...
@@ -132,37 +129,59 @@ internal struct IpAdapterUnicastAddress
internal
byte
prefixLength
;
}
[
StructLayout
(
LayoutKind
.
Sequential
,
CharSet
=
CharSet
.
Unicode
)]
internal
struct
IpAdapterAddresses
[
StructLayout
(
LayoutKind
.
Sequential
)]
internal
unsafe
struct
IpAdapterAddresses
{
internal
const
int
MAX_ADAPTER_ADDRESS_LENGTH
=
8
;
internal
uint
length
;
internal
uint
index
;
internal
I
ntPtr
next
;
internal
I
pAdapterAddresses
*
next
;
// Needs to be ANSI.
[
MarshalAs
(
UnmanagedType
.
LPStr
)]
internal
string
AdapterName
;
private
IntPtr
_adapterName
;
// ANSI string
internal
string
AdapterName
=>
Marshal
.
PtrToStringAnsi
(
_adapterName
)!;
internal
IntPtr
firstUnicastAddress
;
internal
IntPtr
firstAnycastAddress
;
internal
IntPtr
firstMulticastAddress
;
internal
IntPtr
firstDnsServerAddress
;
internal
string
dnsSuffix
;
internal
string
description
;
internal
string
friendlyName
;
[
MarshalAs
(
UnmanagedType
.
ByValArray
,
SizeConst
=
MAX_ADAPTER_ADDRESS_LENGTH
)]
internal
byte
[]
address
;
internal
uint
addressLength
;
private
IntPtr
_dnsSuffix
;
internal
string
DnsSuffix
=>
Marshal
.
PtrToStringUni
(
_dnsSuffix
)!;
private
IntPtr
_description
;
internal
string
Description
=>
Marshal
.
PtrToStringUni
(
_description
)!;
private
IntPtr
_friendlyName
;
internal
string
FriendlyName
=>
Marshal
.
PtrToStringUni
(
_friendlyName
)!;
private
fixed
byte
_address
[
MAX_ADAPTER_ADDRESS_LENGTH
];
private
uint
_addressLength
;
internal
byte
[]
Address
{
get
{
fixed
(
byte
*
pAddress
=
_address
)
return
new
ReadOnlySpan
<
byte
>(
pAddress
,
(
int
)
_addressLength
).
ToArray
();
}
}
internal
AdapterFlags
flags
;
internal
uint
mtu
;
internal
NetworkInterfaceType
type
;
internal
OperationalStatus
operStatus
;
internal
uint
ipv6Index
;
[
MarshalAs
(
UnmanagedType
.
ByValArray
,
SizeConst
=
16
)]
internal
uint
[]
zoneIndices
;
private
fixed
uint
_zoneIndices
[
16
];
internal
uint
[]
ZoneIndices
{
get
{
fixed
(
uint
*
pZoneIndices
=
_zoneIndices
)
return
new
ReadOnlySpan
<
uint
>(
pZoneIndices
,
16
).
ToArray
();
}
}
internal
IntPtr
firstPrefix
;
internal
ulong
transmitLinkSpeed
;
...
...
@@ -174,13 +193,11 @@ internal struct IpAdapterAddresses
internal
ulong
luid
;
internal
IpSocketAddress
dhcpv4Server
;
internal
uint
compartmentId
;
[
MarshalAs
(
UnmanagedType
.
ByValArray
,
SizeConst
=
16
)]
internal
byte
[]
networkGuid
;
internal
fixed
byte
networkGuid
[
16
];
internal
InterfaceConnectionType
connectionType
;
internal
InterfaceTunnelType
tunnelType
;
internal
IpSocketAddress
dhcpv6Server
;
// Never available in Windows.
[
MarshalAs
(
UnmanagedType
.
ByValArray
,
SizeConst
=
130
)]
internal
byte
[]
dhcpv6ClientDuid
;
internal
fixed
byte
dhcpv6ClientDuid
[
130
];
internal
uint
dhcpv6ClientDuidLength
;
internal
uint
dhcpV6Iaid
;
...
...
@@ -211,11 +228,11 @@ internal enum InterfaceTunnelType : int
/// <summary>
/// IP_PER_ADAPTER_INFO - per-adapter IP information such as DNS server list.
/// </summary>
[
StructLayout
(
LayoutKind
.
Sequential
,
CharSet
=
CharSet
.
Ansi
)]
[
StructLayout
(
LayoutKind
.
Sequential
)]
internal
struct
IpPerAdapterInfo
{
internal
bool
autoconfigEnabled
;
internal
bool
autoconfigActive
;
internal
uint
autoconfigEnabled
;
internal
uint
autoconfigActive
;
internal
IntPtr
currentDnsServer
;
/* IpAddressList* */
internal
IpAddrString
dnsServerList
;
};
...
...
@@ -224,14 +241,12 @@ internal struct IpPerAdapterInfo
/// Store an IP address with its corresponding subnet mask,
/// both as dotted decimal strings.
/// </summary>
[
StructLayout
(
LayoutKind
.
Sequential
,
CharSet
=
CharSet
.
Ansi
)]
internal
struct
IpAddrString
{
internal
IntPtr
Next
;
/* struct _IpAddressList* */
[
MarshalAs
(
UnmanagedType
.
ByValTStr
,
SizeConst
=
16
)]
internal
string
IpAddress
;
[
MarshalAs
(
UnmanagedType
.
ByValTStr
,
SizeConst
=
16
)]
internal
string
IpMask
;
[
StructLayout
(
LayoutKind
.
Sequential
)]
internal
unsafe
struct
IpAddrString
{
internal
IpAddrString
*
Next
;
/* struct _IpAddressList* */
internal
fixed
byte
IpAddress
[
16
];
internal
fixed
byte
IpMask
[
16
];
internal
uint
Context
;
}
...
...
src/libraries/System.Diagnostics.FileVersionInfo/src/System/Diagnostics/FileVersionInfo.Windows.cs
浏览文件 @
6d6a3738
...
...
@@ -68,11 +68,11 @@ private static string ConvertTo8DigitHex(uint value)
return
value
.
ToString
(
"X8"
);
}
private
static
Interop
.
Version
.
VS_FIXEDFILEINFO
GetFixedFileInfo
(
IntPtr
memPtr
)
private
static
unsafe
Interop
.
Version
.
VS_FIXEDFILEINFO
GetFixedFileInfo
(
IntPtr
memPtr
)
{
if
(
Interop
.
Version
.
VerQueryValue
(
memPtr
,
"\\"
,
out
IntPtr
memRef
,
out
_
))
{
return
(
Interop
.
Version
.
VS_FIXEDFILEINFO
)
Marshal
.
PtrToStructure
<
Interop
.
Version
.
VS_FIXEDFILEINFO
>(
memRef
)
;
return
*(
Interop
.
Version
.
VS_FIXEDFILEINFO
*)
memRef
;
}
return
default
;
...
...
src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SystemIPInterfaceProperties.cs
浏览文件 @
6d6a3738
...
...
@@ -29,7 +29,7 @@ internal sealed class SystemIPInterfaceProperties : IPInterfaceProperties
internal
SystemIPInterfaceProperties
(
in
Interop
.
IpHlpApi
.
FIXED_INFO
fixedInfo
,
in
Interop
.
IpHlpApi
.
IpAdapterAddresses
ipAdapterAddresses
)
{
_adapterFlags
=
ipAdapterAddresses
.
flags
;
_dnsSuffix
=
ipAdapterAddresses
.
d
nsSuffix
;
_dnsSuffix
=
ipAdapterAddresses
.
D
nsSuffix
;
_dnsEnabled
=
fixedInfo
.
enableDns
;
_dynamicDnsEnabled
=
((
ipAdapterAddresses
.
flags
&
Interop
.
IpHlpApi
.
AdapterFlags
.
DnsEnabled
)
>
0
);
...
...
@@ -64,7 +64,7 @@ internal SystemIPInterfaceProperties(in Interop.IpHlpApi.FIXED_INFO fixedInfo, i
if
((
_adapterFlags
&
Interop
.
IpHlpApi
.
AdapterFlags
.
IPv6Enabled
)
!=
0
)
{
_ipv6Properties
=
new
SystemIPv6InterfaceProperties
(
ipAdapterAddresses
.
ipv6Index
,
ipAdapterAddresses
.
mtu
,
ipAdapterAddresses
.
z
oneIndices
);
ipAdapterAddresses
.
mtu
,
ipAdapterAddresses
.
Z
oneIndices
);
}
}
...
...
src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SystemIPv4InterfaceProperties.cs
浏览文件 @
6d6a3738
...
...
@@ -91,11 +91,10 @@ private unsafe void GetPerAdapterInfo(uint index)
result
=
Interop
.
IpHlpApi
.
GetPerAdapterInfo
(
index
,
buffer
,
&
size
);
if
(
result
==
Interop
.
IpHlpApi
.
ERROR_SUCCESS
)
{
Interop
.
IpHlpApi
.
IpPerAdapterInfo
ipPerAdapterInfo
=
Marshal
.
PtrToStructure
<
Interop
.
IpHlpApi
.
IpPerAdapterInfo
>(
buffer
);
Interop
.
IpHlpApi
.
IpPerAdapterInfo
*
ipPerAdapterInfo
=
(
Interop
.
IpHlpApi
.
IpPerAdapterInfo
*)
buffer
;
_autoConfigEnabled
=
ipPerAdapterInfo
.
autoconfigEnabled
;
_autoConfigActive
=
ipPerAdapterInfo
.
autoconfigActive
;
_autoConfigEnabled
=
ipPerAdapterInfo
->
autoconfigEnabled
!=
0
;
_autoConfigActive
=
ipPerAdapterInfo
->
autoconfigActive
!=
0
;
}
}
finally
...
...
src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SystemNetworkInterface.cs
浏览文件 @
6d6a3738
...
...
@@ -15,7 +15,6 @@ internal sealed class SystemNetworkInterface : NetworkInterface
private
readonly
string
_id
;
private
readonly
string
_description
;
private
readonly
byte
[]
_physicalAddress
;
private
readonly
uint
_addressLength
;
private
readonly
NetworkInterfaceType
_type
;
private
readonly
OperationalStatus
_operStatus
;
private
readonly
long
_speed
;
...
...
@@ -110,14 +109,12 @@ internal static unsafe NetworkInterface[] GetNetworkInterfaces()
if
(
result
==
Interop
.
IpHlpApi
.
ERROR_SUCCESS
)
{
// Linked list of interfaces.
Int
Ptr
ptr
=
buffer
;
while
(
ptr
!=
IntPtr
.
Zero
)
Int
erop
.
IpHlpApi
.
IpAdapterAddresses
*
adapterAddresses
=
(
Interop
.
IpHlpApi
.
IpAdapterAddresses
*)
buffer
;
while
(
adapterAddresses
!=
null
)
{
// Traverse the list, marshal in the native structures, and create new NetworkInterfaces.
Interop
.
IpHlpApi
.
IpAdapterAddresses
adapterAddresses
=
Marshal
.
PtrToStructure
<
Interop
.
IpHlpApi
.
IpAdapterAddresses
>(
ptr
);
interfaceList
.
Add
(
new
SystemNetworkInterface
(
in
fixedInfo
,
in
adapterAddresses
));
ptr
=
adapterAddresses
.
next
;
interfaceList
.
Add
(
new
SystemNetworkInterface
(
in
fixedInfo
,
in
*
adapterAddresses
));
adapterAddresses
=
adapterAddresses
->
next
;
}
}
}
...
...
@@ -146,12 +143,11 @@ internal SystemNetworkInterface(in Interop.IpHlpApi.FIXED_INFO fixedInfo, in Int
{
// Store the common API information.
_id
=
ipAdapterAddresses
.
AdapterName
;
_name
=
ipAdapterAddresses
.
f
riendlyName
;
_description
=
ipAdapterAddresses
.
d
escription
;
_name
=
ipAdapterAddresses
.
F
riendlyName
;
_description
=
ipAdapterAddresses
.
D
escription
;
_index
=
ipAdapterAddresses
.
index
;
_physicalAddress
=
ipAdapterAddresses
.
address
;
_addressLength
=
ipAdapterAddresses
.
addressLength
;
_physicalAddress
=
ipAdapterAddresses
.
Address
;
_type
=
ipAdapterAddresses
.
type
;
_operStatus
=
ipAdapterAddresses
.
operStatus
;
...
...
@@ -172,12 +168,7 @@ internal SystemNetworkInterface(in Interop.IpHlpApi.FIXED_INFO fixedInfo, in Int
public
override
PhysicalAddress
GetPhysicalAddress
()
{
byte
[]
newAddr
=
new
byte
[
_addressLength
];
// Buffer.BlockCopy only supports int while addressLength is uint (see IpAdapterAddresses).
// Will throw OverflowException if addressLength > Int32.MaxValue.
Buffer
.
BlockCopy
(
_physicalAddress
,
0
,
newAddr
,
0
,
checked
((
int
)
_addressLength
));
return
new
PhysicalAddress
(
newAddr
);
return
new
PhysicalAddress
(
_physicalAddress
);
}
public
override
NetworkInterfaceType
NetworkInterfaceType
{
get
{
return
_type
;
}
}
...
...
src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SystemUnicastIPAddressInformation.cs
浏览文件 @
6d6a3738
...
...
@@ -20,7 +20,7 @@ internal sealed class SystemUnicastIPAddressInformation : UnicastIPAddressInform
private
readonly
uint
_preferredLifetime
;
private
readonly
byte
_prefixLength
;
internal
SystemUnicastIPAddressInformation
(
Interop
.
IpHlpApi
.
IpAdapterUnicastAddress
adapterAddress
)
internal
SystemUnicastIPAddressInformation
(
in
Interop
.
IpHlpApi
.
IpAdapterUnicastAddress
adapterAddress
)
{
IPAddress
ipAddress
=
adapterAddress
.
address
.
MarshalIPAddress
();
_innerInfo
=
new
SystemIPAddressInformation
(
ipAddress
,
adapterAddress
.
flags
);
...
...
@@ -135,15 +135,15 @@ public override long DhcpLeaseLifetime
}
// Helper method that marshals the address information into the classes.
internal
static
UnicastIPAddressInformationCollection
MarshalUnicastIpAddressInformationCollection
(
IntPtr
ptr
)
internal
static
unsafe
UnicastIPAddressInformationCollection
MarshalUnicastIpAddressInformationCollection
(
IntPtr
ptr
)
{
UnicastIPAddressInformationCollection
addressList
=
new
UnicastIPAddressInformationCollection
();
while
(
ptr
!=
IntPtr
.
Zero
)
Interop
.
IpHlpApi
.
IpAdapterUnicastAddress
*
pIpAdapterAddress
=
(
Interop
.
IpHlpApi
.
IpAdapterUnicastAddress
*)
ptr
;
while
(
pIpAdapterAddress
!=
null
)
{
Interop
.
IpHlpApi
.
IpAdapterUnicastAddress
addr
=
Marshal
.
PtrToStructure
<
Interop
.
IpHlpApi
.
IpAdapterUnicastAddress
>(
ptr
);
addressList
.
InternalAdd
(
new
SystemUnicastIPAddressInformation
(
addr
));
ptr
=
addr
.
next
;
addressList
.
InternalAdd
(
new
SystemUnicastIPAddressInformation
(
in
*
pIpAdapterAddress
));
pIpAdapterAddress
=
pIpAdapterAddress
->
next
;
}
return
addressList
;
...
...
src/libraries/System.Security.Principal.Windows/src/System/Security/Principal/SID.cs
浏览文件 @
6d6a3738
...
...
@@ -1034,8 +1034,8 @@ private static unsafe IdentityReferenceCollection TranslateToNTAccounts(Identity
for
(
int
i
=
0
;
i
<
rdl
.
Entries
;
i
++)
{
Interop
.
LSA_TRUST_INFORMATION
ti
=
(
Interop
.
LSA_TRUST_INFORMATION
)
Marshal
.
PtrToStructure
<
Interop
.
LSA_TRUST_INFORMATION
>(
new
IntPtr
((
long
)
rdl
.
Domains
+
i
*
Marshal
.
SizeOf
<
Interop
.
LSA_TRUST_INFORMATION
>()))
;
ReferencedDomains
[
i
]
=
Marshal
.
PtrToStringUni
(
ti
.
Name
.
Buffer
,
ti
.
Name
.
Length
/
sizeof
(
char
));
Interop
.
LSA_TRUST_INFORMATION
*
ti
=
(
Interop
.
LSA_TRUST_INFORMATION
*)
rdl
.
Domains
+
i
;
ReferencedDomains
[
i
]
=
Marshal
.
PtrToStringUni
(
ti
->
Name
.
Buffer
,
ti
->
Name
.
Length
/
sizeof
(
char
));
}
Interop
.
LSA_TRANSLATED_NAME
[]
translatedNames
=
new
Interop
.
LSA_TRANSLATED_NAME
[
sourceSids
.
Count
];
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录