private void DeserializeAddrInfos(IVirtualMemoryManager memory, ulong address, ulong size) { ulong endAddress = address + size; while (address < endAddress) { AddrInfoSerializedHeader header = memory.Read <AddrInfoSerializedHeader>(address); if (header.Magic != SfdnsresContants.AddrInfoMagic) { break; } address += (ulong)Unsafe.SizeOf <AddrInfoSerializedHeader>() + header.AddressLength; // ai_canonname string canonname = string.Empty; while (true) { byte chr = memory.Read <byte>(address++); if (chr == 0) { break; } canonname += (char)chr; } } }
private static int SerializeAddrInfos(ServiceCtx context, ulong responseBufferPosition, ulong responseBufferSize, IPHostEntry hostEntry, int port) { ulong originalBufferPosition = responseBufferPosition; ulong bufferPosition = originalBufferPosition; byte[] hostName = Encoding.ASCII.GetBytes(hostEntry.HostName + '\0'); using (WritableRegion region = context.Memory.GetWritableRegion(responseBufferPosition, (int)responseBufferSize)) { Span <byte> data = region.Memory.Span; for (int i = 0; i < hostEntry.AddressList.Length; i++) { IPAddress ip = hostEntry.AddressList[i]; if (ip.AddressFamily != AddressFamily.InterNetwork) { continue; } // NOTE: 0 = Any AddrInfoSerializedHeader header = new AddrInfoSerializedHeader(ip, 0); AddrInfo4 addr = new AddrInfo4(ip, (short)port); AddrInfoSerialized info = new AddrInfoSerialized(header, addr, null, hostEntry.HostName); data = info.Write(data); } uint sentinel = 0; MemoryMarshal.Write(data, ref sentinel); data = data[sizeof(uint)..];
private static void DeserializeAddrInfos(IVirtualMemoryManager memory, ulong address, ulong size) { ulong endAddress = address + size; while (address < endAddress) { AddrInfoSerializedHeader header = memory.Read <AddrInfoSerializedHeader>(address); if (header.Magic != SfdnsresContants.AddrInfoMagic) { break; } address += (ulong)Unsafe.SizeOf <AddrInfoSerializedHeader>() + header.AddressLength; // ai_canonname string canonname = MemoryHelper.ReadAsciiString(memory, address); } }
private ulong SerializeAddrInfos(ServiceCtx context, long responseBufferPosition, long responseBufferSize, IPHostEntry hostEntry, int port) { ulong originalBufferPosition = (ulong)responseBufferPosition; ulong bufferPosition = originalBufferPosition; string hostName = hostEntry.HostName + '\0'; for (int i = 0; i < hostEntry.AddressList.Length; i++) { IPAddress ip = hostEntry.AddressList[i]; if (ip.AddressFamily != AddressFamily.InterNetwork) { continue; } AddrInfoSerializedHeader header = new AddrInfoSerializedHeader(ip, 0); // NOTE: 0 = Any context.Memory.Write(bufferPosition, header); bufferPosition += (ulong)Unsafe.SizeOf <AddrInfoSerializedHeader>(); // addrinfo_in context.Memory.Write(bufferPosition, new AddrInfo4(ip, (short)port)); bufferPosition += header.AddressLength; // ai_canonname context.Memory.Write(bufferPosition, Encoding.ASCII.GetBytes(hostName)); bufferPosition += (ulong)hostName.Length; } // Termination zero value. context.Memory.Write(bufferPosition, 0); bufferPosition += 4; return(bufferPosition - originalBufferPosition); }