server: add safeguards against printing bogus port number