/// <summary> /// Loop epm receive process /// </summary> private static void epmReceiveLoop() { byte[] responseStub = new byte[eptMapResponseStub.Length]; Buffer.BlockCopy(eptMapResponseStub, 0, responseStub, 0, eptMapResponseStub.Length); while (true) { RpceServerSessionContext context; ushort opnum; try { byte[] requestStub = epmServer.ExpectCall(EPM_RECEIVE_LOOP_TIMEOUT, out context, out opnum); if (opnum == eptMapOpnum) { p_syntax_id_t ifSpec = new p_syntax_id_t(); // 37 == offset of interface uuid, 16 == the size of uuid ifSpec.if_uuid = new Guid(ArrayUtility.SubArray(requestStub, 37, 16)); //53 == offset of interface vers_major ifSpec.if_vers_major = BitConverter.ToUInt16(requestStub, 53); //57 == offset of interface vers_minor ifSpec.if_vers_minor = BitConverter.ToUInt16(requestStub, 57); if (endpointMap.ContainsKey(ifSpec)) { //copy tower from request stub to response stub //37 is the offset to interface uuid in request //53 is the offset to interface uuid in response Buffer.BlockCopy(requestStub, 37, responseStub, 53, 70); //modify the endpoint in big enddian oder, offset is 112 responseStub[112] = (byte)(endpointMap[ifSpec] >> 8); responseStub[113] = (byte)endpointMap[ifSpec]; //modify the address, offset is 119 Buffer.BlockCopy(hostIp.GetAddressBytes(), 0, responseStub, 119, 4); //todo support Ipv6 epmServer.SendResponse(context, responseStub); } } } catch (TimeoutException) { continue; } } }