Create reliable method of checking if host is localhost

We finally found a reliable way to check if a given hostname is localhost. This PR creates the utility functions to perform such a check.