PtrToString() публичный статический Метод

public static PtrToString ( IntPtr ptr ) : string
ptr System.IntPtr
Результат string
Пример #1
0
        public static void SplitServiceName(string service, out string name, out string type, out string domain)
        {
            int len = 1024;

            IntPtr namePtr   = Stdlib.malloc((ulong)len);
            IntPtr typePtr   = Stdlib.malloc((ulong)len);
            IntPtr domainPtr = Stdlib.malloc((ulong)len);

            int ret = avahi_service_name_split(Utility.StringToBytes(service), namePtr, len, typePtr, len,
                                               domainPtr, len);

            if (ret < 0)
            {
                Utility.Free(namePtr);
                Utility.Free(typePtr);
                Utility.Free(domainPtr);

                name   = null;
                type   = null;
                domain = null;
                return;
            }

            name   = Utility.PtrToString(namePtr);
            type   = Utility.PtrToString(typePtr);
            domain = Utility.PtrToString(domainPtr);

            Utility.Free(namePtr);
            Utility.Free(typePtr);
            Utility.Free(domainPtr);
        }
Пример #2
0
        private void OnDomainBrowserCallback(IntPtr browser, int iface, Protocol proto, BrowserEvent bevent,
                                             IntPtr domain, LookupResultFlags flags, IntPtr userdata)
        {
            DomainInfo info;

            info.NetworkInterface = iface;
            info.Protocol         = proto;
            info.Domain           = Utility.PtrToString(domain);
            info.Flags            = flags;

            switch (bevent)
            {
            case BrowserEvent.Added:
                infos.Add(info);

                foreach (DomainInfoHandler handler in addListeners)
                {
                    handler(this, new DomainInfoArgs(info));
                }
                break;

            case BrowserEvent.Removed:
                infos.Remove(info);

                foreach (DomainInfoHandler handler in removeListeners)
                {
                    handler(this, new DomainInfoArgs(info));
                }
                break;

            default:
                EmitBrowserEvent(bevent);
                break;
            }
        }
Пример #3
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;
            }
        }
Пример #4
0
        public static IPAddress PtrToAddress(IntPtr ptr)
        {
            IPAddress address = null;

            if (ptr != IntPtr.Zero)
            {
                IntPtr buf     = Stdlib.malloc(256);
                IntPtr addrPtr = avahi_address_snprint(buf, 256, ptr);
                address = IPAddress.Parse(Utility.PtrToString(addrPtr));
                Utility.Free(addrPtr);
            }

            return(address);
        }
Пример #5
0
        private void OnRecordBrowserCallback(IntPtr browser, int iface, Protocol proto, BrowserEvent bevent,
                                             IntPtr name, ushort clazz, ushort type, IntPtr rdata, int size,
                                             LookupResultFlags flags, IntPtr userdata)
        {
            RecordInfo info;

            info.NetworkInterface = iface;
            info.Protocol         = proto;
            info.Name             = Utility.PtrToString(name);
            info.Class            = (RecordClass)clazz;
            info.Type             = (RecordType)type;
            info.Flags            = flags;
            info.Data             = new byte[size];

            if (rdata != IntPtr.Zero)
            {
                Marshal.Copy(rdata, info.Data, 0, size);
            }

            switch (bevent)
            {
            case BrowserEvent.Added:
                infos.Add(info);

                foreach (RecordInfoHandler handler in addListeners)
                {
                    handler(this, new RecordInfoArgs(info));
                }

                break;

            case BrowserEvent.Removed:
                infos.Remove(info);

                foreach (RecordInfoHandler handler in removeListeners)
                {
                    handler(this, new RecordInfoArgs(info));
                }

                break;

            default:
                EmitBrowserEvent(bevent);
                break;
            }
        }
Пример #6
0
        private void OnServiceBrowserCallback(IntPtr browser, int iface, Protocol proto, BrowserEvent bevent,
                                              IntPtr name, IntPtr type, IntPtr domain, 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         = null;
            info.Address          = null;
            info.Port             = 0;
            info.Text             = null;
            info.Flags            = flags;

            switch (bevent)
            {
            case BrowserEvent.Added:
                infos.Add(info);

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

                break;

            case BrowserEvent.Removed:
                infos.Remove(info);

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

                break;

            default:
                EmitBrowserEvent(bevent);
                break;
            }
        }
Пример #7
0
        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;
            }
        }
Пример #8
0
        public static string JoinServiceName(string name, string type, string domain)
        {
            int    len = 4 * (name.Length + type.Length + domain.Length) + 4;
            IntPtr buf = Stdlib.malloc((ulong)len);

            int ret = avahi_service_name_join(buf, len,
                                              Utility.StringToBytes(name),
                                              Utility.StringToBytes(type),
                                              Utility.StringToBytes(domain));

            if (ret < 0)
            {
                Utility.Free(buf);
                return(null); // FIXME, should throw exception
            }

            string service = Utility.PtrToString(buf);

            Utility.Free(buf);

            return(service);
        }
Пример #9
0
        private static string GetErrorString(ErrorCode code)
        {
            IntPtr str = avahi_strerror(code);

            return(Utility.PtrToString(str));
        }