*
*/
-#include "busybox.h"
-#define BB_DECLARE_EXTERN
-#include "messages.c"
#include <sys/time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <stdio.h>
#include <getopt.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include "busybox.h"
+#define BB_DECLARE_EXTERN
+#include "messages.c"
-#define RFC_868_BIAS 2208988800UL
+static const int RFC_868_BIAS = 2208988800UL;
int setdate= 0;
int printdate= 0;
int fd;
if (!(h = gethostbyname(host))) { /* get the IP addr */
- errorMsg("%s: %s\n", host, strerror(errno));
+ perror_msg("%s", host);
return(-1);
}
if ((tserv = getservbyname("time", "tcp")) == NULL) { /* find port # */
- errorMsg("%s: %s\n", "time", strerror(errno));
+ perror_msg("%s", "time");
return(-1);
}
if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { /* get net connection */
- errorMsg("%s: %s\n", "socket", strerror(errno));
+ perror_msg("%s", "socket");
return(-1);
}
sin.sin_family = AF_INET;
if (connect(fd, (struct sockaddr *)&sin, sizeof(sin)) < 0) { /* connect to time server */
- errorMsg("%s: %s\n", host, strerror(errno));
+ perror_msg("%s", host);
close(fd);
return(-1);
}
if (read(fd, (void *)&nett, 4) != 4) { /* read time from server */
close(fd);
- errorMsg("%s did not send the complete time\n", host);
+ error_msg("%s did not send the complete time", host);
}
close(fd);
/* Interpret command line args */
/* do special-case option parsing */
if (argv[1] && (strcmp(argv[1], "--help") == 0))
- usage(rdate_usage);
+ show_usage();
/* do normal option parsing */
while ((opt = getopt(argc, argv, "Hsp")) > 0) {
switch (opt) {
default:
case 'H':
- usage(rdate_usage);
- return(FALSE);
+ show_usage();
break;
case 's':
setdate++;
if (printdate==0 && setdate==0) setdate++;
if (optind == argc) {
- usage(rdate_usage);
- return(FALSE);
+ show_usage();
}
if ((time= askremotedate(argv[optind])) == (time_t)-1) {
- return(FALSE);
+ return EXIT_FAILURE;
}
if (setdate) {
if (stime(&time) < 0)
- fatalError("Could not set time of day: %s\n", strerror(errno));
+ perror_msg_and_die("Could not set time of day");
}
if (printdate) {
- fprintf(stdout, "%s", ctime(&time));
+ printf("%s", ctime(&time));
}
- return(TRUE);
+ return EXIT_SUCCESS;
}