int main(int argc, char **argv) { int opt, only_query, timeout; struct timeval timeout_tv; in_addr_t addr; only_query = 0; timeout = MODOPS_TIMEOUT; getopt_init(); while (-1 != (opt = getopt(argc, argv, "hqt:"))) { switch (opt) { default: return -EINVAL; case 'h': printf("Usage: %s [-q] server", argv[0]); return 0; case 'q': /* Query only - don't set the clock */ only_query = 1; break; case 't': /* Maximum time waiting for a server response */ if (1 != sscanf(optarg, "%d", &timeout)) { printf("%s: error: wrong -t argument %s\n", argv[0], optarg); return -EINVAL; } break; } } if (optind >= argc) { printf("%s: error: no server specified\n", argv[0]); return -EINVAL; } else if (!inet_aton(argv[optind], (struct in_addr *)&addr)) { printf("%s: error: invalid address %s\n", argv[0], argv[optind]); return -EINVAL; } timeout_tv.tv_sec = timeout / MSEC_PER_SEC; timeout_tv.tv_usec = (timeout % MSEC_PER_SEC) * USEC_PER_MSEC; return ntpdate(addr, &timeout_tv, only_query); }
int main() { ntpdate(); return 0; }