Hi,
I'm getting an AccessViolationExcpetion by calling Marshal.PtrToStructure(intPtr, typeof(Servent)). Any ideas what I have done wrong? I tried this on x64.
IntPtr intPtr = NativeMethods.GetServByName(name, "tcp");
if (intPtr != IntPtr.Zero)
{
Servent servent = (Servent)Marshal.PtrToStructure(intPtr, typeof(Servent));
result = System.Convert.ToInt32(IPAddress.NetworkToHostOrder(servent.s_port));
}
else
{
throw CreateWSAException();
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
internal struct Servent
{
public string s_name;
public IntPtr s_aliases;
public short s_port;
public string s_proto;
}