Move common code to netutil