Blurrr Network Service Discovery  1.0.0
Typedefs | Enumerations | Functions
BlurrrNetworkServiceDiscovery.h File Reference
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>

Go to the source code of this file.

Typedefs

typedef struct BNSD_Registration BNSD_Registration
 
typedef struct BNSD_Discovery BNSD_Discovery
 
typedef struct BNSD_Resolve BNSD_Resolve
 
typedef void(* BNSD_RegisterCallback) (struct BNSD_Registration *zeroconf_registration, const char *service_name, const char *service_type, const char *domain, int32_t blurrr_error_code, uint32_t flags, void *user_data)
 Callback for BNSD_RegisterService. More...
 
typedef void(* BNSD_DiscoveryCallback) (struct BNSD_Discovery *zeroconf_discovery, const char *service_name, const char *service_type, const char *domain, bool is_added, int32_t blurrr_error_code, uint32_t flags, int32_t interface_index, void *user_data)
 Callback for BNSD_StartDiscovery. More...
 
typedef void(* BNSD_ResolveCallback) (struct BNSD_Resolve *zeroconf_resolve, const char *service_name, const char *service_type, const char *domain, const char *full_name, const char *host_target, uint16_t port, const char *txt_record, uint16_t txt_record_length, int32_t blurrr_error_code, uint32_t flags, int32_t interface_index, void *user_data)
 Callback for BNSD_StartResolve. More...
 

Enumerations

enum  {
  BNSD_ERR_OK = 0,
  BNSD_ERR_RESOLVE_TIMEOUT = 1,
  BNSD_ERR_FAILURE = -1,
  BNSD_ERR_BAD_STATE = -2,
  BNSD_ERR_INVALID_HOST_NAME = -3,
  BNSD_ERR_INVALID_DOMAIN_NAME = -4,
  BNSD_ERR_NO_NETWORK = -5,
  BNSD_ERR_INVALID_TTL = -6,
  BNSD_ERR_IS_PATTERN = -7,
  BNSD_ERR_COLLISION = -8,
  BNSD_ERR_INVALID_RECORD = -9,
  BNSD_ERR_INVALID_SERVICE_NAME = -10,
  BNSD_ERR_INVALID_SERVICE_TYPE = -11,
  BNSD_ERR_INVALID_PORT = -12,
  BNSD_ERR_INVALID_KEY = -13,
  BNSD_ERR_INVALID_ADDRESS = -14,
  BNSD_ERR_TIMEOUT = -15,
  BNSD_ERR_TOO_MANY_CLIENTS = -16,
  BNSD_ERR_TOO_MANY_OBJECTS = -17,
  BNSD_ERR_TOO_MANY_ENTRIES = -18,
  BNSD_ERR_OS = -19,
  BNSD_ERR_ACCESS_DENIED = -20,
  BNSD_ERR_INVALID_OPERATION = -21,
  BNSD_ERR_DBUS_ERROR = -22,
  BNSD_ERR_DISCONNECTED = -23,
  BNSD_ERR_NO_MEMORY = -24,
  BNSD_ERR_INVALID_OBJECT = -25,
  BNSD_ERR_NO_DAEMON = -26,
  BNSD_ERR_INVALID_INTERFACE = -27,
  BNSD_ERR_INVALID_PROTOCOL = -28,
  BNSD_ERR_INVALID_FLAGS = -29,
  BNSD_ERR_NOT_FOUND = -30,
  BNSD_ERR_INVALID_CONFIG = -31,
  BNSD_ERR_VERSION_MISMATCH = -32,
  BNSD_ERR_INVALID_SERVICE_SUBTYPE = -33,
  BNSD_ERR_INVALID_PACKET = -34,
  BNSD_ERR_INVALID_DNS_ERROR = -35,
  BNSD_ERR_DNS_FORMERR = -36,
  BNSD_ERR_DNS_SERVFAIL = -37,
  BNSD_ERR_DNS_NXDOMAIN = -38,
  BNSD_ERR_DNS_NOTIMP = -39,
  BNSD_ERR_DNS_REFUSED = -40,
  BNSD_ERR_DNS_YXDOMAIN = -41,
  BNSD_ERR_DNS_YXRRSET = -42,
  BNSD_ERR_DNS_NXRRSET = -43,
  BNSD_ERR_DNS_NOTAUTH = -44,
  BNSD_ERR_DNS_NOTZONE = -45,
  BNSD_ERR_INVALID_RDATA = -46,
  BNSD_ERR_INVALID_DNS_CLASS = -47,
  BNSD_ERR_INVALID_DNS_TYPE = -48,
  BNSD_ERR_NOT_SUPPORTED = -49,
  BNSD_ERR_NOT_PERMITTED = -50,
  BNSD_ERR_INVALID_ARGUMENT = -51,
  BNSD_ERR_IS_EMPTY = -52,
  BNSD_ERR_NO_CHANGE = -53,
  BNSD_ERR_INVALID_NAME = -54,
  BNSD_ERR_NOT_INITIALIZED = -55,
  BNSD_ERR_ALREADY_EXISTS = -56,
  BNSD_ERR_FIREWALL = -57,
  BNSD_ERR_NATTRAVERSAL = -58,
  BNSD_ERR_DOUBLENAT = -59,
  BNSD_ERR_BAD_TIME = -60,
  BNSD_ERR_INVALID_PARAMETERS = -61,
  BNSD_ERR_MAX = -62
}
 Error code constants. More...
 
