How can I use WinPcap or PacketX.dll to catch any packets that flow on
my machine network adapter?
Is there any sample code on how to do this?
I would like something like this... and without using any additional
..dlls:
-----------------------------------------------
using System;
using System.Text;
using System.Runtime. InteropServices ;
using System.Diagnost ics;
namespace wpcapnet
{
//for the easiest way, there are only pointers, not structures
public delegate void pcap_handler(In tPtr i, IntPtr hdr, IntPtr stat);
public class pcap
{
//char *pcap_lookupdev (char *);
[DllImport("wpca p.dll")]
static extern IntPtr pcap_lookupdev( ref int errbuf);
//pcap_t *pcap_open_live (char *, int, int, int, char *);
[DllImport("wpca p.dll")]
static extern int pcap_open_live( string device, int snaplen, int
promisc,
int to_ms, StringBuilder errbuf);
//void pcap_close(pcap _t *);
[DllImport("wpca p.dll")]
static extern void pcap_close(int device);
//int pcap_setmode(pc ap_t *p, int mode);
[DllImport("wpca p.dll")]
static extern int pcap_setmode(in t device, int mode);
[DllImport("wpca p.dll")]
static extern int pcap_setbuff(in t device, int buffsize);
//int pcap_loop(pcap_ t *, int, pcap_handler, u_char *);
[DllImport("wpca p.dll")]
static extern int pcap_loop(int device, int cnt, pcap_handler
callback,
IntPtr i);
//const u_char* pcap_next(pcap_ t *, struct pcap_pkthdr *);
[DllImport("wpca p.dll")]
static extern pcap_stat pcap_next(int device, ref pcap_pkthdr
pkthdr);
//callback function
private static void OnStatistic(Int Ptr i, IntPtr hdr, IntPtr stat)
{
Debug.WriteLine (DateTime.Now.T oString());
}
public pcap_handler OnStatisticPtr = new pcap_handler(On Statistic);
public void Test()
{
StringBuilder errbuf = new StringBuilder(2 56);
IntPtr answ = pcap_lookupdev( ref buf);
String devicename = Marshal.PtrToSt ringAuto(answ);
Debug.WriteLine (devicename);
int device = pcap_open_live( devicename,1,1, 1000, errbuf);
Debug.WriteLine (device.ToStrin g());
int result = pcap_setmode(de vice,1);
Debug.WriteLine ("setmode:"+res ult.ToString()) ;
result = pcap_setbuff(de vice,0);
int answ2 = pcap_loop(devic e, 5, OnStatisticPtr, answ);
pcap_close(devi ce);
}
} 3 18778
hi
take a look at www.pinvoke.net
cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Nuno Magalhaes" <nu************ @hotmail.com> wrote in message
news:11******** **************@ g44g2000cwa.goo glegroups.com.. . How can I use WinPcap or PacketX.dll to catch any packets that flow on my machine network adapter?
Is there any sample code on how to do this?
I would like something like this... and without using any additional .dlls:
----------------------------------------------- using System; using System.Text; using System.Runtime. InteropServices ; using System.Diagnost ics;
namespace wpcapnet { //for the easiest way, there are only pointers, not structures public delegate void pcap_handler(In tPtr i, IntPtr hdr, IntPtr stat);
public class pcap { //char *pcap_lookupdev (char *); [DllImport("wpca p.dll")] static extern IntPtr pcap_lookupdev( ref int errbuf);
//pcap_t *pcap_open_live (char *, int, int, int, char *); [DllImport("wpca p.dll")] static extern int pcap_open_live( string device, int snaplen, int promisc, int to_ms, StringBuilder errbuf);
//void pcap_close(pcap _t *); [DllImport("wpca p.dll")] static extern void pcap_close(int device);
//int pcap_setmode(pc ap_t *p, int mode); [DllImport("wpca p.dll")] static extern int pcap_setmode(in t device, int mode);
[DllImport("wpca p.dll")] static extern int pcap_setbuff(in t device, int buffsize);
//int pcap_loop(pcap_ t *, int, pcap_handler, u_char *); [DllImport("wpca p.dll")] static extern int pcap_loop(int device, int cnt, pcap_handler callback, IntPtr i);
//const u_char* pcap_next(pcap_ t *, struct pcap_pkthdr *); [DllImport("wpca p.dll")] static extern pcap_stat pcap_next(int device, ref pcap_pkthdr pkthdr);
//callback function private static void OnStatistic(Int Ptr i, IntPtr hdr, IntPtr stat) { Debug.WriteLine (DateTime.Now.T oString()); }
public pcap_handler OnStatisticPtr = new pcap_handler(On Statistic);
public void Test() { StringBuilder errbuf = new StringBuilder(2 56); IntPtr answ = pcap_lookupdev( ref buf); String devicename = Marshal.PtrToSt ringAuto(answ); Debug.WriteLine (devicename);
int device = pcap_open_live( devicename,1,1, 1000, errbuf); Debug.WriteLine (device.ToStrin g()); int result = pcap_setmode(de vice,1); Debug.WriteLine ("setmode:"+res ult.ToString()) ;
result = pcap_setbuff(de vice,0);
int answ2 = pcap_loop(devic e, 5, OnStatisticPtr, answ);
pcap_close(devi ce); } }
The www.pinvoke.net site is cool but I can't see any reference to
wpcap. :(
Any other sites like this which has the reference or sample code?
Thanks,
Nuno Magalhaes.
Ignacio Machin ( .NET/ C# MVP ) wrote: hi
take a look at www.pinvoke.net
cheers,
-- Ignacio Machin, ignacio.machin AT dot.state.fl.us Florida Department Of Transportation
"Nuno Magalhaes" <nu************ @hotmail.com> wrote in message news:11******** **************@ g44g2000cwa.goo glegroups.com.. . How can I use WinPcap or PacketX.dll to catch any packets that flow on my machine network adapter?
Is there any sample code on how to do this?
I would like something like this... and without using any additional .dlls:
----------------------------------------------- using System; using System.Text; using System.Runtime. InteropServices ; using System.Diagnost ics;
namespace wpcapnet { //for the easiest way, there are only pointers, not structures public delegate void pcap_handler(In tPtr i, IntPtr hdr, IntPtr stat);
public class pcap { //char *pcap_lookupdev (char *); [DllImport("wpca p.dll")] static extern IntPtr pcap_lookupdev( ref int errbuf);
//pcap_t *pcap_open_live (char *, int, int, int, char *); [DllImport("wpca p.dll")] static extern int pcap_open_live( string device, int snaplen, int promisc, int to_ms, StringBuilder errbuf);
//void pcap_close(pcap _t *); [DllImport("wpca p.dll")] static extern void pcap_close(int device);
//int pcap_setmode(pc ap_t *p, int mode); [DllImport("wpca p.dll")] static extern int pcap_setmode(in t device, int mode);
[DllImport("wpca p.dll")] static extern int pcap_setbuff(in t device, int buffsize);
//int pcap_loop(pcap_ t *, int, pcap_handler, u_char *); [DllImport("wpca p.dll")] static extern int pcap_loop(int device, int cnt, pcap_handler callback, IntPtr i);
//const u_char* pcap_next(pcap_ t *, struct pcap_pkthdr *); [DllImport("wpca p.dll")] static extern pcap_stat pcap_next(int device, ref pcap_pkthdr pkthdr);
//callback function private static void OnStatistic(Int Ptr i, IntPtr hdr, IntPtr stat) { Debug.WriteLine (DateTime.Now.T oString()); }
public pcap_handler OnStatisticPtr = new pcap_handler(On Statistic);
public void Test() { StringBuilder errbuf = new StringBuilder(2 56); IntPtr answ = pcap_lookupdev( ref buf); String devicename = Marshal.PtrToSt ringAuto(answ); Debug.WriteLine (devicename);
int device = pcap_open_live( devicename,1,1, 1000, errbuf); Debug.WriteLine (device.ToStrin g()); int result = pcap_setmode(de vice,1); Debug.WriteLine ("setmode:"+res ult.ToString()) ;
result = pcap_setbuff(de vice,0);
int answ2 = pcap_loop(devic e, 5, OnStatisticPtr, answ);
pcap_close(devi ce); } } This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Leszek |
last post by:
Hi All!
I am developing WinPCap 3.1 wrapper in C# and I have a problem with
capturing packets with callback function.
Here is some code:
Declarations:
//C definition:
|
by: Fluffy Convict |
last post by:
I am trying to write a script that changes a textarea wrap realtime,
basically like you can switch to and from "wordwrap" in Microsofts
Notepad. Because of a bug
(https://bugzilla.mozilla.org/show_bug.cgi?id=302710), FireFox does not
listen to the textarea.wrap = 'soft' command. Because I want the script
to be cross-browser compatible,...
|
by: name |
last post by:
Back again for more critique... <grin>
------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#define MAX 10000
|
by: Nuno Magalhaes |
last post by:
Hello all,
Below I have a function that captures a packet and sends that packet to
a Receive function (wether it is sent or received).
I'm asking what functions should I use (what imports should I use and a
sample of source code) in order to get a "byte buf" filled with a
packet and using WinPCap lib.
Thank you very much,
|
by: Mark D. Smith |
last post by:
Hi
I have googled but not found a solution to wordwrap in a textarea using
firefox/netscape.
is there a style sheet solution or am i stuck with not being able to force
wrapping in a textarea
Mark
| |
by: Jason |
last post by:
Anyone know how to make the text wrap in a text box of a DetailsView?
|
by: exman |
last post by:
Hi !
i have a problem related to winpcap, i'm curretly making a sniffer
aplication for my studies.
I want to accomplish this
http://www.winpcap.org/docs/man/html/group__wpcap__tut3.html
but in visual studio, the problem is related to the function
pcap_loop(adhandle, 0, packet_handler, NULL);
it has a pointer to the function...
|
by: Ken Fine |
last post by:
I have been investigating programmatically downloading FLV content from
various sites ("video scraping"??)
Many interactive GUI tools do this, such as the Orbit downloader. At the
heart of them are packet sniffers which inspect the ethernet traffic coming
over the wire. I would like to do this noninteractively in code.
There is a .NET...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
| |
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |