Click to See Complete Forum and Search --> : How to connect computers in same LAN but different IP band by socket
April 23rd, 1999, 02:34 AM
Object: I am trying to establish socket connection between computers in the LAN
using TCP/IP, these computers belong to different domain and in different IP band.
Problem: If two computer are in same IP band, such as 192.168.1.xxx, they can be
connected. But if they are in different IP band, such as 192.168.0.xxx and 192.168.1.xxx,
connection can't be established.
If you know how to solve the problem, please reply here or send email to szl@morrowsoft.com
Thanks in advance.
klussier
April 23rd, 1999, 03:13 AM
Here's a summary of what's going on: let's say the machine you're on has IP address 192.168.1.10 and the machine you're trying to connect to has 192.168.0.20. Since the destination is not on your local area network (LAN), Windows will try to send your packet through your default gateway. Your default gateway (router) doesn't know how to get the packet there, so it gets dropped (or Windows gets a destination unreachable message). Either way, the packet never makes it to the destination.
It is possible, however, to fake Windows out in this regard. All you have to do is add a route on your machine to the destination (192.168.0.20). You would do that using route.exe:
route add 192.168.0.20 mask 255.255.255.255 192.168.1.10
This basically tells Windows to use itself as the default gateway for the specified IP address. Windows will ARP for the device itself. The device should respond and your packet will be sent.
If there is a chance that your device would not respond the the ARP request, you can add an explicit ARP entry, assuming you know the MAC address of the device:
arp -a 192.168.0.20 aa-bb-cc-dd-ee-ff
This tells Windows not to even bother doing the ARP request. So, Windows will then just dump the packet onto the LAN and your device should respond.
Hope this helps!
Kevin Lussier
klussier@home.com
P.S.: To do this programmatically is very difficult unless you are using Windows 98 or Windows NT SP4 or Windows 2000. If you are, then you can use the new CreateIpForwardEntry() and CreateIpNetEntry() functions to do what I've described above.
Daniel
April 23rd, 1999, 09:31 AM
You can't use a gateway with the IP address out of your network on Windows95/98 and WindowsNT Wks but you can on WindowsNT Server.
klussier
April 24th, 1999, 02:34 AM
Actually, you can. In fact, I do it all the time (on 95/98/NT). You're not setting up your machine to be a "router", but you are telling it how to route packets to a particular destination. Every single computer on the internet has a routing table and an ARP table. Under Windows, you can manipulate both.
Kevin
Sunset
April 24th, 1999, 04:11 AM
Thank you for your reply. I tried your methord but failed.
Below is the test procedure, can you tell me what is wrong?
Work environment: 4 computers in the LAN, 2 Windows'95 and 2 NT Server, they are in 2 domain
and different IP band. I test the methord in 2 computers.
Machine1: Windows'97, DomainName is "domain1", IP address is "192.168.1.200"
Machine2: NT Server, DomainName is "domain1", IP address is "192.168.0.1", MAC address is 00-00-E8-74-75-A7
Steps:
1. On machine1, execute "route add 192.168.0.1 mask 255.255.255.255 192.168.1.200"
2. On machine1, execute "arp -s 192.168.0.1 00-00-E8-74-75-A7"
4. On machine1, Run "Ping 192.168.0.1"
Result:
"Request time out"
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.