Closed dragokas closed 3 years ago
Yes, this is a regression. I'll see to it some time when I get back in front of my PC next week.
Thanks a much for your time to fix ip. That works now. I have several questions about it, if you don't mind.
Sorry, if they are too noob-like.
Following image demonstrates sending packets from host to guest VM and vice versa (that is a previous patch w/o port fix yet):
Host: ip - 192.168.31.4 gateway - 192.168.31.1
VM: ip - 192.168.202.169 gateway - 192.168.202.1
1) When I listen on "localhost" or "127.0.0.1" (no matter VM, or host) I cannot send a packet - saying "cannot connect ..." Is it a normal behaviour? The only way to receive a packet between network interfaces is to set the listener on current ip (192.168.31.4 (host) or 192.168.202.169 (vm)).
2) Listener (on host) said that the packet came from 192.168.31.4 which is its own ip! That is not correct since I sent it from vm. Vice versa. Litener on VM said that the packet came from 192.168.202.1 which is its gateway =) Maybe it is some specific behind inter-network interfaces transferring mechanism, so packet is losing info about its original sender...
3) Another case. Maybe you could suggest how correctly open port to see it externally from Internet and be able to send packets?
Test-NetConnection my.external.ip.address -Port 8088
Very appreciate your answers, when you have time.
When I listen on "localhost" or "127.0.0.1" (no matter VM, or host) I cannot send a packet - saying "cannot connect ..."
Try listen on 0.0.0.0
. This will listen both on localhost and all other assigned local IPs.
. . . said that the packet came from 192.168.31.4 which is its own ip
Is this VirtualBox? (No, I see it's VMWare now.) It uses NAT for VM networks by default. Try setting network to bridged and assign IP from your real LAN card subnet.
. . . made port forwarding on 8088 in my router.
If your VM is bridged it has "real" IP from your LAN subnet so you can forward directly to it. If forwarding is not working to your real machine probably listener was setup incorrectly on 127.0.0.1
.
When you start listener on 0.0.0.0
the Windows Firewall will popup a dialog suggesting to add your application to firewall inbound rules. This will be an indication your listener is setup correct :-))
Lot of thanks for your detailed explanations! They was very helpful. Everything works.
One question: by design, when we are listening for a "localhost" only "preferred" network interface is catched. What if we have 2 local network interfaces, but I want to listen for that second localhost interface (without 0.0.0.0, so a port should be invisible to the world). Is it possible?
You have to listen to a specific local IP address that is assigned to this second LAN adapter.
Since commit 186a4ddce5c81d17836068849b5ba82bf5f6b94c you can use GetLocalHost
method to retrieve an array with all local IPs as returned from GetAdaptersInfo
API.
I can tweak it to return more info like network name or default gateway address, not only IP and subnet mask as currently impl.
Is there a method to pass the whole array of IPs (subnet) from the second adapter to listen for?
No, you can either bind a socket on 0.0.0.0
(so called INADDR_ANY
to listen on all local IPs) or bind it to a single local IP address.
127.0.0.1 is the IP address of the local loopback adapter but so is 127.0.0.2 and every other address in 255.0.0.0 subnet so you can listen on (and connect to) all these addresses too.
Ok, thank you. I was thinking about trick to temporarily make second adapter to be preferred, then server.Listen "localhost", than return first adapter to be "preferred". Not sure, can it work that way =) Perhaps better just listen for 0.0.0.0 and use firewall to restrict external access to a port.
About security:
Is that a bug with RemoteHostIP / RemotePort, so we unable to verify the sender?