Wrapping WinPCap with DLLImports

  • Thread starter Thread starter Nuno Magalhaes
  • Start date Start date
N

Nuno Magalhaes

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,
Nuno Magalhaes.

--------------------------------------------------

public void Run()
{
int len_receive_buf=4096;
int len_send_buf=4096;
byte[] receive_buf=new byte[len_receive_buf];
byte[] send_buf=new byte[len_send_buf];
int cout_receive_bytes;
Socket socket=new
Socket(AddressFamily.InterNetwork,SocketType.Raw,ProtocolType.IP);
socket.Blocking=false;
socket.Bind(new IPEndPoint(IPAddress.Parse(DefaultIPComboBox.Text),0));

socket.SetSocketOption(SocketOptionLevel.IP,SocketOptionName.HeaderIncluded­,1);

byte[] IN=new byte[4]{1,0,0,0};
byte[] OUT=new byte[4];
int SIO_RCVALL=unchecked((int)0x98000001);
int ret_code=socket.IOControl(SIO_RCVALL,IN,OUT);
while(true)
{
IAsyncResult
ar=socket.BeginReceive(receive_buf,0,len_receive_buf,SocketFlags.None,null,­this);

cout_receive_bytes=socket.EndReceive(ar);
Receive(receive_buf);
}
}
 
Check out this link.
http://www.codeproject.com/csharp/pktcap.asp

Regards,
Sanjeevakumar Hiremath

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,
Nuno Magalhaes.

--------------------------------------------------

public void Run()
{
int len_receive_buf=4096;
int len_send_buf=4096;
byte[] receive_buf=new byte[len_receive_buf];
byte[] send_buf=new byte[len_send_buf];
int cout_receive_bytes;
Socket socket=new
Socket(AddressFamily.InterNetwork,SocketType.Raw,ProtocolType.IP);
socket.Blocking=false;
socket.Bind(new IPEndPoint(IPAddress.Parse(DefaultIPComboBox.Text),0));

socket.SetSocketOption(SocketOptionLevel.IP,SocketOptionName.HeaderIncluded­,1);

byte[] IN=new byte[4]{1,0,0,0};
byte[] OUT=new byte[4];
int SIO_RCVALL=unchecked((int)0x98000001);
int ret_code=socket.IOControl(SIO_RCVALL,IN,OUT);
while(true)
{
IAsyncResult
ar=socket.BeginReceive(receive_buf,0,len_receive_buf,SocketFlags.None,null,­this);

cout_receive_bytes=socket.EndReceive(ar);
Receive(receive_buf);
}
}
 
Back
Top