summaryrefslogtreecommitdiff
path: root/tools/testbtmm.c
blob: bd6379f84aadf2d53564f690cbe7790de53885f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
 * Simple test program that lists the Back to My Mac domains on a Mac.
 *
 * Compile with:
 *
 *   clang -o testbtmm -g testbtmm.c -framework SystemConfiguration -framework CoreFoundation
 */

#include <stdio.h>
#include <CoreFoundation/CoreFoundation.h>
#include <SystemConfiguration/SystemConfiguration.h>


/*
 * 'dnssdAddAlias()' - Add a DNS-SD alias name.
 */

static void
show_domain(const void *key,		/* I - Key */
	    const void *value,		/* I - Value (domain) */
	    void       *context)	/* I - Unused */
{
  char	valueStr[1024];			/* Domain string */


  (void)key;
  (void)context;

  if (CFGetTypeID((CFStringRef)value) == CFStringGetTypeID() &&
      CFStringGetCString((CFStringRef)value, valueStr, sizeof(valueStr),
                         kCFStringEncodingUTF8))
    printf("Back to My Mac domain: \"%s\"\n", valueStr);
  else
    puts("Bad Back to My Mac domain in dynamic store.");
}


int
main(void)
{
  SCDynamicStoreRef sc;			/* Context for dynamic store */
  CFDictionaryRef btmm;			/* Back-to-My-Mac domains */


  sc = SCDynamicStoreCreate(kCFAllocatorDefault, CFSTR("cups"), NULL, NULL);

  if (!sc)
  {
    puts("Unable to open dynamic store.");
    exit(1);
  }

  btmm = SCDynamicStoreCopyValue(sc, CFSTR("Setup:/Network/BackToMyMac"));
  if (btmm && CFGetTypeID(btmm) == CFDictionaryGetTypeID())
  {
    printf("%d Back to My Mac domains.\n", (int)CFDictionaryGetCount(btmm));
    CFDictionaryApplyFunction(btmm, show_domain, NULL);
  }
  else if (btmm)
    puts("Bad Back to My Mac data in dynamic store.");
  else
    puts("No Back to My Mac domains.");

  return (1);
}