diff -Nur ntp-4.1.0.orig/acconfig.h ntp-4.1.0/acconfig.h
--- ntp-4.1.0.orig/acconfig.h	Thu Apr 26 01:58:55 2001
+++ ntp-4.1.0/acconfig.h	Tue Nov  5 16:00:04 2002
@@ -130,6 +130,9 @@
 /* RCC 8000 clock */
 #undef CLOCK_RCC8000
 
+/* standard Linux RTC */
+#undef CLOCK_RTCLINUX
+
 /* Schmid DCF77 clock */
 #undef CLOCK_SCHMID
 
diff -Nur ntp-4.1.0.orig/config.h.in ntp-4.1.0/config.h.in
--- ntp-4.1.0.orig/config.h.in	Thu Apr 26 01:58:55 2001
+++ ntp-4.1.0/config.h.in	Tue Nov  5 16:00:45 2002
@@ -131,6 +131,9 @@
 /* RCC 8000 clock */
 #undef CLOCK_RCC8000
 
+/* standard Linux RTC */
+#undef CLOCK_RTCLINUX
+
 /* Schmid DCF77 clock */
 #undef CLOCK_SCHMID
 
diff -Nur ntp-4.1.0.orig/configure.in ntp-4.1.0/configure.in
--- ntp-4.1.0.orig/configure.in	Thu Aug  2 00:45:17 2001
+++ ntp-4.1.0/configure.in	Tue Nov  5 10:15:01 2002
@@ -2163,6 +2163,15 @@
     ;;
 esac
 
+AC_MSG_CHECKING(Standard Linux RTC)
+AC_ARG_ENABLE(RTCLINUX,		[  --enable-RTCLINUX            + Standard Linux RTC],
+    [ntp_ok=$enableval], [ntp_ok=$ntp_eac])
+if test "$ntp_ok" = "yes"; then
+    ntp_refclock=yes
+    AC_DEFINE(CLOCK_RTCLINUX)
+fi
+AC_MSG_RESULT($ntp_ok)
+
 AC_MSG_CHECKING(Schmid DCF77 clock)
 AC_ARG_ENABLE(SCHMID,		[  --enable-SCHMID         s Schmid DCF77 clock],
     [ntp_ok=$enableval], [ntp_ok=$ntp_eapc])
