Fix some duplicated IP address parsing code.