Skip to content

getHostname silently truncates to 64 bytes #18088

Closed
@timotheecour

Description

@timotheecour

getconf HOST_NAME_MAX
255
but could potentially be larger, see https://stackoverflow.com/questions/8724954/what-is-the-maximum-number-of-characters-for-a-host-name-in-unix

While the POSIX standard says it is guaranteed not to exceed 255 bytes, that does not necessarily mean that each implementation will adhere to that.

Example

change const size = 64 to const size = 5 (for eg) then run:
nim r --lib:lib --eval:'import nativesockets; echo getHostname()'

Current Output

shows my hostname truncated to 4 chars, and no error

Expected Output

don't truncate, or at least raise

Possible Solution

var buf {.noinit.}: array[256, char]

etc

Additional Information

1.5.1 7f077a7

links

just filed https://stackoverflow.com/questions/67844865/gethostname-silently-truncates-result-instead-of-giving-enametoolong-error

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions