mDNSResponder-client-1.0.3: Library for talking to the mDNSResponder daemon.

Copyright(c) 2016 Obsidian Systems LLC
Safe HaskellNone






Managing connections

data Connection Source #

A connection to the daemon.

connect Source #


:: SockAddr

The address of the daemon.

You probably want defaultAddr. In any case, the implementation currently only works for AF_UNIX-based daemons, even though there are AF_INET-based daemons in existence.

-> AsyncConnectionErrorHandler 
-> IO (Either DNSServiceErrorType Connection) 

Connect to the daemon.

disconnect :: Connection -> IO () Source #

Disconnect from the daemon.

It is an error to use the passed in Connection during or after this call, though it is safe to call this again if it fails due to an asynchronous exception.

defaultAddr :: IO SockAddr Source #

The default address for the daemon.

type AsyncConnectionErrorHandler = AsyncConnectionError -> IO () Source #

Handle a generic error communicating with the daemon.

These errors may occur at any time, are not associated with any particular request, and are not generally recoverable. You should still call disconnect to clean up resources after recieving an error.

The handler is called in its own thread.

Data types

type NullFreeByteString = ByteString Source #

A ByteString with no null characters.

This invariant must be maintained by the caller.


data DNSServiceFlags Source #

Flag type for API calls.

Error codes

kDNSServiceErr_ServiceNotRunning :: DNSServiceErrorType Source #

The daemon is not running/closed the connection.

You should still call disconnect to clean up resources!

kDNSServiceErr_ShortResponse :: DNSServiceErrorType Source #

The response sent by the daemon was too short.

This is not an upstream error code, the official Apple client just declines to call the callback in this case. It is outside of the documented range for mDNS error codes.

Interface indices

data InterfaceIndex Source #

An index to specify on which interface a service exists.

kDNSServiceInterfaceIndexAny :: InterfaceIndex Source #

The service is served on any interface.

kDNSServiceInterfaceIndexLocalOnly :: InterfaceIndex Source #

The service is only served to the local host.


data Request a where Source #

A request to the mDNSResponder daemon.

Parameterized by the type of the response.

Constructor fields documented with the constructor due to

See also the documentation for these requests in dns_sd.h


ServiceRegister :: !DNSServiceFlags -> !InterfaceIndex -> !NullFreeByteString -> !NullFreeByteString -> !NullFreeByteString -> !NullFreeByteString -> !PortNumber -> !ByteString -> Request NTDResponse

Register a service.


  1. flags: Indicate behavior on name conflict.
  2. index: The interface(s) on which to register the service.
  3. name: The service name to be registered, or empty for the default.
  4. type: The service type followed by the protocol, separated by a dot.
  5. domain: The domain on which to advertise, or empty for the default domains.
  6. host: The SRV target host name, or empty for the default host name(s).
  7. port: The port the service listens on.
  8. txt: The text record data, or empty for none.
ServiceBrowse :: !InterfaceIndex -> !NullFreeByteString -> !NullFreeByteString -> Request NTDResponse

Browse for a service.


  1. index: The interface(s) on which to browse.
  2. regtype: The service type being browsed for followed by the protocol, with optional subtypes or group IDs.
  3. domain: The domain on which to browse, or empty for the default.
ServiceResolve :: !DNSServiceFlags -> !InterfaceIndex -> !NullFreeByteString -> !NullFreeByteString -> !NullFreeByteString -> Request ResolveResponse

Resolve a service.

You probably want to populate the name, regtype, and domain from the results of a ServiceBrowse request.


  1. flags: Specify multicast behavior.
  2. index: The interface(s) on which to resolve.
  3. name: The name of the service to be resolved.
  4. regtype: The type of the service to be resolved.
  5. domain: The domain of the service to be resolved.

request Source #


:: PeekableResponse a 
=> Connection 
-> Request a 
-> AsyncResponseHandler a 
-> IO DNSServiceErrorType

The immediate error from the daemon, if any. Even if kDNSServiceErr_NoError is returned here, there still may be asynchronous errors for this request.

Send a request to the daemon.

The PeekableResponse constraint is an implementation detail, all Requests have a type appropriate for request. Unfortunately, it doesn't seem possible to hide this constraint from the haddock docs.


type AsyncResponseHandler a = Either DNSServiceErrorType (Response a) -> IO () Source #

Handle asynchronous responses to a request.

Some requests result in multiple responses.

The handler is called on its own thread.

data ResponseHeader Source #

The shared header for daemon responses.

The header also contains an error code on the wire, but it's always kDNSServiceErr_NoError on code paths that get passed a header.




data Response a Source #

A response with its header.


Response !ResponseHeader !a 

data NTDResponse Source #

A response containing a name, registration type, and domain.




data ResolveResponse Source #

A response to a ServiceResolve request.