Should this check for hostname != "" too?

Also, the hostname may be "localhost" if nothing has set it (either because none is provided or dhcp just hasn't finished yet). What do we do about that case?