S
Shaun Baker
Hi,
I'm a bit of a novice at this but i'm running into a few problems
trying to wrap winpcap in C#. I know I can use a special socket flag
to pick up all packets across an interface but this solution needs to
work w/o an IP bound to the socket so winpcap is the only way to go
(and so I can get it working in mono). I have imported the following
functions.
[DllImport("wpcap.dll")]
public static unsafe extern IntPtr pcap_open_live(char* source, int
snaplen, int flags, int read_timeout, char* errbuf);
[DllImport("wpcap.dll")]
public static unsafe extern char* pcap_lookupdev(char* errbuff);
[DllImport("wpcap.dll")]
public static extern int pcap_next_ex(IntPtr p, ref pcap_pkthdr
pkt_header, StringBuilder pkt_data);
with the structs:
[StructLayout( LayoutKind.Sequential )]
public struct pcap_pkthdr
{
public timeval test;
public UInt32 caplen;
public UInt32 len;
}
[StructLayout( LayoutKind.Sequential )]
public struct timeval
{
public long tv_sec;
public long tv_usec;
}
The problem is twofold: first my pcap_pkthdr struct comes back all out
of whack (ie, everything is zero but tv_sec which is filled with a
huge garbage number. And the string returned seems to just be junk
(around five bytes worth). I am a floundering undergrad but this is my
first attempt at interop with unmanaged code and I was wondering if
anyone sees anything I'm doing. I sincerely appriciate any help anyone
can offer.
Respectfully,
CDT Shaun Baker
(e-mail address removed)
I'm a bit of a novice at this but i'm running into a few problems
trying to wrap winpcap in C#. I know I can use a special socket flag
to pick up all packets across an interface but this solution needs to
work w/o an IP bound to the socket so winpcap is the only way to go
(and so I can get it working in mono). I have imported the following
functions.
[DllImport("wpcap.dll")]
public static unsafe extern IntPtr pcap_open_live(char* source, int
snaplen, int flags, int read_timeout, char* errbuf);
[DllImport("wpcap.dll")]
public static unsafe extern char* pcap_lookupdev(char* errbuff);
[DllImport("wpcap.dll")]
public static extern int pcap_next_ex(IntPtr p, ref pcap_pkthdr
pkt_header, StringBuilder pkt_data);
with the structs:
[StructLayout( LayoutKind.Sequential )]
public struct pcap_pkthdr
{
public timeval test;
public UInt32 caplen;
public UInt32 len;
}
[StructLayout( LayoutKind.Sequential )]
public struct timeval
{
public long tv_sec;
public long tv_usec;
}
The problem is twofold: first my pcap_pkthdr struct comes back all out
of whack (ie, everything is zero but tv_sec which is filled with a
huge garbage number. And the string returned seems to just be junk
(around five bytes worth). I am a floundering undergrad but this is my
first attempt at interop with unmanaged code and I was wondering if
anyone sees anything I'm doing. I sincerely appriciate any help anyone
can offer.
Respectfully,
CDT Shaun Baker
(e-mail address removed)