Mono.Zeroconf – Blame information for rev 2

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 //
2 // Native.cs
3 //
4 // Authors:
5 // Aaron Bockover <abockover@novell.com>
6 //
7 // Copyright (C) 2006-2007 Novell, Inc (http://www.novell.com)
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28  
29 using System;
2 office 30 using System.Text;
1 office 31 using System.Runtime.InteropServices;
32  
33 namespace Mono.Zeroconf.Providers.Bonjour
34 {
35 public static class Native
36 {
37 // ServiceRef
38  
39 [DllImport("dnssd.dll")]
40 public static extern void DNSServiceRefDeallocate(IntPtr sdRef);
41  
42 [DllImport("dnssd.dll")]
43 public static extern ServiceError DNSServiceProcessResult(IntPtr sdRef);
44  
45 [DllImport("dnssd.dll")]
46 public static extern int DNSServiceRefSockFD(IntPtr sdRef);
47  
48 [DllImport("dnssd.dll")]
49 public static extern ServiceError DNSServiceCreateConnection(out ServiceRef sdRef);
50  
51 // DNSServiceBrowse
52  
53 public delegate void DNSServiceBrowseReply(ServiceRef sdRef, ServiceFlags flags, uint interfaceIndex,
2 office 54 ServiceError errorCode, IntPtr serviceName, string regtype, string replyDomain,
1 office 55 IntPtr context);
56  
57 [DllImport("dnssd.dll")]
58 public static extern ServiceError DNSServiceBrowse(out ServiceRef sdRef, ServiceFlags flags,
59 uint interfaceIndex, string regtype, string domain, DNSServiceBrowseReply callBack,
60 IntPtr context);
61  
62 // DNSServiceResolve
63  
64 public delegate void DNSServiceResolveReply(ServiceRef sdRef, ServiceFlags flags, uint interfaceIndex,
2 office 65 ServiceError errorCode, IntPtr fullname, string hosttarget, ushort port, ushort txtLen,
1 office 66 IntPtr txtRecord, IntPtr context);
67  
68 [DllImport("dnssd.dll")]
69 public static extern ServiceError DNSServiceResolve(out ServiceRef sdRef, ServiceFlags flags,
2 office 70 uint interfaceIndex, byte[] name, string regtype, string domain, DNSServiceResolveReply callBack,
1 office 71 IntPtr context);
72  
73 // DNSServiceRegister
74  
75 public delegate void DNSServiceRegisterReply(ServiceRef sdRef, ServiceFlags flags, ServiceError errorCode,
2 office 76 IntPtr name, string regtype, string domain, IntPtr context);
77  
78  
1 office 79 [DllImport("dnssd.dll")]
80 public static extern ServiceError DNSServiceRegister(out ServiceRef sdRef, ServiceFlags flags,
2 office 81 uint interfaceIndex, byte[] name, string regtype, string domain, string host, ushort port,
1 office 82 ushort txtLen, byte [] txtRecord, DNSServiceRegisterReply callBack, IntPtr context);
83  
84 // DNSServiceQueryRecord
85  
86 public delegate void DNSServiceQueryRecordReply(ServiceRef sdRef, ServiceFlags flags, uint interfaceIndex,
87 ServiceError errorCode, string fullname, ServiceType rrtype, ServiceClass rrclass, ushort rdlen,
88 IntPtr rdata, uint ttl, IntPtr context);
89  
90 [DllImport("dnssd.dll")]
91 public static extern ServiceError DNSServiceQueryRecord(out ServiceRef sdRef, ServiceFlags flags,
92 uint interfaceIndex, string fullname, ServiceType rrtype, ServiceClass rrclass,
93 DNSServiceQueryRecordReply callBack, IntPtr context);
94  
95 // TXT Record Handling
96  
97 [DllImport("dnssd.dll")]
98 public static extern void TXTRecordCreate( IntPtr txtRecord, ushort bufferLen, IntPtr buffer);
99  
100 [DllImport("dnssd.dll")]
101 public static extern void TXTRecordDeallocate(IntPtr txtRecord);
102  
103 [DllImport("dnssd.dll")]
104 public static extern ServiceError TXTRecordGetItemAtIndex(ushort txtLen, IntPtr txtRecord,
105 ushort index, ushort keyBufLen, byte [] key, out byte valueLen, out IntPtr value);
106  
107 [DllImport("dnssd.dll")]
108 public static extern ServiceError TXTRecordSetValue(IntPtr txtRecord, byte [] key,
109 sbyte valueSize, byte [] value);
110  
111 [DllImport("dnssd.dll")]
112 public static extern ServiceError TXTRecordRemoveValue(IntPtr txtRecord, byte [] key);
113  
114 [DllImport("dnssd.dll")]
115 public static extern ushort TXTRecordGetLength(IntPtr txtRecord);
116  
117 [DllImport("dnssd.dll")]
118 public static extern IntPtr TXTRecordGetBytesPtr(IntPtr txtRecord);
119  
120 [DllImport("dnssd.dll")]
121 public static extern ushort TXTRecordGetCount(ushort txtLen, IntPtr txtRecord);
2 office 122  
123 public static string Utf8toString(IntPtr ptr)
124 {
125 int len = 0;
126 while (Marshal.ReadByte(ptr, len) != 0)
127 {
128 len++;
129 }
130 byte[] raw = new byte[len];
131 Marshal.Copy(ptr, raw, 0, len);
132 return Encoding.UTF8.GetString(raw);
133 }
1 office 134 }
135 }