enum  { BNSD_FLAGSCB_MORECOMING = 0x1 }
 Flag mask values for callbacks. More...
 
enum  { BNSD_FLAGS_INCLUDE_BLUETOOTH = 0x1 }
 Flag mask values for setup. More...
 

Functions

bool BNSD_IsSupported (void)
 A quick test to see if the current system supports Zeroconf. More...
 
bool BNSD_Init (void *platform_init_object)
 Initializes the library. More...
 
void BNSD_Quit (void)
 Uninitializes the library. More...
 
const char * BNSD_GetBackendDescription (void)
 Returns a string with the name of the backend in use. More...
 
char * BNSD_CreateDeviceNameString (void)
 Returns a string with something that can be used as your computer name. More...
 
void BNSD_FreeString (char *str)
 Frees the string created by BNSD_CreateDeviceNameString. More...
 
size_t BNSD_GetDeviceNameString (char *string_array, size_t array_length)
 Returns a string with something that can be used as your computer name. More...
 
struct BNSD_RegistrationBNSD_RegisterService (const char *service_name, const char *service_type, const char *domain, const char *host_name, uint16_t port, uint32_t flags, const char *txt_record, uint16_t txt_record_length, BNSD_RegisterCallback callback_function, void *user_data)
 Starts advertising a new service. More...
 
void BNSD_UnregisterService (struct BNSD_Registration *registration_service)
 Stops advertising an existing service and frees the resources. More...
 
struct BNSD_DiscoveryBNSD_StartDiscovery (const char *service_type, const char *domain, uint32_t flags, BNSD_DiscoveryCallback callback_function, void *user_data)
 Starts discovering all services that are currently advertised matching your critera. More...
 
void BNSD_StopDiscovery (struct BNSD_Discovery *discovery_service)
 Stops discovering services for the specific instance. More...
 
struct BNSD_ResolveBNSD_StartResolve (const char *service_name, const char *service_type, const char *domain, uint32_t flags, uint32_t time_out, BNSD_ResolveCallback callback_function, void *user_data)
 Starts resolving the service you request. More...
 
void BNSD_StopResolve (struct BNSD_Resolve *resolve_service)
 Stops resolving services for the specific instance. More...
 

Typedef Documentation

◆ BNSD_Registration

◆ BNSD_Discovery

◆ BNSD_Resolve

typedef struct BNSD_Resolve BNSD_Resolve

◆ BNSD_RegisterCallback

typedef void(* BNSD_RegisterCallback) (struct BNSD_Registration *zeroconf_registration, const char *service_name, const char *service_type, const char *domain, int32_t blurrr_error_code, uint32_t flags, void *user_data)

Callback for BNSD_RegisterService.

Callback for BNSD_RegisterService. This shows you the final values for the service you registered if successfully registered, or an error code if something failed.

