Check if hostname is valid, it fixes #3117