2 * Unix SMB/CIFS implementation.
4 * Copyright (C) Guenther Deschner 2007
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
20 #include <sys/types.h>
30 int main(int argc, const char **argv)
32 NET_API_STATUS status;
33 struct libnetapi_ctx *ctx = NULL;
35 const char *hostname = NULL;
36 const char *domain = NULL;
37 uint8_t *buffer = NULL;
42 struct poptOption long_options[] = {
44 POPT_COMMON_LIBNETAPI_EXAMPLES
48 status = libnetapi_init(&ctx);
53 pc = poptGetContext("getdc", argc, argv, long_options, 0);
55 poptSetOtherOptionHelp(pc, "hostname domainname");
56 while((opt = poptGetNextOpt(pc)) != -1) {
59 if (!poptPeekArg(pc)) {
60 poptPrintHelp(pc, stderr, 0);
63 hostname = poptGetArg(pc);
65 if (!poptPeekArg(pc)) {
66 poptPrintHelp(pc, stderr, 0);
69 domain = poptGetArg(pc);
73 status = NetGetDCName(hostname, domain, &buffer);
75 printf("GetDcName failed with: %s\n", libnetapi_errstr(status));
77 printf("%s\n", (char *)buffer);
81 NetApiBufferFree(buffer);