Home Play Pinja Bobbity flop

A blog about Ruby, Rails and other Tech. Mostly.

Back to blog

20th Aug 2003, 1:57pm
ntpdate - no server suitable for synchronization found (2)

This is an update. To recap: I found that ntpd and ntpdate will not communicate with any ntp server, giving a "no server suitable for synchronization found" message.

However, doing ntpdate -d 193.2.69.11 (for instance) works fine.

It turns out I need to use an unprivileged port with the -u option. The -d option automatically does this. So this will work:

ntpdate -u 193.2.69.11

Somewhere in my setup here port 123 is a problem. But no matter, just run ntpdate from crontab once a day (rather than ntpd) and all will be well.

Well, I got an email from Ivan Leong who had read my blog entry. And being a good fellow, he set about fixing the problem in ntpd.

From his email to me: My research shows ntpd creates and binds a fd (file descriptor) to each and every network interface (including 0.0.0.0 and 127.0.0.1) to port 123.

Since it is UDP, all I've to do is to prevent the "bind" statement in ntp_io.c for public IP, but keep the "bind" for i/f 0.0.0.0 and 127.0.0.1.

When ntpd contacts my peers, it uses the public i/f, and the fd that is _not_ bound. When I use ntpq to query my ntpd, ntpq connects to port 123 and my ntpd responds bec the fd on i/f 127.0.0.1 _is_ bound.

This is his patch:


--- ntpd/ntp_io.c.org   2003-04-04 05:31:15.000000000 +0800
+++ ntpd/ntp_io.c       2003-04-04 05:31:36.000000000 +0800
@@ -917,6 +917,11 @@
        /*
         * bind the local address.
         */
+if (
+((addr->sin_addr.s_addr & 0xffffffff)==0) ||
+((addr->sin_addr.s_addr & 0xffffffff)==0x100007f) ||
+((addr->sin_addr.s_addr & 0xffff)==0xa8c0)
+) {
        if (bind(fd, (struct sockaddr *)addr, sizeof(*addr)) < 0) {
                char buff[160];
                sprintf(buff,
@@ -938,6 +943,7 @@
                return -1;
 #endif
        }
+}
 #ifdef DEBUG
        if (debug)
            printf("bind() fd %d, family %d, port %d, addr %s, flags=%d\n",


Back to blog