ntpd/ntpq tangle
James Browning
jamesb192 at jamesb192.com
Tue Jul 7 12:00:30 UTC 2026
> On 07/07/2026 3:42 AM PDT Hal Murray <halmurray at sonic.net> wrote:
>
>
> In the process of chasing another bug, I noticed a bug in libntp/socktoa.c
>
> In socktoa_r
> } else {
> switch(AF(sock)) {
>
> case AF_INET:
> inet_ntop(AF_INET, PSOCK_ADDR4(sock), buf, buflen);
> break;
>
> It had AF_UNSPEC taking the AF_INET path too. So I deleted that line.
> That now takes the default path, so you get trash:
> snprintf(buf, buflen,
> "(socktoa unknown family %d)",
> AF(sock));
Ah, you caught a classic NTP bug that I don't see in their tracker.
> I haven't pushed that fix yet.
>
>
> ntpq ends up displaying DNSFAIL(xxx)
> I only see it if I look before it has done the DNS lookup on names or if
> the slot is pool slot. (Not the new ones, the "pool dns-name" slot that
> never gets an IP Address.)
>
> So I poked around with gdb a bit, and found what was causing the problem,
> and fixed it to send nothing:
> case CP_SRCADR:
> + if (AF_UNSPEC == AF(&p->srcadr))
> + break; // empty slot: pool, or no DNS yet
> ctl_putadr(CV_NAME, 0, &p->srcadr);
> break;
>
>
> Then ntpq crashes. it can't find startswith, probably because srcadr
> isn't a string.
>
> pylib/util.py" 1456L,
> elif srcadr.startswith("224."):
> ptype = 'a' # manycastclient (compatibility with
> Classic)
>
> Would you please see if you can find a good/simple fix.
>
> Thanks.
>
> I can easily hack ntp_control to return any simple fixed text string if
> that will make things simpler on your end. But maybe you should handle
> the no-srcadr case anyway.
>
> I think the old code would return "0.0.0.0"
Not so much, as it turns out. It looks like if sock is NULL,
it returns "(null)" since 2001 September 14.
OTOH, if AF_UNSPEC is the value of sock, then it didn't return
a value until 2004; in 2004 it briefly returned "unknown" before
switching back to nothing and then to "(socktoa unknown family)".
Finally, on 2009 July 16, it changed to processing like AF_INET;
at the same time, other address families changed to emitting
"(socktoa unknown family %d)".
It also looks like POOL entries should be handled before it gets
to that str.startswith conditional.
More information about the devel
mailing list