diff -Nur ntp-4.1.0.orig/ntpd/refclock_rtclinux.c ntp-4.1.0/ntpd/refclock_rtclinux.c
--- ntp-4.1.0.orig/ntpd/refclock_rtclinux.c	Thu Jan  1 01:00:00 1970
+++ ntp-4.1.0/ntpd/refclock_rtclinux.c	Sun Jan  5 12:18:17 2003
@@ -0,0 +1,264 @@
+/*
+ * refclock_rtclinux - clock driver for the standard Linux RTC
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#if defined(REFCLOCK) && defined(CLOCK_RTCLINUX)
+
+#include "ntpd.h"
+#include "ntp_io.h"
+#include "ntp_refclock.h"
+#include "ntp_calendar.h"
+#include "ntp_stdlib.h"
+
+#include <sys/ioctl.h>
+#include <linux/rtc.h>
+
+/*
+ * This driver supports the standard Linux RTC.
+ */
+
+/*
+ * Interface definitions
+ */
+#define	DEVICE		"/dev/rtc"
+#define	PRECISION	(-1)	/* precision assumed (about 0.5 s) */
+#define REFID		"RTC"
+#define DESCRIPTION	"Standard Linux RTC"
+
+/*
+ * Function prototypes
+ */
+static	int 	rtclinux_start 		P((int, struct peer *));
+static	void	rtclinux_shutdown	P((int, struct peer *));
+static	void	rtclinux_poll		P((int, struct peer *));
+
+static inline int compute_yday(struct tm *);
+
+/*
+ * Transfer vector
+ */
+struct  refclock refclock_rtclinux = {
+	rtclinux_start,         /* start up driver */
+	rtclinux_shutdown,      /* shut down driver */
+	rtclinux_poll,          /* transmit poll message */
+	noentry,                /* not used */
+	noentry,                /* initialize driver (not used) */
+	noentry,                /* not used */
+	NOFLAGS                 /* not used */
+};
+
+/*
+ * This variable indicates that the Hardware Clock is kept in
+ * Coordinated Universal Time (0) or local time (1)
+ */
+static	int	rtclinux_rtc_local = 1;
+
+/*
+ * rtclinux_start - open the device and initialize data for processing
+ */
+static int
+rtclinux_start(
+     	int unit,
+	struct peer *peer
+	)
+{
+	struct refclockproc *pp;
+	int fd;
+	FILE *adjfile;
+
+	/*
+	 * Open device file for reading.
+	 */
+	fd = open(DEVICE, O_RDONLY);
+	if (fd == -1) {
+		return (0);
+	}
+	
+	pp = peer->procptr;
+	pp->io.clock_recv = noentry;
+	pp->io.srcclock = (caddr_t)peer;
+	pp->io.datalen = 0;
+	pp->io.fd = fd;
+	
+	/*
+	 * Initialize miscellaneous variables
+	 */
+	peer->precision = PRECISION;
+	pp->clockdesc = DESCRIPTION;
+	memcpy((char *)&pp->refid, REFID, 4);
+	
+	/*
+	 * Check whether --utc or --localtime was specified the last time
+	 * hwclock was used to set the clock
+	 */
+	if ((adjfile = fopen("/etc/adjtime", "r")) != NULL)
+	{
+		char line[81] = {0};
+		
+		fgets(line, sizeof(line), adjfile);
+		fgets(line, sizeof(line), adjfile);
+		fgets(line, sizeof(line), adjfile);
+		fclose(adjfile);
+		
+		if (!strcmp(line, "UTC\n"))
+		{
+			rtclinux_rtc_local = 0;
+		}
+	}
+
+#ifdef DEBUG
+	if (debug)
+		printf ("RTCLINUX: Hardware Clock is kept in %s\n",
+			rtclinux_rtc_local ? "local time" : "Universal Time");
+#endif
+
+	return (1);
+}
+
+
+/*
+ * rtclinux_shutdown - shut down the clock
+ */
+static void
+rtclinux_shutdown(
+	int unit,
+	struct peer *peer
+	)
+{
+	struct refclockproc *pp;
+	
+	pp = peer->procptr;
+	(void)close(pp->io.fd);
+}
+
+
+/*
+ * rtclinux_poll - called by the transmit procedure
+ */
+static void
+rtclinux_poll(
+	int unit,
+	struct peer *peer
+	)
+{
+	struct refclockproc *pp;
+	struct tm tm, *tp;
+	struct rtc_time rtc_tm;
+	time_t t;
+	
+	pp = peer->procptr;
+
+	if (ioctl(pp->io.fd, RTC_RD_TIME, &rtc_tm) == -1) {
+		refclock_report(peer, CEVNT_FAULT);
+		return;
+	}
+
+	tm.tm_sec   = rtc_tm.tm_sec;
+	tm.tm_min   = rtc_tm.tm_min;
+	tm.tm_hour  = rtc_tm.tm_hour;
+	tm.tm_mday  = rtc_tm.tm_mday;
+	tm.tm_mon   = rtc_tm.tm_mon;
+	tm.tm_year  = rtc_tm.tm_year;
+	tm.tm_yday  = compute_yday (&tm);
+	tm.tm_isdst = -1;
+
+	if (rtclinux_rtc_local)
+	{
+#ifdef DEBUG
+		if (debug)
+			printf ("RTCLINUX: RTC time is "
+				"%04d/%02d/%02d %02d:%02d:%02d %s/%s\n",
+				tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour,
+				tm.tm_min, tm.tm_sec, tzname[0], tzname[1]);
+#endif
+
+		t = mktime(&tm);
+		if (t == (time_t) -1) {
+			refclock_report(peer, CEVNT_BADTIME);
+			return;
+		}
+
+		pp->lencode = strftime(pp->a_lastcode, BMAX, "%Y %m %d %H %M %S", &tm);
+
+		tp = gmtime(&t);
+		if (!tp) {
+			refclock_report(peer, CEVNT_FAULT);
+			return;
+		}
+
+		get_systime(&pp->lastrec);
+		pp->polls++;
+		pp->year = tp->tm_year + 1900;
+		pp->day = tp->tm_yday + 1;
+		pp->hour = tp->tm_hour;
+		pp->minute = tp->tm_min;
+		pp->second = tp->tm_sec;
+		pp->usec = 0;
+		pp->msec = 0;
+
+#ifdef DEBUG
+		if (debug)
+			printf ("RTCLINUX: time is "
+				"%04d/%02d/%02d %02d:%02d:%02d UTC\n",
+				pp->year, tp->tm_mon + 1, tp->tm_mday, pp->hour,
+				pp->minute, pp->second);
+#endif
+	}
+	else
+	{
+#ifdef DEBUG
+		if (debug)
+			printf ("RTCLINUX: RTC time is "
+				"%04d/%02d/%02d %02d:%02d:%02d UTC\n",
+				tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour,
+				tm.tm_min, tm.tm_sec);
+#endif
+		pp->lencode = strftime(pp->a_lastcode, BMAX, "%Y %m %d %H %M %S", &tm);
+		get_systime(&pp->lastrec);
+
+		pp->polls++;
+		pp->year = tm.tm_year + 1900;
+		pp->day = tm.tm_yday + 1;
+		pp->hour = tm.tm_hour;
+		pp->minute = tm.tm_min;
+		pp->second = tm.tm_sec;
+		pp->usec = 0;
+		pp->msec = 0;
+	}
+
+	if (!refclock_process(pp)) {
+		refclock_report(peer, CEVNT_BADTIME);
+		return;
+	}
+	record_clock_stats(&peer->srcadr, pp->a_lastcode);
+	pp->leap = LEAP_NOWARNING;
+	refclock_receive(peer);
+}
+#else
+int refclock_rtclinux_bs;
+#endif /* REFCLOCK */
+
+#define is_leap(year) \
+          ((year) % 4 == 0 && ((year) % 100 != 0 || (year) % 400 == 0))
+
+static const unsigned short int __mon_yday[2][13] =
+{
+	/* Normal years.  */
+	{ 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 },
+	/* Leap years.  */  
+	{ 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 }
+};
+
+/*
+ * returns day of the year [0-365]
+ */
+static inline int
+compute_yday(struct tm * tp)
+{
+	return
+	  __mon_yday[is_leap(tp->tm_year + 1900)][tp->tm_mon] + tp->tm_mday - 1;
+}
diff -Naur ntp-4.1.1a.orig/include/ntp.h ntp-4.1.1a/include/ntp.h
--- ntp-4.1.1a.orig/include/ntp.h	Tue Mar 26 18:59:57 2002
+++ ntp-4.1.1a/include/ntp.h	Tue Jul 22 06:45:55 2003
@@ -459,7 +459,8 @@
 #define REFCLK_HOPF_PCI		39	/* hopf DCF77/GPS PCI receiver  */
 #define REFCLK_JJY		40	/* JJY receiver  */
 #define REFCLK_ZYFER		41	/* Zyfer GPStarplus receiver  */