Parameters
zeroconf_registrationThe pointer to the BNSD_Registration you got from BNSD_RegisterService.
service_nameThe service name (e.g. "My Service") for the service you registered. Note: This name may be different than the name you requested with BNSD_RegisterService if it is determined that the name you requested is already in use.
service_typeThe service type (e.g. "_daap._tcp.").
domainThe domain (e.g. "local.").
blurrr_error_code0 (BNSD_ERR_OK) if there was no error, otherwise one of the BNSD_ERR_* values. Note: If there was an error, some of the other parameters passed back by this function may be NULL.
flagsReserved for future use (i.e. You can ignore this value): An integer bitmask to denote certain properties. BNSD_FLAGSCB_* will contain the different mask values.
user_dataThe user_data pointer you passed to BNSD_RegisterService.
Note
You are expected to make your own copy of all string data if you need it beyond the life of the callback.
String parameters are NONNULL for convenience. So if a parameter is missing a value, an empty string "" will be used.
See also
BNSD_RegisterService.
void MyRegisterCallback(struct BNSD_Registration* zeroconf_registration, const char* service_name, const char* service_type, const char* domain, int32_t blurrr_error_code, uint32_t flags, void* user_data)
{
if(BNSD_ERR_OK != blurrr_error_code)
{
printf("Failed to register service\n");
return;
}
printf("Register service succeeded\n");
printf(
"service_name: %s\n"
"service_type: %s\n"
"domain: %s\n",
service_name,
service_type,
domain
);
}

◆ BNSD_DiscoveryCallback

typedef void(* BNSD_DiscoveryCallback) (struct BNSD_Discovery *zeroconf_discovery, const char *service_name, const char *service_type, const char *domain, bool is_added, int32_t blurrr_error_code, uint32_t flags, int32_t interface_index, void *user_data)

Callback for BNSD_StartDiscovery.

This will callback for every service discovered that meets your criteria when you called BNSD_StartDiscovery. Callbacks will continue to happen as services come and go until you call BNSD_StopDiscovery.

Parameters
zeroconf_discoveryThe pointer to the BNSD_Discovery you got from BNSD_StartDiscovery.
service_nameThe service name (e.g. "My Service").
service_typeThe service type (e.g. "_daap._tcp.").
domainThe domain (e.g. "local.").
is_addedIf true, it means the service is currently advertised. If false, it means the service has gone away.
blurrr_error_code0 (BNSD_ERR_OK) if there was no error, otherwise one of the BNSD_ERR_* values. Note: If there was an error, some of the other parameters passed back by this function may be NULL.
flagsReserved for future use (i.e. You can ignore this value): An integer bitmask to denote certain properties. BNSD_FLAGSCB_* will contain the different mask values.
interface_indexFor Apple Bonjour and Avahi, this will give you the interface index this callback is associated with. On other platforms, this value will always be 0. This value is provided for informational purposes to help bookkeeping (see note about multiple callbacks). Otherwise, you can generally ignore this value.
user_dataThe user_data pointer you passed to BNSD_StartDiscovery.
Note
You are expected to make your own copy of all string data if you need it beyond the life of the callback.
You may get multiple callbacks for the same service. This can be due to things like the service being on multiple interface_index. If you are keeping your own list of active services, you should take into consideration that you may get multiple callbacks.
String parameters are NONNULL for convenience. So if a parameter is missing a value, an empty string "" will be used.
See also
BNSD_StartDiscovery.
void MyDiscoveryCallback(struct BNSD_Discovery* zeroconf_discovery, const char* service_name, const char* service_type, const char* domain, bool is_added, int32_t blurrr_error_code, uint32_t flags, int32_t interface_index, void* user_data)
{
if(BNSD_ERR_OK != blurrr_error_code)
{
printf("Discovery had an error\n");
return;
}
printf(
"service_name: %s\n"
"service_type: %s\n"
"domain: %s\n"
"is_added: %d\n",
service_name,
service_type,
domain,
is_added
);
}

◆ BNSD_ResolveCallback

