Skip to content

Commit

Permalink
Update getHost() function to support unicode characters (fix #23)
Browse files Browse the repository at this point in the history
  • Loading branch information
chvancooten committed Dec 21, 2023
1 parent 70bf4c3 commit 02e9296
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions client/util/winUtils.nim
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from nativesockets import getHostName, gethostbyname
from nativesockets import gethostbyname
from os import getCurrentProcessId, splitPath, getAppFilename, createDir, walkDir, splitPath, pcDir, `/`, removeDir
from winim/lean import CopyFileA, FALSE, ULONG, winstrConverterStringToPtrChar
from winim/lean import CopyFileA, GetComputerNameW, winstrConverterStringToPtrChar
from winim/utils import `&`
import winim/inc/[windef, winbase]
import ../commands/whoami
import strenc

Expand Down Expand Up @@ -61,7 +63,15 @@ proc getUsername*() : string =

# Get the hostname
proc getHost*() : string =
result = getHostName()
var
buf : array[257, TCHAR]
lpBuf : LPWSTR = addr buf[0]
pcbBuf : DWORD = int32(len(buf))

discard GetComputerNameW(lpBuf, &pcbBuf)
for character in buf:
if character == 0: break
result.add(char(character))

# Get the internal IP
proc getIntIp*() : string =
Expand Down

0 comments on commit 02e9296

Please sign in to comment.