net: avoid overflow when parsing ports