summaryrefslogtreecommitdiff
path: root/source3/lib/netapi/examples/getdc
diff options
context:
space:
mode:
authorGünther Deschner <gd@samba.org>2008-04-08 14:34:30 +0200
committerGünther Deschner <gd@samba.org>2008-04-08 14:34:30 +0200
commitcccaef9e0896e9a3fcf9b860283543fd35d3f248 (patch)
treeba1c3244a682376c347ab1f8974b1e19106ac0f3 /source3/lib/netapi/examples/getdc
parent0f86cc18ff2e88a0f1fe244574ff5e3fcfce2f92 (diff)
downloadsamba-cccaef9e0896e9a3fcf9b860283543fd35d3f248.tar.gz
samba-cccaef9e0896e9a3fcf9b860283543fd35d3f248.tar.bz2
samba-cccaef9e0896e9a3fcf9b860283543fd35d3f248.zip
Use popt in libetapi example code.
Guenther (This used to be commit 6f239df3f5a57c9549f1637e53fd42d2ed604c3f)
Diffstat (limited to 'source3/lib/netapi/examples/getdc')
-rw-r--r--source3/lib/netapi/examples/getdc/getdc.c45
1 files changed, 37 insertions, 8 deletions
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 <netapi.h>
-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 <hostname> <domain>\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;
}