Quantcast
Channel: openSUSE Forums
Viewing all articles
Browse latest Browse all 40713

It's about time, my first c++ program

$
0
0
Wrote my first c++ program. Though it doesn't answer the question I had, it does provide some nice information.

Here is the code:
Code:

/** Project Name: ntp_project
* Written By: sparkz_alot
* Date: 19 Jun 2014
* Version: 1.0.0
*
* Description: a simple c++11 program to provide information about the Network Time Protocol (ntp) using the
* ntpq and ntpdc query commands.
*
* Written using Code::Blocks v13.12 IDE and tested on openSUSE 13.1.
*/
#include <iostream>


using namespace std;


int main()


{
    cout << "The results of the ntpq -pn (-p: list of peers known to server \n";
    cout << "-n: use numerical rather than canonical name) and a straight system call \n";
    cout << endl;
    system("ntpq -pn");
    cout << endl;
    // or using popen. Note: 'type' is r(read) or w(write), cant't be both
    cout << "Output using popen and ntpq\n";
    FILE *pipe_fp;
    char buff[512];
    // Open pipe and check for errors
    if ((pipe_fp = popen("ntpq -pn" , "r")) == NULL)
        {
            perror("popen");
            exit(1);
        }
    while(fgets(buff, sizeof(buff), pipe_fp)!=NULL)
    {
        cout << buff;
    }
    // Close the pipe
    pclose(pipe_fp);
    cout << endl;
    // Now lets get some info about the server we are currently syncing to
    cout << "Getting system info of current ntp server using ntpdc -sysinfo \n";
    cout << endl;
    if ((pipe_fp = popen("ntpdc -c sysinfo" , "r")) == NULL)
        {
            perror("popen");
            exit(1);
        }
    while(fgets(buff, sizeof(buff), pipe_fp)!=NULL)
    {
        cout << buff;
    }
    // Close the pipe
    pclose(pipe_fp);
    cout << endl;
    // Say good night Gracie
    cout << "\a tata" << endl;


    return 0;
}

And here is the output:

Code:

The results of the ntpq -pn (-p: list of peers known to server -n: use numerical rather than canonical name) and a straight system call


    remote          refid      st t when poll reach  delay  offset  jitter
==============================================================================
-4.53.160.75    64.113.32.5      2 u  675 1024  377  57.563  -9.733  3.646
+50.7.64.4      206.108.0.132    2 u  370 1024  377  48.876  -0.282  2.890
*66.228.59.187  200.98.196.212  2 u  678 1024  367  26.619  -2.186  1.712
+66.7.96.1      140.142.16.34    2 u  613 1024  377  116.687  -8.288  2.773


Output using popen and ntpq
    remote          refid      st t when poll reach  delay  offset  jitter
==============================================================================
-4.53.160.75    64.113.32.5      2 u  675 1024  377  57.563  -9.733  3.646
+50.7.64.4      206.108.0.132    2 u  370 1024  377  48.876  -0.282  2.890
*66.228.59.187  200.98.196.212  2 u  678 1024  367  26.619  -2.186  1.712
+66.7.96.1      140.142.16.34    2 u  613 1024  377  116.687  -8.288  2.773


Getting system info of current ntp server using ntpdc -sysinfo


system peer:          fairy.mattnordhoff.net
system peer mode:    client
leap indicator:      00
stratum:              3
precision:            -22
root distance:        0.05386 s
root dispersion:      0.10902 s
reference ID:        [66.228.59.187]
reference time:      d74d8d32.6dcf68bd  Thu, Jun 19 2014 12:24:18.428
system flags:        auth monitor ntp kernel stats
jitter:              0.005585 s
stability:            0.000 ppm
broadcastdelay:      0.000000 s
authdelay:            0.000000 s


 tata


Viewing all articles
Browse latest Browse all 40713

Trending Articles