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
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.
21 #include <netinet/in.h>
22 #include <arpa/inet.h>
25 char *domainname
= NULL
;
27 void print_ds(ad_disc_ds_t
*);
28 void mylogger(int pri
, const char *format
, ...);
31 main(int argc
, char *argv
[])
33 ad_disc_t ad_ctx
= NULL
;
35 ad_disc_ds_t
*dc
, *gc
;
39 while ((c
= getopt(argc
, argv
, "d")) != -1) {
42 (void) fprintf(stderr
, "bad option: -%c\n", optopt
);
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
);
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
);
67 (void) printf("getdc failed\n");
70 (void) printf("Found a DC:\n");
74 s
= ad_disc_get_ForestName(ad_ctx
, NULL
);
75 (void) printf("Forest: %s\n", s
);
78 s
= ad_disc_get_SiteName(ad_ctx
, NULL
);
79 (void) printf("Site: %s\n", s
);
82 gc
= ad_disc_get_GlobalCatalog(ad_ctx
,
83 AD_DISC_PREFER_SITE
, &autodisc
);
85 (void) printf("Found a GC:\n");
98 print_ds(ad_disc_ds_t
*ds
)
102 for (; ds
->host
[0] != '\0'; ds
++) {
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
,
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
,
123 (void) printf(" AAAA %s %d\n", p
, ds
->port
);
130 mylogger(int pri
, const char *format
, ...)
132 _NOTE(ARGUNUSED(pri
))
135 va_start(args
, format
);
136 (void) vfprintf(stderr
, format
, args
);
137 (void) fprintf(stderr
, "\n");
142 * This is a unit-test program. Always enable libumem debugging.
145 _umem_debug_init(void)
147 return ("default,verbose"); /* $UMEM_DEBUG setting */
151 _umem_logging_init(void)
153 return ("fail,contents"); /* $UMEM_LOGGING setting */