-#define REFCLK_MAX		41	/* Grow as needed... */
+#define REFCLK_RTC_LINUX	42	/* standard Linux RTC */
+#define REFCLK_MAX		43	/* Grow as needed... */
 
 /*
  * We tell reference clocks from real peers by giving the reference
diff -Naur ntp-4.1.1a.orig/libntp/clocktypes.c ntp-4.1.1a/libntp/clocktypes.c
--- ntp-4.1.1a.orig/libntp/clocktypes.c	Tue Mar 26 18:59:57 2002
+++ ntp-4.1.1a/libntp/clocktypes.c	Tue Jul 22 06:46:57 2003
@@ -94,6 +94,8 @@
 	  "JJY" },
 	{ REFCLK_ZYFER,	"Zyfer GPStarplus receiver (41)",
 	  "GPS_ZYFER" },
+	{ REFCLK_RTC_LINUX,	"standard Linux RTC (42)",
+	  "RTC_LINUX"},
 	{ -1,			"", "" }
 };
 
diff -Naur ntp-4.1.1a.orig/ntpd/Makefile.am ntp-4.1.1a/ntpd/Makefile.am
--- ntp-4.1.1a.orig/ntpd/Makefile.am	Fri Mar 29 01:45:12 2002
+++ ntp-4.1.1a/ntpd/Makefile.am	Tue Jul 22 06:51:18 2003
@@ -37,7 +37,7 @@
 	refclock_pcf.c refclock_pst.c refclock_ptbacts.c refclock_shm.c \
 	refclock_tpro.c refclock_trak.c refclock_true.c refclock_tt560.c \
 	refclock_ulink.c refclock_usno.c refclock_wwv.c refclock_wwvb.c \
-	refclock_zyfer.c
+	refclock_zyfer.c refclock_rtclinux.c
 
 $(PROGRAMS): $(LDADD)
 
diff -Naur ntp-4.1.1a.orig/ntpd/ntp_control.c ntp-4.1.1a/ntpd/ntp_control.c
--- ntp-4.1.1a.orig/ntpd/ntp_control.c	Fri Mar 29 02:53:20 2002
+++ ntp-4.1.1a/ntpd/ntp_control.c	Tue Jul 22 06:52:59 2003
@@ -398,6 +398,7 @@
 	CTL_SST_TS_LF,		/* REFCLK_JJY (40) */
 	CTL_SST_TS_UHF,		/* REFCLK_TT560 (41) */
 	CTL_SST_TS_UHF,		/* REFCLK_ZYFER (42) */
