sms@wlv.imsd.contel.com (Steven M. Schultz) (07/26/89)
In porting NTPD and friends I uncovered a number of problems, all related to being on a machine where sizeof (int) != sizeof (long). Using %X to print the value of ntohs(), assigning longs to ints, and inconsistent usage of the typedef u_long (for compilers w/o 'unsigned long'. With the changes below, 'ntpd', 'ntp', and 'ntpdc' work quite nicely on a PDP-11 running 2.10.1BSD Version 3.4.1.6 of NTP diff -r ntp/Makefile ntp.new/Makefile 62c62 < LDFLAGS= --- > LDFLAGS= -i 94c94 < FEATURES= -DSETTICKADJ -DDEBUG -DREFCLOCK -DLOG_NTP=LOG_LOCAL3 --- > FEATURES= -DDEBUG -DLOG_NTP=LOG_LOCAL3 96a97,99 > # for 2.10.1BSD > DEFINES= -DGENERIC_UNS_BUG -DSUN_FLT_BUG > 98c101 < DEFINES= --- > #DEFINES= diff -r ntp/ntp.c ntp.new/ntp.c 269c269 < printf("Synch Distance is %04X.%04x %f\n", --- > printf("Synch Distance is %04x.%04x %f\n", 274c274 < printf("Synch Dispersion is %04X.%04x %f\n", --- > printf("Synch Dispersion is %04x.%04x %f\n", diff -r ntp/ntp.h ntp.new/ntp.h 249c249 < int precision:8; --- > char precision; 382c382 < int precision:8; --- > char precision; 413c413,426 < --- > #ifdef pdp11 > #define double_to_s_fixed Adouble_to_s_fixed > #define adjtime2 Aadjtime2 > #define kern_tickadj Akern_tickadj > #define refclock Brefclock > #define read_clock Aread_clock > #define drift_comp Adrift_comp > #define init_clock Ainit_clock > #define stratums Astratums > #define peer_switches Apeer_switches > #define refclock_input Arefclock_input > #define read_clock_local Bread_clock_local > #define init_clock_local Binit_clock_local > #endif diff -r ntp/ntp_proto.c ntp.new/ntp_proto.c 141c141 < extern unsigned long clock_watchdog; --- > extern u_long clock_watchdog; 601c601 < delay += 1.0/(unsigned long)(1L << -sys.precision) --- > delay += 1.0/(u_long)(1L << -sys.precision) 608c608 < delay += 1.0/(unsigned long)(1L << -peer->precision); --- > delay += 1.0/(u_long)(1L << -peer->precision); 626c626 < printf("host: %s : %f : %f : %f : %f : %f : %o\n", --- > printf("host: %s : %f : %f : %f : %f : %f : %lo\n", 841c841 < ((double)rand()/(double)((unsigned long)(1L<<31) - 1)); --- > ((double)rand()/(double)((u_long)(1L<<31) - 1)); diff -r ntp/ntpd.c ntp.new/ntpd.c 151c151 < unsigned long clock_watchdog; --- > u_long clock_watchdog; 158d157 < extern double s_fixed_to_double(), ul_fixed_to_double(); 485c484 < printf("Synch Dist is %04X.%04X Synch Dispersion is %04X.%04X\n", --- > printf("Synch Dist is %04x.%04x Synch Dispersion is %04x.%04x\n", 1273c1272 < cip->reach = htons(peer->reach & NTP_WINDOW_SHIFT_MASK); --- > cip->reach = htons((u_short)peer->reach & NTP_WINDOW_SHIFT_MASK); 1359c1358 < "%+12.10f %+12.10f %+12.10f %+12.10f %+12.10f %4d\n", --- > "%12.10f %12.10f %12.10f %12.10f %12.10f %4d\n", diff -r ntp/ntpdc.c ntp.new/ntpdc.c 115a116,118 > #ifdef pdp11 > int on = 4*1024; > #else 116a120 > #endif diff -r ntp/ntpsubs.c ntp.new/ntpsubs.c 72c72 < register int i; --- > long i; 86c86 < a = (unsigned long) ntohl(t->fraction); --- > a = (u_long) ntohl(t->fraction); 91c91 < b = (unsigned long) ntohl(t->int_part); --- > b = (u_long) ntohl(t->int_part); 219c219 < int tt; --- > long tt; diff -r ntp/test.c ntp.new/test.c 100c100 < printf(" x%#8X.%#8X ", sample.int_part, sample.fraction); --- > printf(" x%8X.%8X ", sample.int_part, sample.fraction); 106c106 < printf(" x%#4X.%#4X ", s_sample.int_part, s_sample.fraction); --- > printf(" x%4x.%4x ", s_sample.int_part, s_sample.fraction); 131c131 < unsigned long ul = 0x80000001; --- > u_long ul = 0x80000001; 167c167 < int l = 1.5 * dbl; --- > long l = 1.5 * dbl; 173c173 < printf("test4: 3.0*1024.0*1024.0*1024.0 = 0x%08x\n", ul); --- > printf("test4: 3.0*1024.0*1024.0*1024.0 = 0x%08lx\n", ul);