Extract get_hostname functionality into reusable function.
Renamed to library-style name.