ipaddr: reorganize MarshalText and UnmarshalText

Also adds a test case.