forked from dotpcap/sharppcap
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolve FriendlyNames for bridged connections
Use a combination of .NET's interfaces retrieval and direct calls to IP Helper API
- Loading branch information
Showing
9 changed files
with
1,460 additions
and
663 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System; | ||
using System.ComponentModel; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace SharpPcap.Borrowed | ||
{ | ||
#if Windows | ||
internal static class HostInformationPal | ||
{ | ||
private static object s_syncObject = new object(); | ||
|
||
public static Interop.FIXED_INFO GetFixedInfo() | ||
{ | ||
uint pOutBufLen = 0; | ||
Interop.FIXED_INFO fixedInfo = new Interop.FIXED_INFO(); | ||
uint networkParams = Interop.GetNetworkParams(SafeLocalAllocHandle.InvalidHandle, ref pOutBufLen); | ||
while ((int)networkParams == 111) | ||
{ | ||
SafeLocalAllocHandle pFixedInfo; | ||
using (pFixedInfo = Kernel32.LocalAlloc(0, (UIntPtr)pOutBufLen)) | ||
{ | ||
if (pFixedInfo.IsInvalid) | ||
throw new OutOfMemoryException(); | ||
networkParams = Interop.GetNetworkParams(pFixedInfo, ref pOutBufLen); | ||
if ((int)networkParams == 0) | ||
fixedInfo = Marshal.PtrToStructure<Interop.FIXED_INFO>(pFixedInfo.DangerousGetHandle()); | ||
} | ||
} | ||
if ((int)networkParams != 0) | ||
throw new Win32Exception((int)networkParams); | ||
return fixedInfo; | ||
} | ||
} | ||
#endif | ||
} |
Oops, something went wrong.