- memcpy(&sin.sin_addr, h->h_addr, sizeof(sin.sin_addr));
- sin.sin_port= tserv->s_port;
- sin.sin_family = AF_INET;
+ s_in.sin_port = htons(37); /* find port # */
+ if ((tserv = getservbyname("time", "tcp")) != NULL)
+ s_in.sin_port = tserv->s_port;
+
+ s_in.sin_family = AF_INET;
+
+ if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) /* get net connection */
+ perror_msg_and_die("socket");
+
+ if (connect(fd, (struct sockaddr *)&s_in, sizeof(s_in)) < 0) /* connect to time server */
+ perror_msg_and_die("%s", host);
+
+ if (read(fd, (void *)&nett, 4) != 4) /* read time from server */
+ error_msg_and_die("%s did not send the complete time", host);