8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / idmap / test-getdc / getdc_main.c
bloba0465bcc07652f073685b4b4bc0b0cfc47aaf478
1 /*
2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
5 * 1.0 of the CDDL.
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
13 * Copyright 2014 Nexenta Systems, Inc. All rights reserved.
17 #include <sys/note.h>
18 #include <stdarg.h>
19 #include <stdio.h>
20 #include <addisc.h>
21 #include <netinet/in.h>
22 #include <arpa/inet.h>
24 int debug;
25 char *domainname = NULL;
27 void print_ds(ad_disc_ds_t *);
28 void mylogger(int pri, const char *format, ...);
30 int
31 main(int argc, char *argv[])
33 ad_disc_t ad_ctx = NULL;
34 boolean_t autodisc;
35 ad_disc_ds_t *dc, *gc;
36 char *s;
37 int c;
39 while ((c = getopt(argc, argv, "d")) != -1) {
40 switch (c) {
41 case '?':
42 (void) fprintf(stderr, "bad option: -%c\n", optopt);
43 return (1);
44 case 'd':
45 debug++;
46 break;
50 if (optind < argc)
51 domainname = argv[optind];
53 adutils_set_logger(mylogger);
54 adutils_set_debug(AD_DEBUG_ALL, debug);
56 ad_ctx = ad_disc_init();
57 ad_disc_set_StatusFP(ad_ctx, stdout);
59 if (domainname)
60 (void) ad_disc_set_DomainName(ad_ctx, domainname);
62 ad_disc_refresh(ad_ctx);
64 dc = ad_disc_get_DomainController(ad_ctx,
65 AD_DISC_PREFER_SITE, &autodisc);
66 if (dc == NULL) {
67 (void) printf("getdc failed\n");
68 return (1);
70 (void) printf("Found a DC:\n");
71 print_ds(dc);
72 free(dc);
74 s = ad_disc_get_ForestName(ad_ctx, NULL);
75 (void) printf("Forest: %s\n", s);
76 free(s);
78 s = ad_disc_get_SiteName(ad_ctx, NULL);
79 (void) printf("Site: %s\n", s);
80 free(s);
82 gc = ad_disc_get_GlobalCatalog(ad_ctx,
83 AD_DISC_PREFER_SITE, &autodisc);
84 if (gc != NULL) {
85 (void) printf("Found a GC:\n");
86 print_ds(gc);
87 free(gc);
90 ad_disc_done(ad_ctx);
91 ad_disc_fini(ad_ctx);
92 ad_ctx = NULL;
94 return (0);
97 void
98 print_ds(ad_disc_ds_t *ds)
100 char buf[64];
102 for (; ds->host[0] != '\0'; ds++) {
103 const char *p;
105 (void) printf("Name: %s\n", ds->host);
106 (void) printf(" flags: 0x%X\n", ds->flags);
107 if (ds->addr.ss_family == AF_INET) {
108 struct sockaddr_in *sin;
109 sin = (struct sockaddr_in *)&ds->addr;
110 p = inet_ntop(AF_INET, &sin->sin_addr,
111 buf, sizeof (buf));
112 if (p == NULL)
113 p = "?";
114 (void) printf(" A %s %d\n", p, ds->port);
116 if (ds->addr.ss_family == AF_INET6) {
117 struct sockaddr_in6 *sin6;
118 sin6 = (struct sockaddr_in6 *)&ds->addr;
119 p = inet_ntop(AF_INET6, &sin6->sin6_addr,
120 buf, sizeof (buf));
121 if (p == NULL)
122 p = "?";
123 (void) printf(" AAAA %s %d\n", p, ds->port);
128 /* printflike */
129 void
130 mylogger(int pri, const char *format, ...)
132 _NOTE(ARGUNUSED(pri))
133 va_list args;
135 va_start(args, format);
136 (void) vfprintf(stderr, format, args);
137 (void) fprintf(stderr, "\n");
138 va_end(args);
142 * This is a unit-test program. Always enable libumem debugging.
144 const char *
145 _umem_debug_init(void)
147 return ("default,verbose"); /* $UMEM_DEBUG setting */
150 const char *
151 _umem_logging_init(void)
153 return ("fail,contents"); /* $UMEM_LOGGING setting */