title: How to determine NTP communication status
body: <p>I'm working on an embedded OpenSUSE 12.3 system that lets the user configure the (single) NTP server address. I need to be able to give the user feedback on how things are going in terms of communicating with the specified server. Is the server address valid? Has NTP been unable to contact the server? Is it querying the server? Or, are we fully synchronized? (Note: once NTP thinks it's synchronized then I don't care just how synchronized it is.)</p>
  
  <p>Right now I've written a bash script to parse the output of <code>ntpq -np</code>:</p>
  
  <ul>
  <li>If the output contains <code>"ntpq: read: Connection refused"</code> then ntpd isn't running</li>
  <li>If the output contains <code>"No association ID's returned"</code> then the server address is invalid</li>
  <li>If the output contains <code>".INIT."</code> then ntpd hasn't yet connected to the server</li>
  <li>If the output does NOT contain a line starting with <code>"*"</code> then we're querying the server</li>
  <li>Otherwise we're synchronized.</li>
  </ul>
  
  <p>Clearly, this is a pain in the rear and highly platform-dependent, and I'd love to have a better solution.</p>
  
  <p>I understand that there's a libntpq.a inside of a built ntp source tree that can be used by external applications, but until there's an official release then that's just switching to a new flavor of platform-dependence.</p>
  
  <p>Is there an official way to determine the current communication status of an NTP client? Note again that only a single server will be configured.</p>