| Ticket UUID: | da235271f1e5c582eb54a93a893a85c2cbe2b76c | ||
| Title: | [info hostname] on Windows is limited to max NetBIOS name length | ||
| Type: | Bug | Created on: | 2020-02-21 01:41:14 |
| Submitter: | anonymous | Assigned to: | nobody |
| Subsystem: | 17. Commands I-L | Severity: | Minor |
| Priority: | 5 Medium | Last modified: | 2026-10-22 17:19:27 |
| Status: | Closed | Closed by: | serhiy.storchaka |
| Resolution: | Fixed | Closed on: | 2026-10-15 11:39:52 |
| Version: | 8.6.9 | ||
| Description: | ||||
I have a Windows host named "emake-ericm-11-2-x-202002210019-win2k12".
Using [info hostname] on this system gives me a result of "emake-ericm-11-".
This appears to be because in InitializeHostName() (in win/tclWinSock.c), Tcl
uses GetComputerNameW() to get the hostname:
https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-getcomputernamew
GetComputerNameW() is defined to return the NetBIOS name of the host, which is
limited to MAX_COMPUTERNAME_LENGTH, which is only 15 characters, at least on
some versions of Windows.
The documentation for [info hostname] states:
Returns the name of the computer on which this invocation is being executed.
Note that this name is not guaranteed to be the fully qualified domain name
of the host. Where machines have several different names (as is common
on systems with both TCP/IP (DNS) and NetBIOS-based networking installed,)
it is the name that is suitable for TCP/IP networking that is returned.
This seems to be in contradiction to the implementation, which returns the
NetBIOS name, not the DNS name. Tcl should instead use GetComputerNameExW,
which retrieves the DNS name of the host, or at least should try that first
and only fall back to GetComputerNameW if GetComputerNameExW has failed.
https://docs.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-getcomputernameexw
| ||||
| User Comments: | ||||
oehhar added on 2020-02-21 09:03:39:
Yes, tahnk you for the proposal. I suppose, the code is from the aera where Netbios name was prefered and DNS was (not jet) present in the Microsoft world. What do you think about the code in branch [bug-da235271f1-win-netbios-host-prefered]. Would this fix your issue ? Thank you, Harald jan.nijtmans added on 2020-02-21 09:30:45:
@Harald. You were faster then me, I only saw your commit after I committed my solutions. @emelski: Do you prefer to use GetComputerNameExW(), or do you prefer Harald's solution (using hostname()). My preference whould be GetComputerNameExW(), since it - theoretically - can handle more than ASCII. oehhar added on 2020-02-21 09:44:53:
Jan, thank you for the great fix. I suppose, this is ok. Don't you think, the order should be inverted and the netbios name should be taken as fallback? So first call it with ComputerNameDnsFullyQualified, then with ComputerNameNetBIOS? Thank you, Harald anonymous added on 2020-02-21 17:27:04:
Sorry, I don't know how to view the patches you have created -- I tried looking in https://core.tcl-lang.org/tcl/brlist but I couldn't find them. In any case, I think GetComputerNameExW is the right method to use, and it should try DNS first and then NetBIOS. The entire problem here is that Tcl is preferring the NetBIOS name instead of the DNS name. I'm not even sure it's possible to get a name longer than 15 characters from NetBIOS -- that is, I don't know if that is a limit inherent to NetBIOS or if that is "just" a limit of GetComputerNameW. It seems best therefore to default to the DNS name, and only try for the NetBIOS name if there is no DNS name. - emelski oehhar added on 2020-02-25 13:27:14:
Please first log in as anonymous (or your login if you have one): https://core.tcl-lang.org/tcl/login When logged in, there is a "ZIP Archive" link in the page of each checkin: Jan: [632704e948] Harald: [7fedbce431] We are interseted, if this solves your issue. Thank you, Harald apnadkarni added on 2020-04-23 12:37:38:
I would suggest the use of ComputerNamePhysicalDnsFullyQualified instead of ComputerNameDnsFullyQualified in the call to GetComputerNameExW. The latter will return the virtual name of the cluster if part of one whereas I think [info hostname] should return the real name of this system, not the cluster's DNS name. /Ashok oehhar added on 2020-04-30 15:43:51:
Thank you, Ashok. I think, that is reasonable. Performed Actions:
May I ask the original author again, if the issue is fixed by this modification ? Otherwise, I may close the ticket next week. Thank you all, Harald serhiy.storchaka added on 2026-10-15 11:39:52:
Fixed by [632704e948] and [2ba1cd687f], first released in 8.6.11. | ||||
