<!--
{
  "documentType" : "article",
  "framework" : "dnssd",
  "identifier" : "/documentation/dnssd/dns-service-discovery-c",
  "metadataVersion" : "0.1.0",
  "role" : "collectionGroup",
  "title" : "DNS Service Discovery C"
}
-->

# DNS Service Discovery C

See the Overview section above for header-level documentation.

## Discussion

### Overview

#### Included Headers

- [types.h](https://developer.apple.com/library/archive/documentation/Darwin/Reference/usr_APIs/types/index.html#//apple_ref/doc/header/types.h)
- [types.h](https://developer.apple.com/library/archive/documentation/Darwin/Reference/usr_APIs/types/index.html#//apple_ref/doc/header/types.h)
- “Tiano.h”
- <windows.h>
- <stdint.h>
- <dispatch/dispatch.h>

## Topics

### Version checking

[`DNSServiceGetProperty(_:_:_:)`](/documentation/dnssd/DNSServiceGetProperty(_:_:_:))

Gets the specified property of a service.

### Unix Domain Socket access, DNSServiceRef deallocation, and data processing functions

[`DNSServiceProcessResult(_:)`](/documentation/dnssd/DNSServiceProcessResult(_:))

Reads a reply from the daemon, calling the appropriate application callback.

[`DNSServiceRefDeallocate(_:)`](/documentation/dnssd/DNSServiceRefDeallocate(_:))

Terminates a connection with the daemon and frees memory associated with the DNSServiceRef.

[`DNSServiceRefSockFD(_:)`](/documentation/dnssd/DNSServiceRefSockFD(_:))

Accesses underlying Unix domain socket for an initialized DNSServiceRef.

### Unified lookup of both IPv4 and IPv6 addresses for a fully qualified hostname

[`DNSServiceGetAddrInfo(_:_:_:_:_:_:_:)`](/documentation/dnssd/DNSServiceGetAddrInfo(_:_:_:_:_:_:_:))

Queries for the IP address of a hostname by using either Multicast or Unicast DNS.

### TXT Record Parsing Functions

A typical calling sequence for TXT record parsing is something like:

Receive TXT record data in [`DNSServiceResolve(_:_:_:_:_:_:_:_:)`](/documentation/dnssd/DNSServiceResolve(_:_:_:_:_:_:_:_:)) callback

```objc
 
 if (TXTRecordContainsKey(txtLen, txtRecord, "key")) then do something
 val1ptr = TXTRecordGetValuePtr(txtLen, txtRecord, "key1", &len1);
 val2ptr = TXTRecordGetValuePtr(txtLen, txtRecord, "key2", &len2);
 ...
 memcpy(myval1, val1ptr, len1);
 memcpy(myval2, val2ptr, len2);
 ...
 return;
 
```

If you wish to retain the values after return from the [`DNSServiceResolve(_:_:_:_:_:_:_:_:)`](/documentation/dnssd/DNSServiceResolve(_:_:_:_:_:_:_:_:)) callback, then you need to copy the data to your own storage using memcpy() or similar, as shown in the example above.

If for some reason you need to parse a TXT record you built yourself using the TXT record construction functions above, then you can do that using TXTRecordGetLength and TXTRecordGetBytesPtr calls: TXTRecordGetValue(TXTRecordGetLength(x), TXTRecordGetBytesPtr(x), key, &len);

Most applications only fetch keys they know about from a TXT record and ignore the rest. However, some debugging tools wish to fetch and display all keys. To do that, use the TXTRecordGetCount() and TXTRecordGetItemAtIndex() calls.

[DNSServiceCreateDelegateConnection](/documentation/dnssd/DNSServiceCreateDelegateConnection)

Create a delegate connection to the daemon allowing efficient registration of multiple individual records.

[`DNSServiceSetDispatchQueue(_:_:)`](/documentation/dnssd/DNSServiceSetDispatchQueue(_:_:))

Allows you to schedule a DNSServiceRef on a serial dispatch queue for receiving asynchronous callbacks.

[`TXTRecordContainsKey(_:_:_:)`](/documentation/dnssd/TXTRecordContainsKey(_:_:_:))

Allows you to determine if a given TXT Record contains a specified key.

[`TXTRecordGetCount(_:_:)`](/documentation/dnssd/TXTRecordGetCount(_:_:))

Returns the number of keys stored in the TXT Record.

[`TXTRecordGetItemAtIndex(_:_:_:_:_:_:_:)`](/documentation/dnssd/TXTRecordGetItemAtIndex(_:_:_:_:_:_:_:))

Allows you to retrieve a key name and value pointer, given an index into a TXT Record.

[`TXTRecordGetValuePtr(_:_:_:_:)`](/documentation/dnssd/TXTRecordGetValuePtr(_:_:_:_:))

Allows you to retrieve the value for a given key from a TXT Record.

### TXT Record Construction Functions

[`TXTRecordCreate(_:_:_:)`](/documentation/dnssd/TXTRecordCreate(_:_:_:))

Creates a new empty TXTRecordRef referencing the specified storage.

[`TXTRecordDeallocate(_:)`](/documentation/dnssd/TXTRecordDeallocate(_:))

Releases resources associated with a TXT record.

[`TXTRecordGetBytesPtr(_:)`](/documentation/dnssd/TXTRecordGetBytesPtr(_:))

Allows you to retrieve a pointer to the raw bytes within a TXTRecordRef.

[`TXTRecordGetLength(_:)`](/documentation/dnssd/TXTRecordGetLength(_:))

Allows you to determine the length of the raw bytes within a TXTRecordRef.

[`TXTRecordRemoveValue(_:_:)`](/documentation/dnssd/TXTRecordRemoveValue(_:_:))

Removes a key from a TXTRecordRef.

[`TXTRecordSetValue(_:_:_:_:)`](/documentation/dnssd/TXTRecordSetValue(_:_:_:_:))

Adds a key (optionally with value) to a TXTRecordRef.

### Special Purpose Calls

[`DNSServiceCreateConnection(_:)`](/documentation/dnssd/DNSServiceCreateConnection(_:))

Creates a connection to the daemon, allowing efficient registration of multiple individual records., [`DNSServiceRegisterRecord(_:_:_:_:_:_:_:_:_:_:_:_:)`](/documentation/dnssd/DNSServiceRegisterRecord(_:_:_:_:_:_:_:_:_:_:_:_:))

Registers an individual resource record on a connected DNSServiceRef., [`DNSServiceReconfirmRecord(_:_:_:_:_:_:_:)`](/documentation/dnssd/DNSServiceReconfirmRecord(_:_:_:_:_:_:_:))

Instructs the daemon to verify the validity of a resource record that appears to be out of date (for example, because TCP connection to a service’s target failed). (most applications will not use these)

[`DNSServiceCreateConnection(_:)`](/documentation/dnssd/DNSServiceCreateConnection(_:))

Creates a connection to the daemon, allowing efficient registration of multiple individual records.

[`DNSServiceReconfirmRecord(_:_:_:_:_:_:_:)`](/documentation/dnssd/DNSServiceReconfirmRecord(_:_:_:_:_:_:_:))

Instructs the daemon to verify the validity of a resource record that appears to be out of date (for example, because TCP connection to a service’s target failed).

[`DNSServiceRegisterRecord(_:_:_:_:_:_:_:_:_:_:_:_:)`](/documentation/dnssd/DNSServiceRegisterRecord(_:_:_:_:_:_:_:_:_:_:_:_:))

Registers an individual resource record on a connected DNSServiceRef.

[`PeerConnectionRelease(_:_:_:_:)`](/documentation/dnssd/PeerConnectionRelease(_:_:_:_:))

Releases P2P connection resources associated with the service instance.

### Service Registration

[`DNSServiceAddRecord(_:_:_:_:_:_:_:)`](/documentation/dnssd/DNSServiceAddRecord(_:_:_:_:_:_:_:))

Adds a record to a registered service.

[`DNSServiceRegister(_:_:_:_:_:_:_:_:_:_:_:_:)`](/documentation/dnssd/DNSServiceRegister(_:_:_:_:_:_:_:_:_:_:_:_:))

Registers a service.

[`DNSServiceRemoveRecord(_:_:_:)`](/documentation/dnssd/DNSServiceRemoveRecord(_:_:_:))

Removes a record previously added to a service record set via [`DNSServiceAddRecord(_:_:_:_:_:_:_:)`](/documentation/dnssd/DNSServiceAddRecord(_:_:_:_:_:_:_:)), or deregister an record registered individually via [`DNSServiceRegisterRecord(_:_:_:_:_:_:_:_:_:_:_:_:)`](/documentation/dnssd/DNSServiceRegisterRecord(_:_:_:_:_:_:_:_:_:_:_:_:)).

[`DNSServiceUpdateRecord(_:_:_:_:_:_:)`](/documentation/dnssd/DNSServiceUpdateRecord(_:_:_:_:_:_:))

Updates a registered resource record.

### Service Discovery

[`DNSServiceBrowse(_:_:_:_:_:_:_:)`](/documentation/dnssd/DNSServiceBrowse(_:_:_:_:_:_:_:))

Browses for available services.

[`DNSServiceResolve(_:_:_:_:_:_:_:_:)`](/documentation/dnssd/DNSServiceResolve(_:_:_:_:_:_:_:_:))

### Querying Individual Specific Records

[`DNSServiceQueryRecord(_:_:_:_:_:_:_:_:)`](/documentation/dnssd/DNSServiceQueryRecord(_:_:_:_:_:_:_:_:))

Query for an arbitrary DNS record.

### NAT Port Mapping

[`DNSServiceNATPortMappingCreate(_:_:_:_:_:_:_:_:_:)`](/documentation/dnssd/DNSServiceNATPortMappingCreate(_:_:_:_:_:_:_:_:_:))

Requests a port mapping in the NAT gateway, which maps a port on the local machine to an external port on the NAT.

### General Utility Functions

[`DNSServiceConstructFullName(_:_:_:_:)`](/documentation/dnssd/DNSServiceConstructFullName(_:_:_:_:))

Concatenates a three-part domain name (as returned by the above callbacks) into a properly-escaped full domain name.

### Domain Enumeration

[`DNSServiceEnumerateDomains(_:_:_:_:_:)`](/documentation/dnssd/DNSServiceEnumerateDomains(_:_:_:_:_:))

Enumerates domains that are recommended for registration and browsing.

### Callbacks

See the Overview section above for header-level documentation.

[`DNSServiceCreateConnection(_:)`](/documentation/dnssd/DNSServiceCreateConnection(_:))

Creates a connection to the daemon, allowing efficient registration of multiple individual records., [`DNSServiceRegisterRecord(_:_:_:_:_:_:_:_:_:_:_:_:)`](/documentation/dnssd/DNSServiceRegisterRecord(_:_:_:_:_:_:_:_:_:_:_:_:))

Registers an individual resource record on a connected DNSServiceRef., [`DNSServiceReconfirmRecord(_:_:_:_:_:_:_:)`](/documentation/dnssd/DNSServiceReconfirmRecord(_:_:_:_:_:_:_:))

Instructs the daemon to verify the validity of a resource record that appears to be out of date (for example, because TCP connection to a service’s target failed). (most applications will not use these)

[`DNSServiceGetAddrInfoReply`](/documentation/dnssd/DNSServiceGetAddrInfoReply)

Callback for handling the results of a previous call to [`DNSServiceGetAddrInfo(_:_:_:_:_:_:_:)`](/documentation/dnssd/DNSServiceGetAddrInfo(_:_:_:_:_:_:_:)).

[`DNSServiceRegisterRecordReply`](/documentation/dnssd/DNSServiceRegisterRecordReply)

Callback for handling the results of a previous call to [`DNSServiceRegisterRecord(_:_:_:_:_:_:_:_:_:_:_:_:)`](/documentation/dnssd/DNSServiceRegisterRecord(_:_:_:_:_:_:_:_:_:_:_:_:)).

[`DNSServiceRegisterReply`](/documentation/dnssd/DNSServiceRegisterReply)

Handler for the results from a previous call to [`DNSServiceRegister(_:_:_:_:_:_:_:_:_:_:_:_:)`](/documentation/dnssd/DNSServiceRegister(_:_:_:_:_:_:_:_:_:_:_:_:)).

[`DNSServiceBrowseReply`](/documentation/dnssd/DNSServiceBrowseReply)

Callback for handling the results of previous calls to DNSServiceBrowse.

[`DNSServiceResolveReply`](/documentation/dnssd/DNSServiceResolveReply)

[`DNSServiceQueryRecordReply`](/documentation/dnssd/DNSServiceQueryRecordReply)

Callback for handling the results of a previous call to [`DNSServiceQueryRecord(_:_:_:_:_:_:_:_:)`](/documentation/dnssd/DNSServiceQueryRecord(_:_:_:_:_:_:_:_:)).

[`DNSServiceNATPortMappingReply`](/documentation/dnssd/DNSServiceNATPortMappingReply)

Callback for handling the reply from a previous call to [`DNSServiceNATPortMappingReply`](/documentation/dnssd/DNSServiceNATPortMappingReply).

[`DNSServiceDomainEnumReply`](/documentation/dnssd/DNSServiceDomainEnumReply)

Callback for handling the results of a previous call to [`DNSServiceEnumerateDomains(_:_:_:_:_:)`](/documentation/dnssd/DNSServiceEnumerateDomains(_:_:_:_:_:)).

### Data Types

See the Overview section above for header-level documentation.

[`DNSServiceErrorType`](/documentation/dnssd/DNSServiceErrorType)

[`DNSServiceFlags`](/documentation/dnssd/DNSServiceFlags)

[`DNSServiceProtocol`](/documentation/dnssd/DNSServiceProtocol)

[`TXTRecordRef`](/documentation/dnssd/TXTRecordRef)

Opaque internal data type that represents a DNS-SD TXT record.

### Constants

See the Overview section above for header-level documentation.

[Constants for specifying an interface index](/documentation/dnssd/constants-for-specifying-an-interface-index)

[Miscellaneous Defines](/documentation/dnssd/miscellaneous-defines)



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)