Adds hostname support, fixes #343

Works from previous testing but I haven't tried this personal revision
of the code. Take it with a grain of salt.