--- ppp-2.4.5.orig/pppd/main.c	2009-11-16 23:26:07.000000000 +0100
+++ ppp-2.4.5/pppd/main.c	2014-03-17 16:13:13.000000000 +0100
@@ -90,6 +90,7 @@
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
+#include <sys/sysinfo.h>
 
 #include "pppd.h"
 #include "magic.h"
@@ -159,10 +160,10 @@ TDB_CONTEXT *pppdb;		/* database for sto
 
 char db_key[32];
 
-int (*holdoff_hook) __P((void)) = NULL;
-int (*new_phase_hook) __P((int)) = NULL;
-void (*snoop_recv_hook) __P((unsigned char *p, int len)) = NULL;
-void (*snoop_send_hook) __P((unsigned char *p, int len)) = NULL;
+int (*holdoff_hook) (void) = NULL;
+int (*new_phase_hook) (int) = NULL;
+void (*snoop_recv_hook) (unsigned char *p, int len) = NULL;
+void (*snoop_send_hook) (unsigned char *p, int len) = NULL;
 
 static int conn_running;	/* we have a [dis]connector running */
 static int fd_loop;		/* fd for getting demand-dial packets */
@@ -218,7 +219,7 @@ bool bundle_terminating;
 struct subprocess {
     pid_t	pid;
     char	*prog;
-    void	(*done) __P((void *));
+    void	(*done) (void *);
     void	*arg;
     int		killable;
     struct subprocess *next;
@@ -228,38 +229,39 @@ static struct subprocess *children;
 
 /* Prototypes for procedures local to this file. */
 
-static void setup_signals __P((void));
-static void create_pidfile __P((int pid));
-static void create_linkpidfile __P((int pid));
-static void cleanup __P((void));
-static void get_input __P((void));
-static void calltimeout __P((void));
-static struct timeval *timeleft __P((struct timeval *));
-static void kill_my_pg __P((int));
-static void hup __P((int));
-static void term __P((int));
-static void chld __P((int));
-static void toggle_debug __P((int));
-static void open_ccp __P((int));
-static void bad_signal __P((int));
-static void holdoff_end __P((void *));
-static void forget_child __P((int pid, int status));
-static int reap_kids __P((void));
-static void childwait_end __P((void *));
+static void check_time(void);
+static void setup_signals (void);
+static void create_pidfile (int pid);
+static void create_linkpidfile (int pid);
+static void cleanup (void);
+static void get_input (void);
+static void calltimeout (void);
+static struct timeval *timeleft (struct timeval *);
+static void kill_my_pg (int);
+static void hup (int);
+static void term (int);
+static void chld (int);
+static void toggle_debug (int);
+static void open_ccp (int);
+static void bad_signal (int);
+static void holdoff_end (void *);
+static void forget_child (int pid, int status);
+static int reap_kids (void);
+static void childwait_end (void *);
 
 #ifdef USE_TDB
-static void update_db_entry __P((void));
-static void add_db_key __P((const char *));
-static void delete_db_key __P((const char *));
-static void cleanup_db __P((void));
+static void update_db_entry (void);
+static void add_db_key (const char *);
+static void delete_db_key (const char *);
+static void cleanup_db (void);
 #endif
 
-static void handle_events __P((void));
-void print_link_stats __P((void));
+static void handle_events (void);
+void print_link_stats (void);
 
-extern	char	*ttyname __P((int));
-extern	char	*getlogin __P((void));
-int main __P((int, char *[]));
+extern	char	*ttyname (int);
+extern	char	*getlogin (void);
+int main (int, char *[]);
 
 #ifdef ultrix
 #undef	O_NONBLOCK
@@ -530,6 +532,7 @@ main(argc, argv)
 	    info("Starting link");
 	}
 
+	check_time();
 	gettimeofday(&start_time, NULL);
 	script_unsetenv("CONNECT_TIME");
 	script_unsetenv("BYTES_SENT");
@@ -1257,19 +1260,49 @@ update_link_stats(u)
 struct	callout {
     struct timeval	c_time;		/* time at which to call routine */
     void		*c_arg;		/* argument to routine */
-    void		(*c_func) __P((void *)); /* routine */
+    void		(*c_func) (void *); /* routine */
     struct		callout *c_next;
 };
 
 static struct callout *callout = NULL;	/* Callout list */
 static struct timeval timenow;		/* Current time */
+static long uptime_diff = 0;
+static int uptime_diff_set = 0;
+
+static void check_time(void)
+{
+	long new_diff;
+	struct timeval t;
+	struct sysinfo i;
+    struct callout *p;
+	
+	gettimeofday(&t, NULL);
+	sysinfo(&i);
+	new_diff = t.tv_sec - i.uptime;
+	
+	if (!uptime_diff_set) {
+		uptime_diff = new_diff;
+		uptime_diff_set = 1;
+		return;
+	}
+
+	if ((new_diff - 5 > uptime_diff) || (new_diff + 5 < uptime_diff)) {
+		/* system time has changed, update counters and timeouts */
+		info("System time change detected.");
+		start_time.tv_sec += new_diff - uptime_diff;
+		
+    	for (p = callout; p != NULL; p = p->c_next)
+			p->c_time.tv_sec += new_diff - uptime_diff;
+	}
+	uptime_diff = new_diff;
+}
 
 /*
  * timeout - Schedule a timeout.
  */
 void
 timeout(func, arg, secs, usecs)
-    void (*func) __P((void *));
+    void (*func) (void *);
     void *arg;
     int secs, usecs;
 {
@@ -1308,7 +1341,7 @@ timeout(func, arg, secs, usecs)
  */
 void
 untimeout(func, arg)
-    void (*func) __P((void *));
+    void (*func) (void *);
     void *arg;
 {
     struct callout **copp, *freep;
@@ -1333,6 +1366,8 @@ calltimeout()
 {
     struct callout *p;
 
+	check_time();
+	
     while (callout != NULL) {
 	p = callout;
 
@@ -1360,6 +1395,8 @@ timeleft(tvp)
 {
     if (callout == NULL)
 	return NULL;
+	
+	check_time();
 
     gettimeofday(&timenow, NULL);
     tvp->tv_sec = callout->c_time.tv_sec - timenow.tv_sec;
@@ -1692,7 +1729,7 @@ run_program(prog, args, must_exist, done
     char *prog;
     char **args;
     int must_exist;
-    void (*done) __P((void *));
+    void (*done) (void *);
     void *arg;
     int wait;
 {
@@ -1767,7 +1804,7 @@ void
 record_child(pid, prog, done, arg, killable)
     int pid;
     char *prog;
-    void (*done) __P((void *));
+    void (*done) (void *);
     void *arg;
     int killable;
 {
