3

Possible Duplicate:
How to create a simple proxy in C#?

I'm programming a proxy application, which I want to handle all network connections. I have already programmed the server and client applications, so now I only need to redirect network connections to it.

I searched a lot, and this is what I found:

//For sniffing the socket to capture the packets has to be a raw socket, with the
//address family being of type internetwork, and protocol being IP
mainSocket = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP);

//Bind the socket to the selected IP address
mainSocket.Bind(new IPEndPoint(IPAddress.Parse(cmbInterfaces.Text), 0));

//Set the socket  options
mainSocket.SetSocketOption(SocketOptionLevel.IP,    //Applies only to IP packets
SocketOptionName.HeaderIncluded,                    //Set the include the header
true);                                              //option to true

byte[] byTrue = new byte[4] {1, 0, 0, 0};
byte[] byOut = new byte[4]{1, 0, 0, 0}; //Capture outgoing packets

I'm not sure if this going to help me, since I cannot cancel the original request. What is the simplest way to do this?

Community
  • 1
  • 1
Shadow Walker
  • 325
  • 1
  • 4
  • 11

1 Answers1

0

The only way you are going to be able to transparently intercept all network traffic is with a driver, which you aren't going to be able to do in c# for obvious reasons. That said, it might be possible to use winpcap as the kernel mode component and to do your application logic in c#. There is already some interop code written to work with winpcap, though I haven't used it so can't say how stable and/or complete the support is.

Yaur
  • 7,333
  • 1
  • 25
  • 36