public static void EncodeNetworkAddress(Stream stream, NetworkAddress networkAddress) { using (var writer = new BinaryWriter(stream, Encoding.ASCII, leaveOpen: true)) { writer.Write8Bytes(networkAddress.Services); writer.WriteBytes(16, networkAddress.IPv6Address.ToArray()); writer.Write2BytesBE(networkAddress.Port); } }