public PnrpRegisterTraceRecord(string meshId, PnrpPeerResolver.PnrpRegistration global, IEnumerable<PnrpPeerResolver.PnrpRegistration> siteEntries, IEnumerable<PnrpPeerResolver.PnrpRegistration> linkEntries)
 {
     this.meshId = meshId;
     this.siteEntries = siteEntries;
     this.linkEntries = linkEntries;
     this.global = global;
 }
 private void WriteEntry(XmlWriter writer, PnrpPeerResolver.PnrpRegistration entry)
 {
     if (entry != null)
     {
         writer.WriteStartElement("Registration");
         writer.WriteAttributeString("CloudName", entry.CloudName);
         foreach (IPEndPoint point in entry.Addresses)
         {
             writer.WriteElementString("Address", point.ToString());
         }
         writer.WriteEndElement();
     }
 }
 public static CriticalAllocHandle FromWsaQuerySetSafe(PnrpPeerResolver.UnsafePnrpNativeMethods.WsaQuerySetSafe safeQuerySet)
 {
     CriticalAllocHandle handle = CriticalAllocHandle.FromSize(CalculateSize(safeQuerySet));
     PnrpPeerResolver.UnsafePnrpNativeMethods.WsaQuerySetSafe.StructureToPtr(safeQuerySet, (IntPtr) handle);
     return handle;
 }
 private static int CalculateSize(PnrpPeerResolver.UnsafePnrpNativeMethods.WsaQuerySetSafe safeQuerySet)
 {
     int num = Marshal.SizeOf(typeof(PnrpPeerResolver.UnsafePnrpNativeMethods.WsaQuerySetNative));
     if (safeQuerySet.addressList != null)
     {
         num += safeQuerySet.addressList.Length * Marshal.SizeOf(typeof(PnrpPeerResolver.UnsafePnrpNativeMethods.CsAddrInfoNative));
     }
     return num;
 }
 public static void MarshalSafeAddressesToNative(PnrpPeerResolver.UnsafePnrpNativeMethods.WsaQuerySetSafe safeQuery, IntPtr target)
 {
     if ((safeQuery.addressList != null) && (safeQuery.addressList.Length > 0))
     {
         int num = Marshal.SizeOf(typeof(PnrpPeerResolver.UnsafePnrpNativeMethods.CsAddrInfoNative));
         long num2 = target.ToInt64();
         foreach (PnrpPeerResolver.UnsafePnrpNativeMethods.CsAddrInfoSafe safe in safeQuery.addressList)
         {
             PnrpPeerResolver.UnsafePnrpNativeMethods.CsAddrInfoSafe.StructureToPtr(safe, (IntPtr) num2);
             num2 += num;
         }
     }
 }
 public static void StructureToPtr(PnrpPeerResolver.UnsafePnrpNativeMethods.WsaQuerySetSafe input, IntPtr target)
 {
     PnrpPeerResolver.UnsafePnrpNativeMethods.WsaQuerySetNative structure = new PnrpPeerResolver.UnsafePnrpNativeMethods.WsaQuerySetNative {
         dwSize = input.dwSize,
         lpszServiceInstanceName = (IntPtr) input.lpszServiceInstanceName,
         lpServiceClassId = (IntPtr) input.lpServiceClassId,
         lpVersion = IntPtr.Zero,
         lpszComment = (IntPtr) input.lpszComment,
         dwNameSpace = input.dwNameSpace,
         lpNSProviderId = (IntPtr) input.lpNSProviderId,
         lpszContext = (IntPtr) input.lpszContext,
         dwNumberOfProtocols = 0,
         lpafpProtocols = IntPtr.Zero,
         lpszQueryString = IntPtr.Zero,
         dwNumberOfCsAddrs = input.dwNumberOfCsAddrs,
         dwOutputFlags = 0,
         lpBlob = (IntPtr) input.lpBlob
     };
     long num = target.ToInt64() + Marshal.SizeOf(typeof(PnrpPeerResolver.UnsafePnrpNativeMethods.WsaQuerySetNative));
     structure.lpcsaBuffer = (IntPtr) num;
     Marshal.StructureToPtr(structure, target, false);
     MarshalSafeAddressesToNative(input, (IntPtr) num);
 }
 public static PnrpPeerResolver.UnsafePnrpNativeMethods.WsaQuerySetSafe ToWsaQuerySetSafe(PnrpPeerResolver.UnsafePnrpNativeMethods.WsaQuerySet input)
 {
     PnrpPeerResolver.UnsafePnrpNativeMethods.WsaQuerySetSafe safe = new PnrpPeerResolver.UnsafePnrpNativeMethods.WsaQuerySetSafe();
     if (input != null)
     {
         safe.dwSize = Marshal.SizeOf(typeof(PnrpPeerResolver.UnsafePnrpNativeMethods.WsaQuerySetNative));
         safe.lpszServiceInstanceName = PnrpPeerResolver.UnsafePnrpNativeMethods.CriticalAllocHandleString.FromString(input.ServiceInstanceName);
         safe.lpServiceClassId = CriticalAllocHandleGuid.FromGuid(input.ServiceClassId);
         safe.lpszComment = PnrpPeerResolver.UnsafePnrpNativeMethods.CriticalAllocHandleString.FromString(input.Comment);
         safe.dwNameSpace = input.NameSpace;
         safe.lpNSProviderId = CriticalAllocHandleGuid.FromGuid(input.NSProviderId);
         safe.lpszContext = PnrpPeerResolver.UnsafePnrpNativeMethods.CriticalAllocHandleString.FromString(input.Context);
         safe.dwNumberOfProtocols = 0;
         safe.lpafpProtocols = IntPtr.Zero;
         safe.lpszQueryString = IntPtr.Zero;
         if (input.CsAddrInfos != null)
         {
             safe.dwNumberOfCsAddrs = input.CsAddrInfos.Length;
             safe.addressList = PnrpPeerResolver.UnsafePnrpNativeMethods.CsAddrInfoSafe.FromAddresses(input.CsAddrInfos);
         }
         safe.dwOutputFlags = 0;
         safe.lpBlob = PnrpPeerResolver.UnsafePnrpNativeMethods.CriticalAllocHandlePnrpBlob.FromPnrpBlob(input.Blob);
     }
     return safe;
 }
 public static void ToPnrpInfoNative(PnrpPeerResolver.UnsafePnrpNativeMethods.PnrpInfo source, ref PnrpPeerResolver.UnsafePnrpNativeMethods.PnrpInfoNative target)
 {
     target.dwSize = source.dwSize;
     target.lpwszIdentity = source.lpwszIdentity;
     target.nMaxResolve = source.nMaxResolve;
     target.dwTimeout = source.dwTimeout;
     target.dwLifetime = source.dwLifetime;
     target.enResolveCriteria = source.enResolveCriteria;
     target.dwFlags = source.dwFlags;
     if (source.saHint != null)
     {
         target.saHint.lpSockAddr = (IntPtr) source.saHint.lpSockAddr;
         target.saHint.iSockaddrLength = source.saHint.iSockaddrLength;
     }
     else
     {
         target.saHint.lpSockAddr = IntPtr.Zero;
         target.saHint.iSockaddrLength = 0;
     }
     target.enNameState = source.enNameState;
 }
 public static void StructureToPtr(PnrpPeerResolver.UnsafePnrpNativeMethods.CsAddrInfoSafe input, IntPtr target)
 {
     PnrpPeerResolver.UnsafePnrpNativeMethods.CsAddrInfoNative native;
     native.iProtocol = input.iProtocol;
     native.iSocketType = input.iSocketType;
     native.LocalAddr.iSockaddrLength = input.LocalAddr.iSockaddrLength;
     native.LocalAddr.lpSockAddr = (IntPtr) input.LocalAddr.lpSockAddr;
     native.RemoteAddr.iSockaddrLength = input.RemoteAddr.iSockaddrLength;
     native.RemoteAddr.lpSockAddr = (IntPtr) input.RemoteAddr.lpSockAddr;
     Marshal.StructureToPtr(native, target, false);
 }
 public PeerNameResolver(string peerName, int numberOfResultsRequested, PnrpPeerResolver.UnsafePnrpNativeMethods.PnrpResolveCriteria resolveCriteria, uint scopeId, string cloudName, TimeSpan timeout, List<PnrpPeerResolver.PnrpRegistration> results) : base(null, null)
 {
     if (timeout > PnrpPeerResolver.MaxTimeout)
     {
         timeout = PnrpPeerResolver.MaxTimeout;
     }
     this.timeoutHelper = new TimeoutHelper(timeout);
     PnrpPeerResolver.UnsafePnrpNativeMethods.PnrpInfo info = new PnrpPeerResolver.UnsafePnrpNativeMethods.PnrpInfo {
         dwSize = Marshal.SizeOf(typeof(PnrpPeerResolver.UnsafePnrpNativeMethods.PnrpInfo)),
         nMaxResolve = numberOfResultsRequested,
         dwTimeout = (int) timeout.TotalSeconds,
         dwLifetime = 0,
         enNameState = (PnrpPeerResolver.UnsafePnrpNativeMethods.PnrpRegisteredIdState) 0,
         lpwszIdentity = null,
         dwFlags = 1
     };
     IPEndPoint hint = PnrpPeerResolver.GetHint();
     info.enResolveCriteria = resolveCriteria;
     info.saHint = PnrpPeerResolver.UnsafePnrpNativeMethods.SOCKET_ADDRESS_SAFE.SocketAddressFromIPEndPoint(hint);
     this.resolveQuery = new PnrpPeerResolver.UnsafePnrpNativeMethods.WsaQuerySet();
     this.resolveQuery.ServiceInstanceName = peerName;
     this.resolveQuery.ServiceClassId = PnrpPeerResolver.UnsafePnrpNativeMethods.SvcIdNameV1;
     this.resolveQuery.NameSpace = PnrpPeerResolver.UnsafePnrpNativeMethods.NspNamespaces.Name;
     this.resolveQuery.NSProviderId = PnrpPeerResolver.UnsafePnrpNativeMethods.NsProviderName;
     this.resolveQuery.Context = cloudName;
     this.resolveQuery.Blob = info;
     this.results = results;
     this.scopeId = scopeId;
     ActionItem.Schedule(new Action<object>(this.SyncEnumeration), null);
 }
 public PeerNameResolver(string peerName, int numberOfResultsRequested, PnrpPeerResolver.UnsafePnrpNativeMethods.PnrpResolveCriteria resolveCriteria, TimeSpan timeout, List<PnrpPeerResolver.PnrpRegistration> results) : this(peerName, numberOfResultsRequested, resolveCriteria, 0, "Global_", timeout, results)
 {
 }
 private void RegisterService(PnrpPeerResolver.UnsafePnrpNativeMethods.WsaQuerySet registerQuery)
 {
     try
     {
         InvokeService(registerQuery, PnrpPeerResolver.UnsafePnrpNativeMethods.WsaSetServiceOp.Register, 0);
     }
     catch (PnrpPeerResolver.PnrpException)
     {
         if (4 >= registerQuery.CsAddrInfos.Length)
         {
             throw;
         }
         List<PnrpPeerResolver.UnsafePnrpNativeMethods.CsAddrInfo> list = new List<PnrpPeerResolver.UnsafePnrpNativeMethods.CsAddrInfo>(registerQuery.CsAddrInfos);
         list.RemoveRange(4, registerQuery.CsAddrInfos.Length - 4);
         registerQuery.CsAddrInfos = list.ToArray();
         InvokeService(registerQuery, PnrpPeerResolver.UnsafePnrpNativeMethods.WsaSetServiceOp.Register, 0);
     }
 }
 public void Register(PnrpPeerResolver.PnrpRegistration registration, TimeSpan timeout)
 {
     PnrpPeerResolver.UnsafePnrpNativeMethods.PnrpInfo info;
     info = new PnrpPeerResolver.UnsafePnrpNativeMethods.PnrpInfo {
         dwLifetime = 0xe10,
         lpwszIdentity = null,
         dwSize = Marshal.SizeOf(info),
         dwFlags = 1
     };
     IPEndPoint hint = PnrpPeerResolver.GetHint();
     info.saHint = PnrpPeerResolver.UnsafePnrpNativeMethods.SOCKET_ADDRESS_SAFE.SocketAddressFromIPEndPoint(hint);
     PnrpPeerResolver.UnsafePnrpNativeMethods.WsaQuerySet registerQuery = new PnrpPeerResolver.UnsafePnrpNativeMethods.WsaQuerySet {
         NameSpace = PnrpPeerResolver.UnsafePnrpNativeMethods.NspNamespaces.Name,
         NSProviderId = PnrpPeerResolver.UnsafePnrpNativeMethods.NsProviderName,
         ServiceClassId = PnrpPeerResolver.UnsafePnrpNativeMethods.SvcIdNameV1,
         ServiceInstanceName = registration.PeerName,
         Comment = registration.Comment,
         Context = registration.CloudName
     };
     if (registration.Addresses != null)
     {
         registerQuery.CsAddrInfos = new PnrpPeerResolver.UnsafePnrpNativeMethods.CsAddrInfo[registration.Addresses.Length];
         for (int i = 0; i < registration.Addresses.Length; i++)
         {
             registerQuery.CsAddrInfos[i].LocalAddr = registration.Addresses[i];
             registerQuery.CsAddrInfos[i].iProtocol = 6;
             registerQuery.CsAddrInfos[i].iSocketType = 1;
         }
     }
     registerQuery.Blob = info;
     this.RegisterService(registerQuery);
 }
 private static void InvokeService(PnrpPeerResolver.UnsafePnrpNativeMethods.WsaQuerySet registerQuery, PnrpPeerResolver.UnsafePnrpNativeMethods.WsaSetServiceOp op, int flags)
 {
     PnrpPeerResolver.UnsafePnrpNativeMethods.WsaQuerySetSafe safeQuerySet = PnrpPeerResolver.UnsafePnrpNativeMethods.WsaQuerySet.ToWsaQuerySetSafe(registerQuery);
     using (safeQuerySet)
     {
         if (PnrpPeerResolver.UnsafePnrpNativeMethods.WSASetService(PnrpPeerResolver.UnsafePnrpNativeMethods.CriticalAllocHandleWsaQuerySetSafe.FromWsaQuerySetSafe(safeQuerySet), op, flags) != 0)
         {
             PeerExceptionHelper.ThrowPnrpError(PnrpPeerResolver.UnsafePnrpNativeMethods.WSAGetLastError(), registerQuery.Context);
         }
     }
 }
 private void DeleteService(PnrpPeerResolver.UnsafePnrpNativeMethods.WsaQuerySet registerQuery)
 {
     InvokeService(registerQuery, PnrpPeerResolver.UnsafePnrpNativeMethods.WsaSetServiceOp.Delete, 0);
 }
 private int InvokeService(PnrpPeerResolver.UnsafePnrpNativeMethods.WsaQuerySet registerQuery, PnrpPeerResolver.UnsafePnrpNativeMethods.WsaSetServiceOp op, int flags)
 {
     PnrpPeerResolver.UnsafePnrpNativeMethods.WsaQuerySetSafe safeQuerySet = PnrpPeerResolver.UnsafePnrpNativeMethods.WsaQuerySet.ToWsaQuerySetSafe(registerQuery);
     int num = 0;
     using (safeQuerySet)
     {
         CriticalAllocHandle querySet = PnrpPeerResolver.UnsafePnrpNativeMethods.CriticalAllocHandleWsaQuerySetSafe.FromWsaQuerySetSafe(safeQuerySet);
         using (querySet)
         {
             if (PnrpPeerResolver.UnsafePnrpNativeMethods.WSASetService(querySet, op, flags) != 0)
             {
                 num = PnrpPeerResolver.UnsafePnrpNativeMethods.WSAGetLastError();
             }
         }
     }
     return num;
 }
 private static IPEndPoint IPEndPointFromSocketAddress(PnrpPeerResolver.UnsafePnrpNativeMethods.SOCKET_ADDRESS_NATIVE socketAddress, uint scopeId)
 {
     IPEndPoint point = null;
     if (!(socketAddress.lpSockAddr != IntPtr.Zero))
     {
         return point;
     }
     AddressFamily family = (AddressFamily) Marshal.ReadInt16(socketAddress.lpSockAddr);
     if (family == AddressFamily.InterNetwork)
     {
         if (socketAddress.iSockaddrLength == Marshal.SizeOf(typeof(PnrpPeerResolver.UnsafePnrpNativeMethods.sockaddr_in)))
         {
             PnrpPeerResolver.UnsafePnrpNativeMethods.sockaddr_in _in = (PnrpPeerResolver.UnsafePnrpNativeMethods.sockaddr_in) Marshal.PtrToStructure(socketAddress.lpSockAddr, typeof(PnrpPeerResolver.UnsafePnrpNativeMethods.sockaddr_in));
             point = new IPEndPoint(new IPAddress(_in.sin_addr), _in.sin_port);
         }
         return point;
     }
     if ((family != AddressFamily.InterNetworkV6) || (socketAddress.iSockaddrLength != Marshal.SizeOf(typeof(PnrpPeerResolver.UnsafePnrpNativeMethods.sockaddr_in6))))
     {
         return point;
     }
     PnrpPeerResolver.UnsafePnrpNativeMethods.sockaddr_in6 _in2 = (PnrpPeerResolver.UnsafePnrpNativeMethods.sockaddr_in6) Marshal.PtrToStructure(socketAddress.lpSockAddr, typeof(PnrpPeerResolver.UnsafePnrpNativeMethods.sockaddr_in6));
     if ((scopeId != 0) && (_in2.sin6_scope_id != 0))
     {
         scopeId = _in2.sin6_scope_id;
     }
     return new IPEndPoint(new IPAddress(_in2.sin6_addr, (long) scopeId), _in2.sin6_port);
 }
 public static PnrpPeerResolver.UnsafePnrpNativeMethods.CsAddrInfoSafe[] FromAddresses(PnrpPeerResolver.UnsafePnrpNativeMethods.CsAddrInfo[] addresses)
 {
     PnrpPeerResolver.UnsafePnrpNativeMethods.CsAddrInfoSafe[] safeArray = null;
     if ((addresses == null) || (addresses.Length == 0))
     {
         return null;
     }
     safeArray = new PnrpPeerResolver.UnsafePnrpNativeMethods.CsAddrInfoSafe[addresses.Length];
     int num = 0;
     foreach (PnrpPeerResolver.UnsafePnrpNativeMethods.CsAddrInfo info in addresses)
     {
         PnrpPeerResolver.UnsafePnrpNativeMethods.CsAddrInfoSafe safe = new PnrpPeerResolver.UnsafePnrpNativeMethods.CsAddrInfoSafe {
             LocalAddr = PnrpPeerResolver.UnsafePnrpNativeMethods.SOCKET_ADDRESS_SAFE.SocketAddressFromIPEndPoint(info.LocalAddr),
             RemoteAddr = PnrpPeerResolver.UnsafePnrpNativeMethods.SOCKET_ADDRESS_SAFE.SocketAddressFromIPEndPoint(info.RemoteAddr),
             iProtocol = info.iProtocol,
             iSocketType = info.iSocketType
         };
         safeArray[num++] = safe;
     }
     return safeArray;
 }