+	CTL_SST_TS_LOCAL,	/* REFCLK_RTC_LINUX (43) */
 };
 
 
diff -Naur ntp-4.1.1a.orig/ntpd/refclock_conf.c ntp-4.1.1a/ntpd/refclock_conf.c
--- ntp-4.1.1a.orig/ntpd/refclock_conf.c	Fri Mar 29 01:41:10 2002
+++ ntp-4.1.1a/ntpd/refclock_conf.c	Tue Jul 22 06:54:22 2003
@@ -258,6 +258,12 @@
 #define	refclock_zyfer refclock_none
 #endif
 
+#ifdef CLOCK_RTCLINUX
+extern struct refclock refclock_rtclinux;
+#else
+#define        refclock_rtclinux refclock_none
+#endif
+
 /*
  * Order is clock_start(), clock_shutdown(), clock_poll(),
  * clock_control(), clock_init(), clock_buginfo, clock_flags;
@@ -307,7 +313,8 @@
 	&refclock_hopfpci,	/* 39 REFCLK_HOPF_PCI */
 	&refclock_jjy,		/* 40 REFCLK_JJY */
 	&refclock_tt560,	/* 41 REFCLK_TT560 */
-	&refclock_zyfer		/* 42 REFCLK_ZYFER */
+	&refclock_zyfer,	/* 42 REFCLK_ZYFER */
+	&refclock_rtclinux	/* 43 REFCLK_RTC_LINUX */
 };
 
 u_char num_refclock_conf = sizeof(refclock_conf)/sizeof(struct refclock *);
--- ntp-4.1.1a.orig/configure	Fri Mar 29 02:11:29 2002
+++ ntp-4.1.1a/configure	Tue Jul 22 08:19:35 2003
@@ -725,6 +725,7 @@
   --enable-MEINBERG       s Meinberg clocks
   --enable-RAWDCF         s DCF77 raw time code
   --enable-RCC8000        s RCC 8000 clock
+  --enable-RTCLINUX	  + Standard Linux RTC
   --enable-SCHMID         s Schmid DCF77 clock
   --enable-TRIMTAIP       s Trimble GPS receiver/TAIP protocol
   --enable-TRIMTSIP       s Trimble GPS receiver/TSIP protocol
@@ -13395,6 +13396,25 @@
    { (exit 1); exit 1; }; }
     ;;
 esac
+
+echo "$as_me:12835: checking Standard Linux RTC" >&5
+echo $ECHO_N "checking Standard Linux RTC... $ECHO_C" >&6
+# Check whether --enable-RTCLINUX or --disable-RTCLINUX was given.
+if test "${enable_RTCLINUX+set}" = set; then
+  enableval="$enable_RTCLINUX"
+  ntp_ok=$enableval
+else
+  ntp_ok=$ntp_eac
+fi;
+if test "$ntp_ok" = "yes"; then
+    ntp_refclock=yes
+    cat >>confdefs.h <<\EOF
+#define CLOCK_RTCLINUX 1
+EOF
+
+fi
+echo "$as_me:12851: result: $ntp_ok" >&5
+echo "${ECHO_T}$ntp_ok" >&6
 
 echo "$as_me:13399: checking Schmid DCF77 clock" >&5
 echo $ECHO_N "checking Schmid DCF77 clock... $ECHO_C" >&6
