Changeset 1770 in MondoRescue for branches/stable/mindi-busybox/util-linux/rdate.c
- Timestamp:
- Nov 6, 2007, 11:01:53 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/stable/mindi-busybox/util-linux/rdate.c
r821 r1770 9 9 */ 10 10 11 #include <sys/types.h> 12 #include <sys/socket.h> 13 #include <netinet/in.h> 14 #include <netdb.h> 15 #include <stdio.h> 16 #include <string.h> 17 #include <time.h> 18 #include <stdlib.h> 19 #include <unistd.h> 20 #include <signal.h> 11 #include "libbb.h" 21 12 22 #include "busybox.h" 23 24 25 static const int RFC_868_BIAS = 2208988800UL; 13 enum { RFC_868_BIAS = 2208988800UL }; 26 14 27 15 static void socket_timeout(int sig) … … 32 20 static time_t askremotedate(const char *host) 33 21 { 34 unsigned long nett; 35 struct sockaddr_in s_in; 22 uint32_t nett; 36 23 int fd; 37 38 bb_lookup_host(&s_in, host);39 s_in.sin_port = bb_lookup_port("time", "tcp", 37);40 24 41 25 /* Add a timeout for dead or inaccessible servers */ … … 43 27 signal(SIGALRM, socket_timeout); 44 28 45 fd = xconnect(&s_in);29 fd = create_and_connect_stream_or_die(host, bb_lookup_port("time", "tcp", 37)); 46 30 47 31 if (safe_read(fd, (void *)&nett, 4) != 4) /* read time from server */ … … 51 35 /* convert from network byte order to local byte order. 52 36 * RFC 868 time is the number of seconds 53 * 54 * 55 * Subtract the RFC 868 time 37 * since 00:00 (midnight) 1 January 1900 GMT 38 * the RFC 868 time 2,208,988,800 corresponds to 00:00 1 Jan 1970 GMT 39 * Subtract the RFC 868 time to get Linux epoch 56 40 */ 57 41 58 return (ntohl(nett) - RFC_868_BIAS);42 return ntohl(nett) - RFC_868_BIAS; 59 43 } 60 44 45 int rdate_main(int argc, char **argv); 61 46 int rdate_main(int argc, char **argv) 62 47 { … … 64 49 unsigned long flags; 65 50 66 bb_opt_complementally = "-1";67 flags = bb_getopt_ulflags(argc,argv, "sp");51 opt_complementary = "-1"; 52 flags = getopt32(argv, "sp"); 68 53 69 54 remote_time = askremotedate(argv[optind]); … … 74 59 time(¤t_time); 75 60 if (current_time == remote_time) 76 bb_error_msg(" Current time matches remote time.");61 bb_error_msg("current time matches remote time"); 77 62 else 78 63 if (stime(&remote_time) < 0) 79 bb_perror_msg_and_die(" Couldnot set time of day");64 bb_perror_msg_and_die("cannot set time of day"); 80 65 } 81 66
Note:
See TracChangeset
for help on using the changeset viewer.