On 8/15/10 7:08 AM, Kenneth R Westerback wrote:
On Sun, Aug 15, 2010 at 09:16:32AM +0200, Matthieu Herrb wrote:
On Sun, Aug 15, 2010 at 2:32 AM, Daniel Ouellet<dan...@presscom.net>  wrote:
In trying the latest snapshots on sparc64 servers, so far 3 of them all give
me the same errors. I can't use the -n flag anymore with rdate as before.

It worked on 4.7 and before. Not sure of the exact date it stop working.

Any suggestions?

Probably an aligment problem.

Try this patch:

Index: ntp.c
===================================================================
RCS file: /cvs/src/usr.sbin/rdate/ntp.c,v
retrieving revision 1.29
diff -u -r1.29 ntp.c
--- ntp.c       17 Sep 2006 17:03:56 -0000      1.29
+++ ntp.c       15 Aug 2010 07:12:11 -0000
@@ -305,7 +305,8 @@
  int
  read_packet(int fd, struct ntp_data *data, double *off, double *error)
  {
-       u_char  receive[NTP_PACKET_MAX];
+       u_int64_t receivebuf[howmany(NTP_PACKET_MAX, sizeof(u_int64_t))];
+       u_char  *receive = (u_char *)receivebuf;;
         struct  timeval tv;
         double  x, y;
         int     length, r;


--
Matthieu Herrb

There may be a similar potential issue in write_packet. Here I use
bcopy() rather than aligning the buffer on the stack. Not sure what
the preferred idiom is. This way it will continue to work if
recvck/xmitck ever become u_int128_t. :-).

.... Ken

Index: ntp.c
===================================================================
RCS file: /cvs/src/usr.sbin/rdate/ntp.c,v
retrieving revision 1.29
diff -u -p -r1.29 ntp.c
--- ntp.c       17 Sep 2006 17:03:56 -0000      1.29
+++ ntp.c       15 Aug 2010 11:01:55 -0000
@@ -280,9 +280,11 @@ write_packet(int fd, struct ntp_data *da
         * No endian concerns here.  Since we're running as a strict
         * unicast client, we don't have to worry about anyone else finding
         * the transmit field intelligible.
+        *
+        * NOTE: packet is not necessarily aligned, so a (u_int64_t *) would
+        *       be bad on aligned architectures!
         */
-
-       *(u_int64_t *)(packet + NTP_TRANSMIT) = data->xmitck;
+       bcopy(&data->xmitck, (packet + NTP_TRANSMIT), sizeof(data->xmitck));

        data->originate = current_time(JAN_1970);

@@ -423,8 +425,13 @@ unpack_ntp(struct ntp_data *data, u_char

        data->transmit = d / NTP_SCALE;

-       /* See write_packet for why this isn't an endian problem. */
-       data->recvck = *(u_int64_t *)(packet + NTP_ORIGINATE);
+       /*
+        * See write_packet for why this isn't an endian problem.
+        *
+        * NOTE: packet is not necessarily aligned, so a (u_int64_t *) would
+        *       be bad on aligned architectures!
+        */
+       bcopy((packet + NTP_ORIGINATE),&data->recvck, sizeof(data->recvck));
  }

  /*


Redoing it clean from the original and use only this one works too.

Both are good and solved the problem. Not sure witch one should be use in the end. You guys know better. I suppose the second one, but what do I know really. (;> May even be something else coming.

Let me know should you need more tests and thanks again!

Best,

Daniel

Reply via email to