Author Topic: Multi WAN  (Read 7657 times)

Offline wizziwig

  • Contributor
  • ***
  • Posts: 14
Re: Multi WAN
« Reply #15 on: August 30, 2016, 11:14:17 pm »
I'm still waiting for someone to point me to application that is able to receive from 2 network adapters...

That's the whole point.  There is no usenet client currently available that supports two network adapters.  That's why we're asking for this feature.  It would be unique to altbinz and might get more people to use it.

I already explained above how to implement it but I can go into more details if you need.  The only change is to your winsock Bind() call in order to specify which network card to use.  That's what the ForceBindIP() application does.  It patches all your calls to Bind() to make them use a specific local address.

My current altbinz work-around is to add static routes for specific news servers.  Something like this:

route add x.y.0.0 MASK 255.255.0.0 192.168.1.101

Replace x.y from the IP address of your news server.  Replace 192.168.1.101 with the IP address of the gateway associated with your second network card.

I left the other parts of the address as 0.0 because most providers have multiple servers for load-balancing.  Sometimes the x.y also changes for their backup servers so you may need to add multiple routes to make sure they all use your second network adapter. You can use task manager to verify that traffic is going through your secondary network adapter.  Having this feature built into altbinz would make life much easier since you would not need to keep updating the IP address of your news provider when they add or change servers.

Mixing wifi and ethernet is fine.  You just need a different network card associated with each gateway/ISP.  I use a USB->Ethernet adapter for my slower ISP.


Offline Rdl

  • Administrator
  • *****
  • Posts: 3837
Re: Multi WAN
« Reply #16 on: August 30, 2016, 11:55:05 pm »
I'm still waiting for someone to point me to ANY windows application that is able to send/receive from 2 network adapters at the same time in one instance...

You can easily bind to secondary NIC, just as ForceBindIP does, BUT after that all trafic in that instance goes over that NIC. You can try to bind again, but it still goes over the NIC you first bind to.
I really can't be more clearer, so unless someone points me to the right app, I say this can't be done without messing with the routes.

Offline wizziwig

  • Contributor
  • ***
  • Posts: 14
Re: Multi WAN
« Reply #17 on: September 01, 2016, 12:08:33 pm »
Freeproxy binds to multiple nics and forwards traffic to any of those nics.  It runs as a single process or service.  I used to use it for forwarding usenet before switching to static routes.

Are you working in C/C++?  If I have some spare time I can try making you a proof-of-concept demo.

Offline Rdl

  • Administrator
  • *****
  • Posts: 3837
Re: Multi WAN
« Reply #18 on: September 01, 2016, 06:26:20 pm »
I'll take a look at freeproxy.

Offline wizziwig

  • Contributor
  • ***
  • Posts: 14
Re: Multi WAN
« Reply #19 on: September 02, 2016, 02:45:40 am »
I verified this works fine to connect a single process client through 2 different NICs to the same server.  The server process accepted two connections.  One from 192.168.1.7 and the other from 192.168.1.102.  Here is most of the code for the client.  I can give you server code as well but it's not important for this example.  Your server setup window in altbinz would need to have 3 fields: address, port, and optional local ip.  If you look at freeproxy, you can see they have a drop-down list of network cards instead of local bind address - this just makes it easier for the user but is not required.

Code: [Select]

        const char *serverAddressStr = "your news server url or ip";
int nPort = 119; //server port
const char *localNicAddressStr[2] = { "192.168.1.7", "192.168.1.102" };  //addresses assigned to each of your network cards.

u_long serverAddress = inet_addr(serverAddressStr);
if (serverAddress == INADDR_NONE)
{
// serverAddressStr isn't a dotted IP, so resolve it through DNS
hostent* pHE = gethostbyname(serverAddressStr);
if (pHE == 0)
return INADDR_NONE;
serverAddress = *((u_long*)pHE->h_addr_list[0]);
}

SOCKET sd[2];

//connect each network card to the server
for (int i = 0; i < 2; ++i)
{
sd[i] = socket(AF_INET, SOCK_STREAM, 0);

if (sd[i] != INVALID_SOCKET) {
sockaddr_in sinRemote;
sinRemote.sin_family = AF_INET;
sinRemote.sin_addr.s_addr = serverAddress;
sinRemote.sin_port = htons(nPort);

sockaddr_in sinInterface;

u_long nLocalAddr = inet_addr(localNicAddressStr[i]);
sinInterface.sin_family = AF_INET;
sinInterface.sin_addr.s_addr = nLocalAddr;
sinInterface.sin_port = 0; //assign automatic port
if (bind(sd[i], (sockaddr*)&sinInterface, sizeof(sockaddr_in)) != SOCKET_ERROR)
{
if (connect(sd[i], (sockaddr*)&sinRemote, sizeof(sockaddr_in)) == SOCKET_ERROR)
sd[i] = INVALID_SOCKET;
}
}
}

//send and receive message from each network card
const char* EchoMessage = "Echo Message";
const int EchoMessageLen = strlen(EchoMessage);

for (int i = 0; i < 2; ++i)
{
if (send(sd[i], EchoMessage, EchoMessageLen, 0) != SOCKET_ERROR)
{
//get reply from server
char ReadBuffer[128];
int TotalBytes = 0;
while (TotalBytes < EchoMessageLen)
{
int NewBytes = recv(sd[i], ReadBuffer + TotalBytes, 128 - TotalBytes, 0);
TotalBytes += NewBytes;
}
}
}


Offline Rdl

  • Administrator
  • *****
  • Posts: 3837
Re: Multi WAN
« Reply #20 on: September 02, 2016, 08:19:28 pm »
Done