get rid of timewarp problems in client (server will be done later)

This commit is contained in:
Russ Dill
2004-05-19 08:26:01 +00:00
parent 7a77334126
commit 9a59393459
5 changed files with 18 additions and 12 deletions

View File

@@ -8,10 +8,10 @@ USRSHAREDIR=${prefix}/share
# Uncomment this to get a shared binary. Call as udhcpd for the server,
# and udhcpc for the client
COMBINED_BINARY=1
#COMBINED_BINARY=1
# Uncomment this for extra output and to compile with debugging symbols
#UDHCP_DEBUG=1
UDHCP_DEBUG=1
# Uncomment this to output messages to syslog, otherwise, messages go to stdout
#CFLAGS += -DUDHCP_SYSLOG

View File

@@ -6,7 +6,6 @@
*/
#include <sys/time.h>
#include <sys/sysinfo.h>
#include <time.h>
#include <sys/socket.h>
#include <netinet/if_ether.h>
@@ -42,7 +41,6 @@ int arpping(uint32_t yiaddr, uint32_t ip, uint8_t *mac, char *interface)
fd_set fdset;
struct timeval tm;
time_t prevTime;
struct sysinfo info;
if ((s = socket (PF_PACKET, SOCK_PACKET, htons(ETH_P_ARP))) == -1) {
@@ -81,8 +79,7 @@ int arpping(uint32_t yiaddr, uint32_t ip, uint8_t *mac, char *interface)
/* wait arp reply, and check it */
tm.tv_usec = 0;
sysinfo(&info);
prevTime = info.uptime;
prevTime = uptime();
while (timeout > 0) {
FD_ZERO(&fdset);
FD_SET(s, &fdset);
@@ -100,9 +97,8 @@ int arpping(uint32_t yiaddr, uint32_t ip, uint8_t *mac, char *interface)
break;
}
}
sysinfo(&info);
timeout -= info.uptime - prevTime;
prevTime = info.uptime;
timeout -= uptime() - prevTime;
prevTime = uptime();
}
close(s);
DEBUG(LOG_INFO, "%salid arp replies for this address", rv ? "No v" : "V");

View File

@@ -29,6 +29,7 @@
#include <signal.h>
#include <paths.h>
#include <sys/socket.h>
#include <sys/sysinfo.h>
#include <stdarg.h>
#include "common.h"
@@ -37,6 +38,14 @@
static int daemonized;
long uptime(void)
{
struct sysinfo info;
sysinfo(&info);
printf("uptime %d\n", info.uptime);
return info.uptime;
}
/*
* This function makes sure our first socket calls

View File

@@ -39,6 +39,7 @@ enum syslog_levels {
#include <syslog.h>
#endif
long uptime(void);
void background(const char *pidfile);
void start_log_and_pid(const char *client_server, const char *pidfile);
void background(const char *pidfile);

View File

@@ -188,7 +188,7 @@ int main(int argc, char *argv[])
int c, len;
struct dhcpMessage packet;
struct in_addr temp_addr;
time_t now;
long now;
int max_fd;
int sig;
@@ -290,7 +290,7 @@ int main(int argc, char *argv[])
for (;;) {
tv.tv_sec = timeout - time(0);
tv.tv_sec = timeout - uptime();
tv.tv_usec = 0;
if (listen_mode != LISTEN_NONE && fd < 0) {
@@ -310,7 +310,7 @@ int main(int argc, char *argv[])
retval = select(max_fd + 1, &rfds, NULL, NULL, &tv);
} else retval = 0; /* If we already timed out, fall through */
now = time(0);
now = uptime();
if (retval == 0) {
/* timeout dropped to zero */
switch (state) {