Implement and use StringToPort().

If the given port string is invalid, the function returns 0.  This is
actually a parsing error, so in the future, we might want to raise a
proper error if that happens.