Skip to content

Commit

Permalink
Resolve FriendlyNames for bridged connections
Browse files Browse the repository at this point in the history
Use a combination of .NET's interfaces retrieval and direct calls to IP Helper API
  • Loading branch information
theXappy committed Mar 7, 2019
1 parent bb2974f commit 535c342
Show file tree
Hide file tree
Showing 9 changed files with 1,460 additions and 663 deletions.
602 changes: 301 additions & 301 deletions .gitignore

Large diffs are not rendered by default.

662 changes: 331 additions & 331 deletions SharpPcap.sln

Large diffs are not rendered by default.

35 changes: 35 additions & 0 deletions SharpPcap/Borrowed/HostInformationPal.cs
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
}

0 comments on commit 535c342

Please sign in to comment.