From cccaef9e0896e9a3fcf9b860283543fd35d3f248 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 8 Apr 2008 14:34:30 +0200 Subject: Use popt in libetapi example code. Guenther (This used to be commit 6f239df3f5a57c9549f1637e53fd42d2ed604c3f) --- source3/lib/netapi/examples/getdc/getdc.c | 45 +++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 8 deletions(-) (limited to 'source3/lib/netapi/examples/getdc') diff --git a/source3/lib/netapi/examples/getdc/getdc.c b/source3/lib/netapi/examples/getdc/getdc.c index 272ba1088e..98bb6a13b2 100644 --- a/source3/lib/netapi/examples/getdc/getdc.c +++ b/source3/lib/netapi/examples/getdc/getdc.c @@ -25,33 +25,62 @@ #include -int main(int argc, char **argv) +#include "common.h" + +int main(int argc, const char **argv) { NET_API_STATUS status; struct libnetapi_ctx *ctx = NULL; + + const char *hostname = NULL; + const char *domain = NULL; uint8_t *buffer = NULL; - if (argc < 3) { - printf("usage: getdc \n"); - return -1; - } + poptContext pc; + int opt; + + struct poptOption long_options[] = { + POPT_AUTOHELP + POPT_COMMON_LIBNETAPI_EXAMPLES + POPT_TABLEEND + }; status = libnetapi_init(&ctx); if (status != 0) { return status; } - libnetapi_set_username(ctx, ""); - libnetapi_set_password(ctx, ""); + pc = poptGetContext("getdc", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "hostname domainname"); + while((opt = poptGetNextOpt(pc)) != -1) { + } + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + hostname = poptGetArg(pc); + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + domain = poptGetArg(pc); + + /* NetGetDCName */ - status = NetGetDCName(argv[1], argv[2], &buffer); + status = NetGetDCName(hostname, domain, &buffer); if (status != 0) { printf("GetDcName failed with: %s\n", libnetapi_errstr(status)); } else { printf("%s\n", (char *)buffer); } + + out: NetApiBufferFree(buffer); libnetapi_free(ctx); + poptFreeContext(pc); return status; } -- cgit