8 #include <sys/socket.h>
13 #include <sys/types.h>
15 #include <arpa/inet.h>
16 #include <netinet/in.h>
18 /* open a socket to a tcp remote host with the specified port */
19 static int open_socket_out(const char *host, int port)
21 struct sockaddr_in sock_out;
26 res = socket(PF_INET, SOCK_STREAM, 0);
31 inet_aton(host, &addr);
33 sock_out.sin_addr = addr;
34 sock_out.sin_port = htons(port);
35 sock_out.sin_family = PF_INET;
37 if (connect(res,(struct sockaddr *)&sock_out,sizeof(sock_out)) != 0) {
39 fprintf(stderr,"failed to connect to %s (%s)\n",
40 host, strerror(errno));
48 static void unix_time(time_t t)
54 printf("%04d%02d%02d%02d%02d%02d\n",
55 tm->tm_year + 1900, tm->tm_mon+1, tm->tm_mday, tm->tm_hour,
56 tm->tm_min, tm->tm_sec);
59 int main(int argc, char *argv[])
66 printf("rtime <server> <offset>\n");
73 sock = open_socket_out(argv[1], 37);
75 if (read(sock, &t, sizeof(t)) == 4) {
76 unix_time(ofs + ntohl(t) - 2208988800U);