Slightly better checking for valid ip and port.

This check if the value of the port number is also in the allowed
range. Few other Go idiom related changes.