DNSSDObjects への参照を MonoTouch のプロジェクト、特に DNSServiceResolve オブジェクトに追加したいと考えています。
MonoTouch プロジェクトで DNSServiceResolve にアクセスしたいのですが、そのクラスがどこにも見つかりません。
どうすればそれができますか?
DNSSDObjects への参照を MonoTouch のプロジェクト、特に DNSServiceResolve オブジェクトに追加したいと考えています。
MonoTouch プロジェクトで DNSServiceResolve にアクセスしたいのですが、そのクラスがどこにも見つかりません。
どうすればそれができますか?
P/Invokes で動作する dns_sd.h から関数を取得しました。ほとんどの定義は、プロジェクト zeroconfignetservices [1]、具体的にはファイル mDNSImports.cs で既に行われています。を参照する代わりに、iOS 上にdnssd.dll
あります。/usr/lib/system/libsystem_dnssd.dylib
たとえば、DNSServiceQueryRecord の定義は次のようになります。
[DllImport("/usr/lib/system/libsystem_dnssd.dylib")]
public static extern DNSServiceErrorType DNSServiceQueryRecord(out IntPtr sdRef,
DNSServiceFlags flags,
UInt32 interfaceIndex,
[MarshalAs(
UnmanagedType.CustomMarshaler,
MarshalTypeRef = typeof(Utf8Marshaler))] String fullname,
DNSServiceType rrType,
DNSServiceClass rrClass,
DNSServiceQueryReply callBack,
IntPtr context);
また、SRV レコードのクエリは次のようになります。
public void DoDnsLookup()
{
IntPtr sdRef;
var result = DNSServiceQueryRecord(
out sdRef,
DNSServiceFlags.LongLivedQuery,
0,
"_xmpp-client._tcp.gmail.com",
DNSServiceType.SRV,
DNSServiceClass.IN,
DnsServiceQueryReply,
IntPtr.Zero
);
if (result == DNSServiceErrorType.NoError)
{
DNSServiceProcessResult(sdRef);
DNSServiceRefDeallocate(sdRef);
}
}
//see [2] why this method is static and the attribute
[MonoPInvokeCallback(typeof(DNSServiceQueryReply))]
public static void DnsServiceQueryReply(
IntPtr sdRef,
DNSServiceFlags flags,
UInt32 interfaceIndex,
DNSServiceErrorType errorCode,
[MarshalAs(
UnmanagedType.CustomMarshaler,
MarshalTypeRef = typeof(Utf8Marshaler))] String fullname,
DNSServiceType rrType,
DNSServiceClass rrClass,
UInt16 rdLength,
[MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 7)]byte[] rData,
UInt32 ttl,
IntPtr context)
{
if (result == DNSServiceErrorType.NoError)
{
// process returned DNS data in rData
// a useful library for this could be Bdev.Net.Dns [3]
}
}
ここで定義されていないすべてのクラス、列挙型などは [1] からのものです。
参考文献: