Project

General

Profile

Feature #4181

GetComputerNameA emulation

Added by Greg Shah almost 5 years ago. Updated over 3 years ago.

Status:
Closed
Priority:
Normal
Target version:
-
Start date:
Due date:
% Done:

100%

billable:
No
vendor_id:
GCD
version_reported:
version_resolved:

Related issues

Related to User Interface - Feature #4203: expose some web-client details as 4GL global variables Closed

History

#1 Updated by Greg Shah almost 5 years ago

The idea here is to emulate this API call. The big issue is what to return. For the computername, in the web client, we should return the hostname or IP address of the client browser. But which one? There may be two addresses:

  • The browser's system IP address, which can be read from Javascript in modern browsers using WebRTC.
  • The external IP address of the Internet system with which the server (FWD client JVM in this case) is communicating. In a NAT firewall or proxy case (which is common), this will be the address of the gateway (the firewall or proxy) and the browser's system IP address would be on a private network (e.g. something like 192.168.x.y which is not a valid Internet address).

If the browser's address is directly on the Internet, then that one is best.

But what do we do when the IP address seen by the server is different from the one that the browser can see? The external address can be looked up via reverse DNS, but it will be shared between many actual browser clients. The internal address is private but is more likely to be unique.

Other alternatives:

  • same some unique token in a permanent cookie and read/return that value (or a mapped name that is associated with that value); the issue here is how to get the mapped name in the first place
  • return some unique fingerprint based on values that can be read in JavaScript such as the OS, browser etc...; this may easily be duplicated in multiple clients so it may not be the best idea

#2 Updated by Greg Shah almost 5 years ago

  • Related to Feature #4203: expose some web-client details as 4GL global variables added

#3 Updated by Greg Shah over 4 years ago

In #4121, a number of winsock native API emulation methods were added. This led to the implementation of LogicalTerminal.getHostName() and LogicalTerminal.getHostByName() both of which return the client's IP address. This is implemented in the screen-driver, which means that it comes from the browser in the case of the web client. These changes are in trunk already. The IP address is read using WebRTC (if possible) when the client is started. This can be repurposed for this use case.

#4 Updated by Roger Borrello over 4 years ago

  • Assignee set to Roger Borrello

GetComputerNameA is defined as returning the NetBIOS name established at system startup. Further: "If the caller is running under a client session, this function returns the server name. To retrieve the client name, use the WTSQuerySessionInformation function."

Does that change how we look at what should be returned?

#5 Updated by Greg Shah over 4 years ago

Not really. I don't think we care about the netbios names of client or server. We are just trying to provide a name for the machine. We would prefer to return the hostname instead of an IP address, since the calling code expects a name. To do this we would have to do a reverse lookup of the IP address, which will work in Java if the DNS is setup.

Also we would only want to "resolve" this once. Then it should be cached for the current session's lifetime.

#6 Updated by Roger Borrello over 4 years ago

Is it valid to simply return what returned by LogicalTerminal.getHostName()?

#7 Updated by Greg Shah over 4 years ago

Roger Borrello wrote:

Is it valid to simply return what returned by LogicalTerminal.getHostName()?

Only as a last resort. Please try to get a result from the reverse lookup first. If there is no result, then return the IP. You can try using java.net.InetAddress. For example:

InetAddress addr = InetAddress.getByName(ip_addr_as_string);
if (addr != null)
{
   // use addr.getCanonicalHostName() here
}

#8 Updated by Igor Skornyakov over 4 years ago

In addition to the problem with NAT/proxy mentioned in the initial task description please consider the case of multiple IP addresses. In this scenario, different clients can have access to different IP addresses (and even in case of a single IP address the reverse DNS lookup can potentially provide different DNS names).
If I remember correctly this problem does not exist for NetBIOS names which are the names of the machine and are resolved via broadcast.

#9 Updated by Greg Shah over 4 years ago

True. It does NOT make sense to do a reverse lookup. Just return the IP address as returned by LogicalTerminal.getHostName(). If that code needs additional changes to better handle multiple client-side IP addresses, then we will fix it there.

#10 Updated by Roger Borrello over 4 years ago

  • Status changed from New to WIP
  • % Done changed from 0 to 100

Implemented with a TODO based upon future customer specifications. Ultimately to be implemented in the client drivers. Right now, it will return LogicalTerminal.getHostName() results.

Commited in 4207a-11400

#11 Updated by Greg Shah over 4 years ago

  • Status changed from WIP to Test

#12 Updated by Greg Shah over 3 years ago

  • Status changed from Test to Closed

Also available in: Atom PDF