PtrToAddress() public static méthode

public static PtrToAddress ( IntPtr ptr ) : IPAddress
ptr System.IntPtr
Résultat System.Net.IPAddress
Exemple #1
0
        private void OnServiceResolverCallback(IntPtr resolver, int iface, Protocol proto,
                                               ResolverEvent revent, IntPtr name, IntPtr type,
                                               IntPtr domain, IntPtr host, IntPtr address,
                                               UInt16 port, IntPtr txt, LookupResultFlags flags,
                                               IntPtr userdata)
        {
            ServiceInfo info;

            info.NetworkInterface = iface;
            info.Protocol         = proto;
            info.Domain           = Utility.PtrToString(domain);
            info.ServiceType      = Utility.PtrToString(type);
            info.Name             = Utility.PtrToString(name);
            info.HostName         = Utility.PtrToString(host);
            info.Address          = Utility.PtrToAddress(address);
            info.Port             = port;

            if (proto == Protocol.IPv6)
            {
                info.Address.ScopeId = iface;
            }

            ArrayList txtlist = new ArrayList();

            for (IntPtr l = txt; l != IntPtr.Zero; l = avahi_string_list_get_next(l))
            {
                IntPtr buf = avahi_string_list_get_text(l);
                int    len = avahi_string_list_get_size(l);

                byte[] txtbuf = new byte[len];
                Marshal.Copy(buf, txtbuf, 0, len);
                txtlist.Add(txtbuf);
            }

            info.Text  = (byte[][])txtlist.ToArray(typeof(byte[]));
            info.Flags = flags;

            switch (revent)
            {
            case ResolverEvent.Found:
                currentInfo = info;

                foreach (ServiceInfoHandler handler in foundListeners)
                {
                    handler(this, new ServiceInfoArgs(info));
                }
                break;

            case ResolverEvent.Failure:
                EmitFailure(client.LastError);
                break;
            }
        }
        private void OnHostNameResolverCallback(IntPtr resolver, int iface, Protocol proto,
                                                ResolverEvent revent, IntPtr hostname, IntPtr address,
                                                LookupResultFlags flags, IntPtr userdata)
        {
            switch (revent)
            {
            case ResolverEvent.Found:
                currentAddress = Utility.PtrToAddress(address);
                currentHost    = Utility.PtrToString(hostname);

                foreach (HostAddressHandler handler in foundListeners)
                {
                    handler(this, new HostAddressArgs(currentHost, currentAddress));
                }
                break;

            case ResolverEvent.Failure:
                EmitFailure(client.LastError);
                break;
            }
        }