CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Guest

    How to connect computers in same LAN but different IP band by socket

    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 [email protected]
    Thanks in advance.


  2. #2
    Join Date
    May 1999
    Posts
    8

    Re: How to connect computers in same LAN but different IP band by socket

    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
    [email protected]

    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.


  3. #3
    Join Date
    Apr 1999
    Posts
    15

    Re: How to connect computers in same LAN but different IP band by socket

    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.


  4. #4
    Join Date
    May 1999
    Posts
    8

    Re: How to connect computers in same LAN but different IP band by socket

    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


  5. #5
    Join Date
    Apr 1999
    Posts
    1

    Re: How to connect computers in same LAN but different IP band by socket

    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"


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured