Hello all.
I'm feeling pretty confused about how UDP port forwarding is done. My situation is: I have Comp1 with a local IP (192.168.0.2) connected to Comp2 with external IP and internet connection, and some unknown Internet Client (IC) (three of them actually), who needs to send data to the Server hosted at Comp1 through UDP port 7777 and then receive a response.
I managed to forward UDP data from Comp2 to Comp1 by simply accepting IC's packets at Comp2's port 7777 and sending them to Comp1's port 7777, but the problem is that Comp1's Server sees sender as Comp2 and sends response to it (192.168.0.1), rather than to IC. I can't modify Server application and it judges about packets' source by UDP's IEP. Server then stores IEPs and sends data itself (it's p2p application actually).
I would think that the task is impossible, but this kind of forwarding is implemented in applications like AUTAPF (for both UDP and TCP ports).
So how do I forward ICs' data from Comp2 to Comp1 with Comp1's Server knowing, that response must be sent to ICs?
Here's what I managed to do:
namespace PortForwarder
{
class Program
{
public static UdpClient UDP1 = new UdpClient(7777);
static void Main(string[] args)
{
Console.Title = "Port Forwarder";
Console.WriteLine("-= Port Forwarder started. =-");
Console.WriteLine("UDP ports forwarded: 7777");
UDP1.BeginReceive(ReceiveDataUDP1, null);
while (true) { };
}
static void ReceiveDataUDP1(IAsyncResult ar)
{
IPEndPoint IEP = new IPEndPoint(IPAddress.Any, 0);
Byte[] receiveBytes = UDP1.EndReceive(ar, ref IEP);
// Trying to "lie" about local IEP results in exception
// UdpClient US1 = new UdpClient(IEP);
// US1.Send(receiveBytes, receiveBytes.Length, "192.168.0.2", 7777);
UDP1.Send(receiveBytes, receiveBytes.Length, "192.168.0.2", 7777);
UDP1.BeginReceive(ReceiveDataUDP1, null);
}
}
P.S. Comp1 is connected to the internet through Comp2's ICS (Internet Connection Sharing). Comp2 is running Windows Server 2008 and connects to the internet through VPN connection. I tried to set up NAT there, but VPN connection cannot be shared for some reason (and sharing public adapter doesn't help). If, by any chance, anybody knows how it's configured, I would be really grateful. :)