mirror of
https://github.com/sheumann/hush.git
synced 2024-12-21 23:29:34 +00:00
68404f13d4
function old new delta procps_scan 1265 1298 +33 aliascmd 278 283 +5 parse_file_cmd 116 120 +4 dname_enc 373 377 +4 setcmd 90 93 +3 execcmd 57 60 +3 count_lines 72 74 +2 process_command_subs 340 339 -1 test_main 409 407 -2 mknod_main 179 177 -2 handle_incoming_and_exit 2653 2651 -2 argstr 1312 1310 -2 shiftcmd 131 128 -3 exitcmd 46 43 -3 dotcmd 297 294 -3 breakcmd 86 83 -3 evalpipe 353 349 -4 evalcommand 1180 1176 -4 evalcmd 109 105 -4 send_tree 374 369 -5 mkfifo_main 82 77 -5 evalsubshell 152 147 -5 typecmd 75 69 -6 letcmd 61 55 -6 add_cmd 1190 1183 -7 main 891 883 -8 ash_main 1415 1407 -8 parse_stream 1377 1367 -10 alloc_procps_scan 55 - -55 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 7/21 up/down: 54/-148) Total: -94 bytes text data bss dec hex filename 797195 658 7428 805281 c49a1 busybox_old 797101 658 7428 805187 c4943 busybox_unstripped
72 lines
1.7 KiB
C
72 lines
1.7 KiB
C
/* vi: set sw=4 ts=4: */
|
|
/*
|
|
* The Rdate command will ask a time server for the RFC 868 time
|
|
* and optionally set the system time.
|
|
*
|
|
* by Sterling Huxley <sterling@europa.com>
|
|
*
|
|
* Licensed under GPL v2 or later, see file License for details.
|
|
*/
|
|
|
|
#include "libbb.h"
|
|
|
|
enum { RFC_868_BIAS = 2208988800UL };
|
|
|
|
static void socket_timeout(int sig ATTRIBUTE_UNUSED)
|
|
{
|
|
bb_error_msg_and_die("timeout connecting to time server");
|
|
}
|
|
|
|
static time_t askremotedate(const char *host)
|
|
{
|
|
uint32_t nett;
|
|
int fd;
|
|
|
|
/* Add a timeout for dead or inaccessible servers */
|
|
alarm(10);
|
|
signal(SIGALRM, socket_timeout);
|
|
|
|
fd = create_and_connect_stream_or_die(host, bb_lookup_port("time", "tcp", 37));
|
|
|
|
if (safe_read(fd, (void *)&nett, 4) != 4) /* read time from server */
|
|
bb_error_msg_and_die("%s did not send the complete time", host);
|
|
close(fd);
|
|
|
|
/* convert from network byte order to local byte order.
|
|
* RFC 868 time is the number of seconds
|
|
* since 00:00 (midnight) 1 January 1900 GMT
|
|
* the RFC 868 time 2,208,988,800 corresponds to 00:00 1 Jan 1970 GMT
|
|
* Subtract the RFC 868 time to get Linux epoch
|
|
*/
|
|
|
|
return ntohl(nett) - RFC_868_BIAS;
|
|
}
|
|
|
|
int rdate_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
|
int rdate_main(int argc ATTRIBUTE_UNUSED, char **argv)
|
|
{
|
|
time_t remote_time;
|
|
unsigned long flags;
|
|
|
|
opt_complementary = "-1";
|
|
flags = getopt32(argv, "sp");
|
|
|
|
remote_time = askremotedate(argv[optind]);
|
|
|
|
if ((flags & 2) == 0) {
|
|
time_t current_time;
|
|
|
|
time(¤t_time);
|
|
if (current_time == remote_time)
|
|
bb_error_msg("current time matches remote time");
|
|
else
|
|
if (stime(&remote_time) < 0)
|
|
bb_perror_msg_and_die("cannot set time of day");
|
|
}
|
|
|
|
if ((flags & 1) == 0)
|
|
printf("%s", ctime(&remote_time));
|
|
|
|
return EXIT_SUCCESS;
|
|
}
|