--- ntp-4.1.1a.orig/ntpd/Makefile.in	Tue Jul 22 06:42:25 2003
+++ ntp-4.1.1a/ntpd/Makefile.in	Tue Jul 22 08:23:59 2003
@@ -146,7 +146,7 @@
 	refclock_pcf.c refclock_pst.c refclock_ptbacts.c refclock_shm.c \
 	refclock_tpro.c refclock_trak.c refclock_true.c refclock_tt560.c \
 	refclock_ulink.c refclock_usno.c refclock_wwv.c refclock_wwvb.c \
-	refclock_zyfer.c
+	refclock_zyfer.c refclock_rtclinux.c
 
 subdir = ntpd
 mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
@@ -190,7 +190,8 @@
 	refclock_trak$U.$(OBJEXT) refclock_true$U.$(OBJEXT) \
 	refclock_tt560$U.$(OBJEXT) refclock_ulink$U.$(OBJEXT) \
 	refclock_usno$U.$(OBJEXT) refclock_wwv$U.$(OBJEXT) \
-	refclock_wwvb$U.$(OBJEXT) refclock_zyfer$U.$(OBJEXT)
+	refclock_wwvb$U.$(OBJEXT) refclock_zyfer$U.$(OBJEXT) \
+	refclock_rtclinux$U.$(OBJEXT)
 ntpd_OBJECTS = $(am_ntpd_OBJECTS)
 ntpd_DEPENDENCIES = version.o ../libntp/libntp.a
 ntpd_LDFLAGS =
@@ -254,7 +255,8 @@
 @AMDEP_TRUE@	$(DEPDIR)/refclock_usno$U.Po \
 @AMDEP_TRUE@	$(DEPDIR)/refclock_wwv$U.Po \
 @AMDEP_TRUE@	$(DEPDIR)/refclock_wwvb$U.Po \
-@AMDEP_TRUE@	$(DEPDIR)/refclock_zyfer$U.Po
+@AMDEP_TRUE@	$(DEPDIR)/refclock_zyfer$U.Po \
+@AMDEP_TRUE@	$(DEPDIR)/refclock_rtclinux$U.Po
 COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
 	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
 CCLD = $(CC)
@@ -380,6 +382,7 @@
 @AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/refclock_wwv$U.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/refclock_wwvb$U.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/refclock_zyfer$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/refclock_rtclinux$U.Po@am__quote@
 
 distclean-depend:
 	-rm -rf $(DEPDIR)
@@ -516,6 +519,8 @@
 	$(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/refclock_wwvb.c; then echo $(srcdir)/refclock_wwvb.c; else echo refclock_wwvb.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > refclock_wwvb_.c || rm -f refclock_wwvb_.c
 refclock_zyfer_.c: refclock_zyfer.c $(ANSI2KNR)
 	$(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/refclock_zyfer.c; then echo $(srcdir)/refclock_zyfer.c; else echo refclock_zyfer.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > refclock_zyfer_.c || rm -f refclock_zyfer_.c
+refclock_rtclinux_.c: refclock_rtclinux.c $(ANSI2KNR)
+	$(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/refclock_rtclinux.c; then echo $(srcdir)/refclock_rtclinux.c; else echo refclock_rtclinux.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > refclock_rtclinuxzyfer_.c || rm -f refclock_rtclinux_.c 
 check_y2k_.$(OBJEXT) cmd_args_.$(OBJEXT) map_vme_.$(OBJEXT) \
 ntp_config_.$(OBJEXT) ntp_control_.$(OBJEXT) ntp_crypto_.$(OBJEXT) \
 ntp_filegen_.$(OBJEXT) ntp_intres_.$(OBJEXT) ntp_io_.$(OBJEXT) \
@@ -542,7 +547,8 @@
 refclock_true_.$(OBJEXT) refclock_tt560_.$(OBJEXT) \
 refclock_ulink_.$(OBJEXT) refclock_usno_.$(OBJEXT) \
 refclock_wwv_.$(OBJEXT) refclock_wwvb_.$(OBJEXT) \
-refclock_zyfer_.$(OBJEXT) : $(ANSI2KNR)
+refclock_zyfer_.$(OBJEXT) \
+refclock_rtclinux_.$(OBJEXT) : $(ANSI2KNR)
 uninstall-info-am:
 
 tags: TAGS
