pcap_if structure in C#( urgent )

  • Thread starter Thread starter Vineet S
  • Start date Start date
V

Vineet S

Hello friends,

i am doing a project in C# which involves accessing funtions and
structres from winpcap. so i would like some one to please help me to
access the pcap_if structure in my C# program. i have tried doing it by
DllImport but i am not able to do it.

Please help me its very urgent.

thank u all.
 
Vineet,

From what I can tell, this would be the definitions that you need:

[StructLayout(LayoutKind.Sequential)]
public struct in_addr
{
public byte s_b1;
public byte s_b2;
public byte s_b3;
public byte s_b4;
}

[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
public struct sockaddr_in
{
public short sin_family;
[MarshalAs(UnmanagedType.U2)]
public short sin_port;
public in_addr sin_addr;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=8)]
public string sin_zero;
}

[StructLayout(LayoutKind.Sequential)]
public struct pcap_addr
{
public IntPtr next;
public IntPtr addr;
public IntPtr netmask;
public IntPtr broadaddr;
public IntPtr dstaddr;
}

[StructLayout(LayoutKind.Sequential)]
public struct pcap_if
{
public IntPtr next;
public IntPtr name;
public IntPtr description;
public IntPtr addresses
[MarshalAs(UnmanagedType.U4)]
public int flags;
}

Now, you will have to marshal most of the information yourself
(basically, anything with an IntPtr type in the field). You might have some
better luck using some unsafe code, but all in all, this will be quite the
pain to use. You might want to create a C++ implementation which will
simplify the process, and then expose that to managed code.

Hope this helps.
 
Hello Nick,

I got the code u sent for the pcap_if structure. But i am really finding
it painful to Marshal the structure members.

the pcap_if structure contains members like next, description. so when i
call the function
pcap_findalldevs(ref IntPtr alldevs,
StringBuilder errbuf );

then i am not able to access each of the member items.

Please let me know how to do it.

Regards,
Vineet
 
Back
Top