1/* 2 * Unix SMB/CIFS implementation. 3 * NetRemoteTOD query 4 * Copyright (C) Guenther Deschner 2008 5 * 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. 10 * 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. 15 * 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/>. 18 */ 19 20#include <sys/types.h> 21#include <inttypes.h> 22#include <stdio.h> 23#include <stdlib.h> 24#include <string.h> 25 26#include <netapi.h> 27 28#include "common.h" 29 30int main(int argc, const char **argv) 31{ 32 NET_API_STATUS status; 33 struct libnetapi_ctx *ctx = NULL; 34 const char *hostname = NULL; 35 struct TIME_OF_DAY_INFO *tod = NULL; 36 37 poptContext pc; 38 int opt; 39 40 struct poptOption long_options[] = { 41 POPT_AUTOHELP 42 POPT_COMMON_LIBNETAPI_EXAMPLES 43 POPT_TABLEEND 44 }; 45 46 status = libnetapi_init(&ctx); 47 if (status != 0) { 48 return status; 49 } 50 51 pc = poptGetContext("tod", argc, argv, long_options, 0); 52 53 poptSetOtherOptionHelp(pc, "hostname"); 54 while((opt = poptGetNextOpt(pc)) != -1) { 55 } 56 57 if (!poptPeekArg(pc)) { 58 poptPrintHelp(pc, stderr, 0); 59 goto out; 60 } 61 hostname = poptGetArg(pc); 62 63 64 /* NetRemoteTOD */ 65 66 status = NetRemoteTOD(hostname, 67 (uint8_t **)&tod); 68 if (status != 0) { 69 printf("NetRemoteTOD failed with: %s\n", 70 libnetapi_get_error_string(ctx, status)); 71 } else { 72 printf("%d-%d-%d %d:%d:%d\n", 73 tod->tod_day, tod->tod_month, tod->tod_year, 74 tod->tod_hours, tod->tod_mins, tod->tod_secs); 75 NetApiBufferFree(tod); 76 } 77 78 out: 79 libnetapi_free(ctx); 80 poptFreeContext(pc); 81 82 return status; 83} 84