typedef void(* BNSD_ResolveCallback) (struct BNSD_Resolve *zeroconf_resolve, const char *service_name, const char *service_type, const char *domain, const char *full_name, const char *host_target, uint16_t port, const char *txt_record, uint16_t txt_record_length, int32_t blurrr_error_code, uint32_t flags, int32_t interface_index, void *user_data)

Callback for BNSD_StartResolve.

This will callback for every service discovered that meets your criteria when you called BNSD_StartResolve. Callbacks will continue to happen as the service updates until you call BNSD_StopResolve or your requested time_out occurs. When a time_out callback occurs, many of the other fields will be NULL. After the time_out callback, future callbacks will be suppressed for convenience, but network resources are still alive and network traffic will continue, thus you should call BNSD_StopResolve(). Additionally, if you get back all the information you want before your time_out callback, consider calling BNSD_StopResolve immediately to free resources.

Parameters
zeroconf_resolveThe pointer to the BNSD_Resolve you got from BNSD_StartResolve.
service_nameThe service name (e.g. "My Service").
service_typeThe service type (e.g. "_daap._tcp.").
domainThe domain (e.g. "local.").
full_nameThis is the full name of the service, including escaping needed for DNS names (e.g. Not\032a\032real\032page._http_.tcp.local.)
host_targetThe reachable host name of the machine the service resides on, (e.g. MacBook.local.). Names are preferred because they can stand in front of both IPv4 and IPv6 addresses, but if a name cannot be found, this could also be an IP address (e.g. 192.168.0.42 or an IPv6 address). (Android seems to have a bug where the IPv4 address is given even if there is an actual name (or IPv6 address also available) https://issuetracker.google.com/issues/80368263).
portThe port number in host byte order that the service is running on (e.g. MySsh._ssh._tcp.local. is running on port 22).
blurrr_error_code0 (BNSD_ERR_OK) if there was no error, BNSD_ERR_RESOLVE_TIMEOUT (1) if the time out BNSD_E otherwise one of the BNSD_ERR_* values. Note: If there was an error, some of the other parameters passed back by this function may be NULL. Tip: Notice that BNSD_ERR_OK and BNSD_ERR_RESOLVE_TIMEOUT are not-negative and real errors are negative.
txt_recordIf the service has a TXT Record, this is the pointer to the array of bytes. Otherwise, this is NULL. Note: This is not a proper C string. It is not NULL terminated. This is in DNS TXT Record format, where each field entry starts with the number of bytes (an actual number, not a string) followed by that number characters, then repeat. (e.g. char txt_record[] = "\xfMyKey1=MyValue1\xfMyKey2=MyValue2"; where "\xf" is hex for 15).
txt_record_lengthThe length in bytes of the txt_record. Make sure to use this and don't use strlen() because the txt_record is not a proper C string.
flagsReserved for future use: An integer bitmask to denote certain properties. BNSD_FLAGSCB_* will contain the different mask values.
interface_indexFor Apple Bonjour and Avahi, this will give you the interface index this callback is associated with. On other platforms, this value will always be 0. This value is provided for informational purposes to help bookkeeping (see note about multiple callbacks). Otherwise, you can generally ignore this value.
user_dataThe user_data pointer you passed to BNSD_Resolve.
Note
You are expected to make your own copy of all string data if you need it beyond the life of the callback.
You may get multiple callbacks for the same service. This can be due to things like the service being on multiple interface_index or possibly because of seperate calls for IPv4 and IPv6 host_targets. If you are keeping your own list of active services, you should take into consideration that you may get multiple callbacks.
See also
BNSD_StartResolve, BNSD_StopResolve.
Note
String parameters are NONNULL for convenience. So if a parameter is missing a value, an empty string "" will be used. txt_record is not considered a string parameter and thus may be NULL.
void MyResolveCallback(struct BNSD_Resolve* zeroconf_resolve, const char* service_name, const char* service_type, const char* domain, const char* full_name, const char* host_target, uint16_t port, const char* txt_record, uint16_t txt_record_length, int32_t blurrr_error_code, uint32_t flags, int32_t interface_index, void* user_data)
{
if(BNSD_ERR_RESOLVE_TIMEOUT == blurrr_error_code)
{
// If you have any other pointers to the zeroconf_resolve outside this function,
// they are now dangling pointers.
BNSD_StopResolve(zeroconf_resolve);
return;
}
printf("BlurrrLog_SysLog In MyResolveCallback:\n"
"service_name:%s\n"
"service_type:%s\n"
"domain:%s\n"
"full_name:%s\n"
"host_target:%s\n"
"port:%d\n"
"blurrr_error_code:%d\n"
"interface_index:%d\n",
service_name,
service_type,
domain,
full_name,
host_target,
port,
blurrr_error_code,
interface_index
);

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Error code constants.

Enumerator
BNSD_ERR_OK 

OK.

BNSD_ERR_RESOLVE_TIMEOUT 

If a time out was specified calling StartResolve, this is the value returned when the time out happens.

BNSD_ERR_FAILURE 

Generic error code.

BNSD_ERR_BAD_STATE 

Object was in a bad state.

BNSD_ERR_INVALID_HOST_NAME 

Invalid host name.

BNSD_ERR_INVALID_DOMAIN_NAME 

Invalid domain name.

BNSD_ERR_NO_NETWORK 

No suitable network protocol available.

BNSD_ERR_INVALID_TTL 

Invalid DNS TTL.

BNSD_ERR_IS_PATTERN 

RR key is pattern.

BNSD_ERR_COLLISION 

Name collision.

BNSD_ERR_INVALID_RECORD 

Invalid RR.

BNSD_ERR_INVALID_SERVICE_NAME 

Invalid service name.

BNSD_ERR_INVALID_SERVICE_TYPE 

Invalid service type.

BNSD_ERR_INVALID_PORT 

Invalid port number.

BNSD_ERR_INVALID_KEY 

Invalid key.

BNSD_ERR_INVALID_ADDRESS 

Invalid address.

BNSD_ERR_TIMEOUT 
BNSD_ERR_TOO_MANY_CLIENTS 

Too many clients.

BNSD_ERR_TOO_MANY_OBJECTS 

Too many objects.

BNSD_ERR_TOO_MANY_ENTRIES 

Too many entries.

BNSD_ERR_OS 

OS error.

BNSD_ERR_ACCESS_DENIED 

Access denied.

BNSD_ERR_INVALID_OPERATION 

Invalid operation.

BNSD_ERR_DBUS_ERROR 

An unexpected D-Bus error occurred.

BNSD_ERR_DISCONNECTED 

Daemon connection failed.

BNSD_ERR_NO_MEMORY 

Memory exhausted.

BNSD_ERR_INVALID_OBJECT 

The object passed to this function was invalid.

BNSD_ERR_NO_DAEMON 

Daemon not running.

BNSD_ERR_INVALID_INTERFACE 

Invalid interface.

BNSD_ERR_INVALID_PROTOCOL 

Invalid protocol.

BNSD_ERR_INVALID_FLAGS 

Invalid flags.

BNSD_ERR_NOT_FOUND 

Not found.

BNSD_ERR_INVALID_CONFIG 

Configuration error.

BNSD_ERR_VERSION_MISMATCH 

Verson mismatch.

BNSD_ERR_INVALID_SERVICE_SUBTYPE 

Invalid service subtype.

BNSD_ERR_INVALID_PACKET 

Invalid packet.

BNSD_ERR_INVALID_DNS_ERROR 

Invlaid DNS return code.

BNSD_ERR_DNS_FORMERR 

DNS Error: Form error.

BNSD_ERR_DNS_SERVFAIL 

DNS Error: Server Failure.

BNSD_ERR_DNS_NXDOMAIN 

DNS Error: No such domain.

BNSD_ERR_DNS_NOTIMP 

DNS Error: Not implemented.

BNSD_ERR_DNS_REFUSED 

DNS Error: Operation refused.

BNSD_ERR_DNS_YXDOMAIN 
BNSD_ERR_DNS_YXRRSET 
BNSD_ERR_DNS_NXRRSET 
BNSD_ERR_DNS_NOTAUTH 

DNS Error: Not authorized.

BNSD_ERR_DNS_NOTZONE 
BNSD_ERR_INVALID_RDATA 

Invalid RDATA.

BNSD_ERR_INVALID_DNS_CLASS 

Invalid DNS class.

BNSD_ERR_INVALID_DNS_TYPE 

Invalid DNS type.

BNSD_ERR_NOT_SUPPORTED 

Not supported.

BNSD_ERR_NOT_PERMITTED 

Operation not permitted.

BNSD_ERR_INVALID_ARGUMENT 

Invalid argument.

BNSD_ERR_IS_EMPTY 

Is empty.

BNSD_ERR_NO_CHANGE 

The requested operation is invalid because it is redundant.

BNSD_ERR_INVALID_NAME 
BNSD_ERR_NOT_INITIALIZED 
BNSD_ERR_ALREADY_EXISTS 
BNSD_ERR_FIREWALL 
BNSD_ERR_NATTRAVERSAL 
BNSD_ERR_DOUBLENAT 
BNSD_ERR_BAD_TIME 
BNSD_ERR_INVALID_PARAMETERS 

invalid paramters were passed (Windows DNSSD)

BNSD_ERR_MAX 

◆ anonymous enum

anonymous enum

Flag mask values for callbacks.

Enumerator
BNSD_FLAGSCB_MORECOMING 

EXPERIMENTAL: A hint that another callback is pending so you might defer updating UI.

Currently Apple Bonjour only.

◆ anonymous enum

anonymous enum

Flag mask values for setup.

Enumerator
BNSD_FLAGS_INCLUDE_BLUETOOTH 

EXPERIMENTAL: Include Bluetooth.

Only Apple.

Function Documentation

◆ BNSD_IsSupported()

bool BNSD_IsSupported ( void  )

A quick test to see if the current system supports Zeroconf.

On Android, it will check OS version for 4.1+. On Apple platforms, this will always return true. On Linux platforms, this will return true. (Currently expected to link to avahi, so launch time will fail without it.) On Windows, this first checks if Apple Bonjour for Windows is installed (looks for system-wide dnssd.dll), then if not found, checks for the Windows 10+ built in DNSSD UWP. This does not check for availability, i.e. the user has stopped the service. Specific allback results are needed to handle those failure cases.

Returns
Returns 1 if supported, 0 if not.

◆ BNSD_Init()

bool BNSD_Init ( void *  platform_init_object)

Initializes the library.

On Apple, Linux, & Android, this is expected to return true. On Windows, this first tries to load Apple Bonjour for Windows if it is installed (looks for system-wide dnssd.dll), then if not found, tries to load the Windows 10+ built in DNSSD UWP.

Parameters
platform_init_objectOn Android, you must pass a JNI jobject that is a Context. Use BlurrrPlatformAndroid_GetApplicationContext() or SDL_AndroidGetActivity() to get this object. For other platforms, pass NULL.
Returns
true if succeeded, false otherwise.

◆ BNSD_Quit()

void BNSD_Quit ( void  )

Uninitializes the library.

◆ BNSD_GetBackendDescription()

const char* BNSD_GetBackendDescription ( void  )

Returns a string with the name of the backend in use.

This is mostly used for diagnostic purposes, particularly for Windows where different backends could be running on diffent systems. Valid strings are: "Apple Bonjour" "Avahi" "Android Network Service Discovery" "Microsoft Windows DNS-SD UWP" "uninitialized"

Returns
Returns the string. Do not call free on this string. This will return "uninitialized" if not initialized and backend cannot be determined until initialized. This will not return NULL.
See also
BNSD_Init

◆ BNSD_CreateDeviceNameString()

char* BNSD_CreateDeviceNameString ( void  )

Returns a string with something that can be used as your computer name.

Returns
Returns the string. You must free this with BNSD_FreeString when you are done. Will not return NULL.

◆ BNSD_FreeString()

void BNSD_FreeString ( char *  str)

Frees the string created by BNSD_CreateDeviceNameString.

See also
BNSD_CreateDeviceNameString.

◆ BNSD_GetDeviceNameString()

size_t BNSD_GetDeviceNameString ( char *  string_array,
size_t  array_length 
)

Returns a string with something that can be used as your computer name.

Parameters
string_arrayThe buffer the result will be written into. Maybe NULL if you just want the return length.
array_lengthThe length of the string_array buffer.
Returns
Returns the length needed for the resulting string, including the +1 for the \0 terminator. This value will return 0 if the resulting string is/would-be NULL. The passed in string will be null terminated if the value would be NULL.

◆ BNSD_RegisterService()

struct BNSD_Registration* BNSD_RegisterService ( const char *  service_name,
const char *  service_type,
const char *  domain,
const char *  host_name,
uint16_t  port,
uint32_t  flags,
const char *  txt_record,
uint16_t  txt_record_length,
BNSD_RegisterCallback  callback_function,
void *  user_data 
)

Starts advertising a new service.

This will register a new service and advertising it over the network.

Parameters
service_nameThe name for the new service. Must be a string shorter than 63 characters and valid UTF-8. Example: "My Game Service on Mario's iPad". Passing NULL will cause a name to be generated for you.
service_typeThe service type followed by the protocol, separated by a dot (e.g. "_ftp._tcp"). The service type must be an underscore, followed by 1-15 characters, which may be letters, digits, or hyphens. The transport protocol must be "_tcp" or "_udp". New service types should be registered at http://www.dns-sd.org/ServiceTypes.html. Trailing dots are allowed (e.g. "_ftp._tcp.") This does not support subtypes. May not be NULL.
domainYou should pass NULL which will utilize defaults. Advanced use cases of specifying a domain other than "local" may not be cross-platform. Trailing dots are allowed.
host_nameThe host this service is residing on. It is recommended you pass NULL here, which defaults to your current device. Advanced use cases of this parameter are for proxying services (i.e. advertising a service on behalf of another device, e.g. advertise the service is coming from another machine, "macbook.local", instead of my current device.). Not all implementations are guaranteed to support this advanced use case.
portThe port, in host byte order, on which the service accepts connections.
flagsReserved for future use. Pass 0 for now.
txt_recordUse this to provide a DNS TXT Record with your service. This may be NULL if you don't want one. This is in DNS TXT Record format, where each field entry starts with the number of bytes (an actual number, not a string) followed by that number characters, then repeat. (e.g. char txt_record[] = "\xfMyKey1=MyValue1\xfMyKey2=MyValue2"; where "\xf" is hex for 15).
txt_record_lengthThe length in bytes of the entire txt_record you supplied. Use 0 if you passed NULL.
callback_functionThe callback function that will be invoked when your service is successfully created (or failed). Be aware that if you pick a service name that is already in use, a new unique name will be created to avoid the conflict. The callback is your opportunity to see what name was actually chosen.
user_dataThis pointer will be passed back to you in the callback_function. This may be NULL.
Returns
A new instance of a BNSD_Registration opaque data, or NULL on an immediately detectable error. Additional registration errors and successes will be reported through the callback.
Note
Remember on platforms with suspend/resume states, such as iOS, network sockets must be closed and recreated. So you will likely want to unregister your service on suspend and re-register on resume.
See also
BNSD_RegisterCallback, BNSD_UnregisterService

◆ BNSD_UnregisterService()

void BNSD_UnregisterService ( struct BNSD_Registration registration_service)

Stops advertising an existing service and frees the resources.

This will unregister a service you created with BNSD_RegisterService and free the resource.

Parameters
registration_serviceThe service you want to stop advertising.
See also
BNSD_RegisterService

◆ BNSD_StartDiscovery()

struct BNSD_Discovery* BNSD_StartDiscovery ( const char *  service_type,
const char *  domain,
uint32_t  flags,
BNSD_DiscoveryCallback  callback_function,
void *  user_data 
)

Starts discovering all services that are currently advertised matching your critera.

Starts discovering all services that are currently advertised matching your critera. You will get a callback for each service that is advertised, and a callback for each services that was available but just stopped advertising.

Parameters
service_typeThe service type followed by the protocol, separated by a dot (e.g. "_ftp._tcp"). The service type must be an underscore, followed by 1-15 characters, which may be letters, digits, or hyphens. The transport protocol must be "_tcp" or "_udp". New service types should be registered at http://www.dns-sd.org/ServiceTypes.html. Trailing dots are allowed (e.g. "_ftp._tcp.") This does not support subtypes. May not be NULL.
domainYou should pass NULL which will utilize defaults. Advanced use cases of specifying a domain other than "local" may not be cross-platform. Trailing dots are allowed.
flagsReserved for future use. Pass 0 for now.
callback_functionThe callback function that will be invoked for each service found.
user_dataThis pointer will be passed back to you in the callback_function. This may be NULL.
Returns
A new instance of a BNSD_Discovery opaque data, or NULL on an immediately detectable error. Additional errors and successes will be reported through the callback.
Note
Remember on platforms with suspend/resume states, such as iOS, network sockets must be closed and recreated. So you will likely want to unregister your service on suspend and re-register on resume.
See also
BNSD_DiscoveryCallback, BNSD_StopDiscovery

◆ BNSD_StopDiscovery()

void BNSD_StopDiscovery ( struct BNSD_Discovery discovery_service)

Stops discovering services for the specific instance.

This stops discovering services created with BNSD_StartDiscovery and free the resource.

Parameters
discovery_serviceThe service you want to stop discovering.
See also
BNSD_StartDiscovery

◆ BNSD_StartResolve()

struct BNSD_Resolve* BNSD_StartResolve ( const char *  service_name,
const char *  service_type,
const char *  domain,
uint32_t  flags,
uint32_t  time_out,
BNSD_ResolveCallback  callback_function,
void *  user_data 
)

Starts resolving the service you request.

Starts resolving the service you request. A callback will give you information about your service. As long as the resolve is running, you may receive additional callbacks when information changes. To cut down on unnecessary network traffic, you should call BNSD_StopResolve once you have all the information you need. However, if you are doing advanced things to use DNS TXT Records to broadcast changes, keeping the resolve going is the appropriate thing to do. Optionally, you may specify a time_out value which will give you a callback at that time. After the time_out, additional callbacks will be suppressed for convenience. However, network resources may still be active. So you are still responsible for calling BNSD_StopResolve after the time out.

Parameters
service_nameThe name of the service to resolve. This is typically a service_name you got from a BNSD_DiscoveryCallback.
service_typeThe service type followed by the protocol, separated by a dot (e.g. "_ftp._tcp"). The service type must be an underscore, followed by 1-15 characters, which may be letters, digits, or hyphens. The transport protocol must be "_tcp" or "_udp". New service types should be registered at http://www.dns-sd.org/ServiceTypes.html. Trailing dots are allowed (e.g. "_ftp._tcp.") This does not support subtypes. May not be NULL. This is typically a service_name you got from a BNSD_DiscoveryCallback.
domainYou should provide the value you got from BNSD_DiscoveryCallback or pass NULL.
flagsReserved for future use. Pass 0 for now.
time_outPassing a non-zero value will set up a callback in the specified number of seconds, that you want a callback to happen with the blurrr_error_code==BNSD_ERR_RESOLVE_TIMEOUT. This is provided as a convenince in case your requested service doesn't resolve (maybe the service died without alerting the network). Using a timeout is a convenient way to help you from keeping your app waiting forever for a resolve. When your callback happens, remember that you are still required to call BNSD_StopResolve to fully stop and clean up the resources. Pass 0 if you do not want a timeout.
callback_functionThe callback function that will be invoked for the resolve.
user_dataThis pointer will be passed back to you in the callback_function. This may be NULL.
Returns
A new instance of a BNSD_Resolve opaque data, or NULL on an immediately detectable error. Additional errors and successes will be reported through the callback.
Note
Remember on platforms with suspend/resume states, such as iOS, network sockets must be closed and recreated. So you will likely want to unregister your service on suspend and re-register on resume.
See also
BNSD_ResolveCallback, BNSD_StopResolve

◆ BNSD_StopResolve()

void BNSD_StopResolve ( struct BNSD_Resolve resolve_service)

Stops resolving services for the specific instance.

This stops resolving services created with BNSD_StartResolve and free the resource.

Parameters
resolve_serviceThe service you want to stop resolving.
See also
BNSD_StartResolve