BitKeeper file /geom_mobile/home/Amidamaru/projects/sntp/repo/ntp-dev/gsoc_sntp/utilities.h
Makefile.am:
Added sntp-opts.c to sources
+ minor fixes
main.c:
on_wire, timesetting stuff etc.
log.c, kod_management.c:
Bug fixes
utilities.o:
BitKeeper file /geom_mobile/home/Amidamaru/projects/sntp/repo/ntp-dev/gsoc_sntp/utilities.o
utilities.c:
BitKeeper file /geom_mobile/home/Amidamaru/projects/sntp/repo/ntp-dev/gsoc_sntp/utilities.c
sntp-opts.def:
fixed arg-type stuff
bk: 48a5f808IuFfNCcjV4Pp9DdbpS4g6g
AUTOMAKE_OPTIONS = foreign
ACLOCAL_AMFLAGS= -I libopts/m4
-AM_CPPFLAGS= $(LIBOPTS_CFLAGS) -I$(top_srcdir)/../include/
-LDADD= $(LIBOPTS_LDADD)
+AM_CPPFLAGS= $(LIBOPTS_CFLAGS) -I$(top_srcdir)/../include/ -Wall
+LDADD= $(LIBOPTS_LDADD) -lm ../libntp/libntp.a
NULL=
sntp_SOURCES = \
networking.c \
+ kod_management.c \
+ log.c \
+ utilities.c \
+ sntp-opts.c \
main.c \
$(NULL)
char *search_str
)
{
- struct kod_entry **dummy;
+ struct kod_entry **dummy = NULL;
- return search_entry(search_str, dummy);
+ if(dummy == NULL)
+ return 0;
+
+ else
+ return 1;
}
void
int scan_value = 0;
while(!feof(db_s)) {
- printf("%s", fgets(fbuf, 272, db_s));
+ fgets(fbuf, 272, db_s);
+
int sepc = 0;
for(a=0; a<strlen(fbuf); a++) {
if(fbuf[a] == ':')
error = 1;
}
else {
-#ifdef DEBUG
- printf("KOD entry %i %i: %s at %i type %s\n", a, b, kod_db[b].hostname,
- kod_db[b].timestamp, kod_db[b].type);
-#endif
if(b > 0)
kod_db[b-1].next = &kod_db[b];
}
printf("KOD entry %i: %s at %i type %s\n", a, kod_db[a].hostname,
kod_db[a].timestamp, kod_db[a].type);
+ printf("\n");
#endif
if(ferror(db_s) || error) {
struct kod_entry {
char hostname[255];
unsigned int timestamp;
- char type[4];
+ char type[5];
struct kod_entry *next;
};
int search_entry (char *hostname, struct kod_entry **dst);
+int kod_entry_exists (char *search_str);
void add_entry (char *hostname, char *type);
void delete_entry (char *hostname, char *type);
void log_msg(char *message, char type) {
- if(filelog) {
- if(init) {
- fprintf(log_file, message);
- }
- else {
- fprintf(stderr, "Error: Log not initialized!\n");
- }
+ if(init) {
+ printf("log!\n");
+ printf(log_file, message);
}
else {
+ printf("ELSEZWEIG!!!!! HAAAAAARRRRRRRRRRRRRRRRRG!\n");
switch(type) {
case 0:
- type = LOG_DEBUG;
+ type = LOG_CONS;
break;
case 1:
- type = LOG_WARNING;
+ type = LOG_DEBUG | LOG_CONS;
break;
case 2:
}
void debug_msg(char *message) {
- if(filelog) {
+ if(HAVE_OPT(FILELOG)) {
fprintf(stderr, message);
+ fprintf(stderr, "\n");
}
else {
- syslog(LOG_DEBUG | LOG_PERROR, message);
+ syslog(LOG_DEBUG | LOG_PERROR | LOG_CONS, message);
}
}
void init_log(char *logfile) {
+ printf("INIT IST KRIEEEEEG %s!!!\n", logfile);
log_file = fopen(logfile, "a");
if(log_file == NULL) {
void log_msg(char *message, char type);
void debug_msg(char *message);
-char init = 0;
-FILE *log_file;
-
void init_log(char *logfile);
void cleanup_log(void);
-#if 0
-#include <stdio.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netdb.h>
-#endif
-
+#include <ntp_fp.h>
+#include <ntp.h>
#include <ntp_stdlib.h>
#include <ntp_unixtime.h>
#include <l_stdlib.h>
#include <sntp-opts.h>
+#include "kod_management.h"
#include "networking.h"
-/*#include "header.h"*/
-
-#define NTP_PORT 123
+#include "utilities.h"
+#include "log.h"
#define DEBUG
int ai_fam_templ;
volatile int debug;
+char adr_buf[INET6_ADDRSTRLEN];
+
+
+void set_li_vn_mode (struct pkt *spkt, char leap, char version, char mode);
+int sntp_main (int argc, char **argv);
+int on_wire (struct addrinfo *host);
+void set_li_vn_mode (struct pkt *spkt, char leap, char version, char mode);
+int set_time (double offset);
-/* tOptions sntpOptions; */
int
char *kod_file, *log_file;
register int c;
-#ifdef DEBUG
- printf("Starting %s with %i arguments...\n", argv[0], argc);
-#endif
-
if (isc_net_probeipv6() != ISC_R_SUCCESS) {
ai_fam_templ = AF_INET;
#ifdef DEBUG
#ifndef NO_DISK
#endif
+ log_msg("Started sntp", 0);
int optct = optionProcess(&sntpOptions, argc, argv);
argc -= optct;
argv += optct;
- for(c=0; c<argc; c++)
- printf("%s\n", argv[c]);
-
-
/* Parse config file if declared TODO */
/* Initialize logging system */
kod_init_kod_db(OPT_ARG(KOD));
}
- kod_init_kod_db("test.kod");
-
-
/* Considering employing a variable that prevents functions of doing anything until
* everything is initialized properly
*/
int sync_data_suc = 0;
for(c=0; c<resc && !sync_data_suc; c++) {
- if(!kod_entry_exists(inet_ntoa(resh[c]->ai_addr))) {
+ getnameinfo(resh[c]->ai_addr, resh[c]->ai_addrlen, adr_buf,
+ INET6_ADDRSTRLEN, NULL, 0, NI_NUMERICHOST);
+
+ if(!kod_entry_exists(adr_buf) &&
+ is_reachable(resh[c])) {
int ow_ret = on_wire(resh[c]);
- sync_data_suc = 1;
+ if(ow_ret < 0) {
+ printf("on_wire failed!\n");
+ }
+ else {
+ sync_data_suc = 1;
+ }
}
else {
struct kod_entry **reason;
int kodc = search_entry(resh[c], reason);
- printf("KoD package exists for %s, stopping any further communication.", inet_ntoa(resh[c]->ai_addr));
+ printf("KoD package exists for %s, stopping any further communication.\n",
+ adr_buf);
}
+
+ freeaddrinfo(resh[c]);
}
return 0;
struct addrinfo *host
)
{
+ register int try;
SOCKET sock;
+
+ for(try=0; try<5; try++) {
+ struct pkt *x_pkt = (struct pkt *) malloc(sizeof(struct pkt));
+ struct pkt *r_pkt = (struct pkt *) malloc(sizeof(struct pkt));
+
+ struct timeval tv_org, tv_dst;
+
+ double t21, t34, delta, offset;
- struct pkt *x_pkt = (struct pkt *) malloc(sizeof(struct pkt));
- struct pkt *r_pkt = (struct pkt *) malloc(sizeof(struct pkt));
+ int error, rsock, rpktl;
- struct timeval tv_t1, tv_t2;
- struct timezone tz;
- l_fp t1, t4;
+ l_fp p_rec, p_xmt, p_ref, p_org, org, tmp, dst, theta;
- int error = GETTIMEOFDAY(&tv_t1, &tz);
+
+ error = GETTIMEOFDAY(&tv_org, (struct timezone *)NULL);
#ifdef DEBUG
- printf("tv_t1 sec: %i msec: %i\n", tv_t1.tv_sec, tv_t1.tv_usec);
+ printf("Current time sec: %i msec: %i\n\n", tv_org.tv_sec, tv_org.tv_usec);
#endif
- TVTOTS(&tv_t1, &(x_pkt->org));
+ tv_org.tv_sec += JAN_1970;
+ TVTOTS(&tv_org, &org);
+ HTONL_FP(&org, &(x_pkt->org));
+
+ x_pkt->stratum = STRATUM_TO_PKT(STRATUM_UNSPEC);
+ x_pkt->ppoll = 8;
+ /* FIXME! Modus broadcast + adr. check -> bdr. pkt */
+ set_li_vn_mode(x_pkt, LEAP_NOTINSYNC, 4, 3);
-/* Data from a valid timestamp */
-/* unsigned char *tptr = &(x_pkt->org);
- tptr[0] = 0xcc;
- tptr[1] = 0x44;
- tptr[2] = 0x87;
- tptr[3] = 0x45;*/
+
+ create_socket(&sock, (struct sockaddr_storage *)host->ai_addr);
- x_pkt->stratum = 15;
- x_pkt->ppoll = 8;
- x_pkt->li_vn_mode = 0x1b;
+ rsock = sendpkt(sock, host->ai_addr, x_pkt, LEN_PKT_NOMAC);
+ rpktl = recvpkt(sock, r_pkt, x_pkt);
+ close_socket(sock);
+
+ if(rpktl == -1)
+ return -1;
+
+ /* -2 would indicate that we should try to get a packet
+ * from this server again
+ */
+ if(rpktl != -2) {
+ NTOHL_FP(&r_pkt->reftime, &p_ref);
+ NTOHL_FP(&r_pkt->org, &p_org);
+ NTOHL_FP(&r_pkt->rec, &p_rec);
+ NTOHL_FP(&r_pkt->xmt, &p_xmt);
+
+ if(ENABLED_OPT(NORMALVERBOSE)) {
+ getnameinfo(host->ai_addr, host->ai_addrlen, adr_buf,
+ INET6_ADDRSTRLEN, NULL, 0, NI_NUMERICHOST);
+
+ printf("\non_wire: Received %i bytes from %s\n", rpktl, adr_buf);
+ }
+
+#ifdef DEBUG
+ pkt_output(r_pkt, rpktl, stdout);
+
+ printf("on_wire: rpkt->reftime:\n");
+ l_fp_output(&(r_pkt->reftime), stdout);
+ printf("on_wire: rpkt->org:\n");
+ l_fp_output(&(r_pkt->org), stdout);
+ printf("on_wire: rpkt->rec:\n");
+ l_fp_output(&(r_pkt->rec), stdout);
+ printf("on_wire: rpkt->rec:\n");
+ l_fp_output_bin(&(r_pkt->rec), stdout);
+ printf("on_wire: rpkt->rec:\n");
+ l_fp_output_dec(&(r_pkt->rec), stdout);
+ printf("on_wire: rpkt->xmt:\n");
+ l_fp_output(&(r_pkt->xmt), stdout);
+#endif
+ GETTIMEOFDAY(&tv_dst, (struct timezone *)NULL);
- /*in_addr_t foo = inet_addr("127.0.0.1"); */
- create_socket(&sock, host->ai_addr);
+ tmp = p_rec;
+ L_SUB(&tmp, &p_org);
- int rsock = sendpkt(sock, host->ai_addr, x_pkt, 48);
+ LFPTOD(&tmp, t21);
- int rpktl = recvpkt(sock, r_pkt, x_pkt);
+ TVTOTS(&tv_dst, &dst);
- close_socket(sock);
+ tmp = dst;
+ L_SUB(&tmp, &p_xmt);
- NTOHL_FP(&(r_pkt->rec), &(r_pkt->rec));
- TSTOTV(&(r_pkt->rec), &tv_t2);
+ LFPTOD(&tmp, t34);
- double time = 0.0;
+ offset = (t21 + t34) / 2.;
+ delta = t21 - t34;
- LFPTOD(&(r_pkt->rec), time);
- printf("\nrec: %d\n", time);
+ if(ENABLED_OPT(NORMALVERBOSE))
+ printf("on_wire: t21: %.6f\t t34: %.6f\ndelta: %.6f\t offset: %.6f\n",
+ t21, t34, delta, offset);
+ set_time(offset);
+ return 0;
+ }
+ }
- return 0;
-}
+ char logmsg[32 + INET6_ADDRSTRLEN];
+ getnameinfo(host->ai_addr, host->ai_addrlen, adr_buf, INET6_ADDRSTRLEN, NULL, 0, NI_NUMERICHOST);
+ snprintf(logmsg, 32 + INET6_ADDRSTRLEN, "Received no useable packet from %s!", adr_buf);
+ if(ENABLED_OPT(NORMALVERBOSE))
+ printf("on_wire: Received no useable packet from %s!\n", adr_buf);
+ log_msg(logmsg, 1);
+ return -1;
+}
+void
+set_li_vn_mode (
+ struct pkt *spkt,
+ char leap,
+ char version,
+ char mode
+ )
+{
+ if(leap > 3) {
+ debug_msg("set_li_vn_mode: leap > 3 using max. 3");
+ leap = 3;
+ }
+ if(mode > 7) {
+ debug_msg("set_li_vn_mode: mode > 7, using client mode 3");
+ mode = 3;
+ }
-
+ spkt->li_vn_mode = leap << 6;
+ spkt->li_vn_mode |= version << 3;
+ spkt->li_vn_mode |= mode;
+}
+
+int
+set_time (
+ double offset
+ )
+{
+ struct timeval tp;
+ if(ENABLED_OPT(SETTOD)) {
+ GETTIMEOFDAY(&tp, (struct timezone *)NULL);
+ tp.tv_sec += (int) offset;
+ tp.tv_usec += offset - (double)((int)offset);
+ if(SETTIMEOFDAY(&tp, (struct timezone *)NULL) < 0) {
+ if(errno == EPERM)
+ printf("set_time: You don't have enough priviledges to call settimeofday(), cannot set time!\n");
+ else
+ printf("set_time: settimeofday() returned with an error, couldn't set time!\n");
+
+ return -1;
+ }
+ else {
+ return 0;
+ }
+ }
+ else {
+ tp.tv_sec = (int) offset;
+ tp.tv_usec = offset - (double)((int)offset);
+
+ if(ADJTIMEOFDAY(&tp, NULL) < 0) {
+ if(errno == EPERM)
+ printf("set_time: You don't have enough priviledges to call adjtime(), cannot set time!\n");
+ else
+ printf("set_time: adjtime() returned with an error, couldn't set time!\n");
+
+ return -1;
+ }
+ else {
+ return 0;
+ }
+ }
+
+
+}
#include <config.h>
-/* #include "sntp-opts.h" /**/
+#include "sntp-opts.h"
#include "networking.h"
#include "header.h"
+#include "utilities.h"
#include "log.h"
-#ifdef DEBUG
-#define WS80 do { \
- register int wsc; \
- for(wsc=0; wsc<80; wsc++) \
- printf("-"); \
- printf("\n"); \
-} while(0);
-#endif
-
-
+char adr_buf[INET6_ADDRSTRLEN];
int
register unsigned int a, b;
unsigned int entryc = 0;
- /* res = (struct addrinfo **) malloc(sizeof(struct addrinfo) * (hostc + 1)); */
-
if(hostc < 1)
return 0;
for(dres=*tres[a]; dres; dres=dres->ai_next) {
entryc++;
#ifdef DEBUG
- WS80
+ getnameinfo(dres->ai_addr, dres->ai_addrlen, adr_buf, INET6_ADDRSTRLEN, NULL, 0, NI_NUMERICHOST);
+ STDLINE
printf("Resolv No.: %i Result of getaddrinfo for %s:\n", entryc, hosts[a]);
printf("socktype: %i ", dres->ai_socktype);
printf("protocol: %i ", dres->ai_protocol);
- printf("Prefered socktype: %i IP: %s\n", dres->ai_socktype, inet_ntoa(dres->ai_addr));
- WS80
- printf("\n");
+ printf("Prefered socktype: %i IP: %s\n", dres->ai_socktype, adr_buf);
+ STDLINE
#endif
}
}
#ifdef DEBUG
for(a=0; a<entryc; a++)
- printf("%x: IP %s\n", result[a], inet_ntoa(result[a]->ai_addr));
+ getnameinfo(result[a]->ai_addr, result[a]->ai_addrlen, adr_buf, INET6_ADDRSTRLEN, NULL, 0, NI_NUMERICHOST);
+
+ printf("%x: IP %s\n", result[a], adr_buf);
#endif
*res = (struct addrinfo *) malloc(sizeof(struct addrinfo *) * entryc);
void
create_socket (
SOCKET *rsock,
- struct sockaddr *dest
+ struct sockaddr_storage *dest
)
{
- *rsock = socket(dest->sa_family, SOCK_DGRAM, 0);
+ *rsock = socket(dest->ss_family, SOCK_DGRAM, 0);
#ifdef DEBUG
if(*rsock == -1)
- printf("Failed to create UDP socket with family %i\n", dest->sa_family);
+ printf("Failed to create UDP socket with family %i\n", dest->ss_family);
#endif
-
-/* int error = bind(*rsock, dest, SOCKLEN(dest));
-
- if(error != 0) {
- *rsock = -1;
-#ifdef DEBUG
- printf("Failed to bind %i %i socket to address %s\n", error, errno, inet_ntoa(dest));
-#endif
- } */
}
void
void
sendpkt (
SOCKET rsock,
- struct sockaddr *dest,
+ struct sockaddr_storage *dest,
struct pkt *pkt,
int len
)
{
#ifdef DEBUG
- register int a;
-
- unsigned char *cpy = (unsigned char *) malloc(sizeof(char) * len);
-
- for(a=0; a<len; a++)
- cpy[a] = ((unsigned char *) pkt)[a];
-
- for(a=0; a<len; a++) {
- if(a > 0 && a%8 == 0)
- printf("\n");
-
- printf("%x: %x \t", a, cpy[a]);
- }
-
+ pkt_output(pkt, len, stdout);
+ getnameinfo((struct sockaddr *) dest, dest->ss_len, adr_buf, INET6_ADDRSTRLEN, NULL, 0, NI_NUMERICHOST);
- printf("\nSending packet to %s...\n", inet_ntoa(dest));
+ printf("\nSending packet to %s...\n", adr_buf);
#endif
- int cc = sendto(rsock, (char *)pkt, len, 0, dest,
- SOCKLEN(dest));
+ int cc = sendto(rsock, (char *)pkt, len, 0, (struct sockaddr *)dest, dest->ss_len);
if (cc == SOCKET_ERROR) {
#ifdef DEBUG
int
recvdata (
SOCKET rsock,
- struct sockaddr *sender,
+ struct sockaddr_storage *sender,
char *rdata,
size_t rdata_length,
char *done
#endif
int recvc = recvfrom(rsock, rdata, rdata_length, 0,
- sender, &slen);
+ (struct sockaddr *) sender, &slen);
#ifdef DEBUG
printf("recvfrom returned...\n");
#endif
register int a;
if(recvc > 0) {
- printf("Received %i bytes from %s:\n", recvc, inet_ntoa(sender));
+ getnameinfo((struct sockaddr *)sender, sender->ss_len, adr_buf, INET6_ADDRSTRLEN, NULL, 0, NI_NUMERICHOST);
- unsigned char *cpy = (unsigned char *) malloc(sizeof(char) * recvc);
-
- for(a=0; a<recvc; a++)
- cpy[a] = ((unsigned char *) rdata)[a];
+ printf("Received %i bytes from %s:\n", recvc, adr_buf);
- for(a=0; a<recvc; a++) {
- if(a > 0 && a%8 == 0)
- printf("\n");
-
- printf("%i: %x \t", a, cpy[a]);
- }
+ pkt_output((struct pkt *) rdata, recvc, stdout);
}
else {
printf("Failure, recvc: %i\n", recvc);
}
/* Fetch data, check if it's data for us and whether it's useable or not. If not, return -1
- * so we can delete this server from our list and continue with another one. KOD package handling
- * is not done here.
+ * so we can delete this server from our list and continue with another one.
*/
int
recvpkt (
struct pkt *spkt
)
{
+ register int a;
int has_mac;
int is_authentic;
l_fp ci;
- struct sockaddr sender;
+ struct sockaddr_storage sender;
char *rdata, done;
/* Much space, just to be sure */
has_mac = 0;
else if(pkt_length > LEN_PKT_NOMAC)
- has_mac = 1;
+ has_mac = pkt_length - LEN_PKT_NOMAC;
else
if(debug) {
return -1;
}
- rpkt = (struct pkt *)rdata;
+ if(has_mac) {
+ if(has_mac > MAX_MAC_LEN || has_mac % 4 != 0) {
+ return -1;
+ }
+ /* Do auth stuff */
+ }
+
+ /*struct pkt *tmp_rpkt = (struct pkt *)rdata;
+ rpkt->li_vn_mode = tmp_rpkt->li_vn_mode;
+ rpkt->stratum = tmp_rpkt->stratum;
+ rpkt->ppoll = tmp_rpkt->ppoll;
+ rpkt->precision = tmp_rpkt->precision;
+ rpkt->rootdelay = tmp_rpkt->rootdelay;
+ rpkt->rootdisp = tmp_rpkt->rootdisp;
+ rpkt->refid = tmp_rpkt->refid;
+ rpkt->reftime = tmp_rpkt->reftime;
+ rpkt->org = tmp_rpkt->org;
+ rpkt->rec = tmp_rpkt->rec;
+ rpkt->xmt = tmp_rpkt->xmt; */
+
+ if(pkt_length > LEN_PKT_MAC) {
+ if(ENABLED_OPT(NORMALVERBOSE))
+ printf("sntp recvpkt: Received packet is too big (%i bytes), trying again to get a useable packet\n",
+ pkt_length);
+
+ return -2;
+ }
+
+ for(a=0; a<pkt_length; a++)
+ ((unsigned char *) rpkt)[a] = rdata[a];
+ printf("%x %x\n", PKT_VERSION(rpkt->li_vn_mode), NTP_OLDVERSION);
if (PKT_VERSION(rpkt->li_vn_mode) < NTP_OLDVERSION ||
PKT_VERSION(rpkt->li_vn_mode) > NTP_VERSION) {
return -1;
- }
+ }
- if ((PKT_MODE(rpkt->li_vn_mode) != MODE_SERVER
- && PKT_MODE(rpkt->li_vn_mode) != MODE_PASSIVE)
- || rpkt->stratum >= STRATUM_UNSPEC) {
+ if (PKT_MODE(rpkt->li_vn_mode) != MODE_SERVER
+ && PKT_MODE(rpkt->li_vn_mode) != MODE_PASSIVE) {
#ifdef DEBUG
- printf("receive: mode %d stratum %d\n",
+ printf("sntp recvpkt: mode %d stratum %i\n",
PKT_MODE(rpkt->li_vn_mode), rpkt->stratum);
#endif
return -1;
}
+ if(rpkt->stratum == STRATUM_PKT_UNSPEC) {
+ if(ENABLED_OPT(NORMALVERBOSE))
+ printf("sntp recvpkt: Unusable packet, discarding. (stratum: %i)\n", rpkt->stratum);
+
+ return -1;
+ }
+
+ if(PKT_LEAP(rpkt->li_vn_mode) == LEAP_NOTINSYNC) {
+ if(ENABLED_OPT(NORMALVERBOSE))
+ printf("sntp recvpkt: Server not in sync, skipping this server\n");
+
+ return -1;
+ }
+
+
/*
* Decode the org timestamp and make sure we're getting a response
* to our last request.
return -1;
}
- /* Do authentication stuff here */
/* Left for now, finishin other stuff. I think I might want that somewhere else,
* don't want this function to do on-wire tasks. Sanity checks are right here I think
SOCKET sockfd;
sockfd = socket(dst->ai_family, SOCK_DGRAM, 0);
+
if (sockfd == -1) {
+#ifdef DEBUG
+ printf("is_reachable: Couldn't create socket\n");
+#endif
return 0;
}
closesocket(sockfd);
return 0;
}
+
closesocket(sockfd);
return 1;
}
#include <ntp_stdlib.h>
#include "data_formats.h"
-
/* FIXME, see portability issue 1 */ /* irrelevant for now */
#ifndef SYS_WINNT
#define SOCKET int
int resolve_hosts (char **hosts, int hostc, struct addrinfo **res);
-/* From ntpdate.c */
-void send_pkt (struct sockaddr_storage *dest, struct pkt *pkt, int len);
+void create_socket (SOCKET *rsock, struct sockaddr_storage *dest);
+
+void close_socket (SOCKET rsock);
+
+void send_pkt (SOCKET rsock, struct sockaddr_storage *dest, struct pkt *pkt, int len);
-int recvdata (SOCKET rsock, struct sockaddr *sender, char *rdata, size_t rdata_length, char *done);
+int recvdata (SOCKET rsock, struct sockaddr_storage *sender, char *rdata, size_t rdata_length, char *done);
int recvpkt (SOCKET rsock, struct pkt *rpkt, struct pkt *spkt);
#include autogen-version.def
+prog-name = "sntp";
+prog-title = "standard SNTP program";
+homerc = $HOME, ".";
+argument = '...';
+
copyright = {
date = "2008";
owner = "ntp.org";
};
-prog-name = "sntp";
-prog-title = "standard SNTP program";
-homerc = $HOME, ".";
long-opts;
config-header = "config.h";
flag = {
name = debug;
value = d;
+ ifdef = DEBUG;
descrip = "Debugging output";
doc = <<- _EndOfDoc_
Very verbose debugging output that will interfere with the timing
flag = {
name = kod;
value = k;
+ arg-type = string;
descrip = "Specify a file for the KOD packet storage";
doc = <<- _EndOfDoc_
Specifies the file to be used to store KOD packaet information.
flag = {
name = filelog;
value = l;
+ arg-type = string;
flags-cant = syslog;
descrip = "Logging to specified logfile";
doc = <<- _EndOfDoc_
};
flag = {
- name = settimeofday;
+ name = settod;
value = r;
flags-cant = adjtime;
descrip = "Set (step) the time with settimeofday()";
flag = {
name = adjtime;
value = a;
- flags-cant = settimeofday;
+ flags-cant = settod;
descrip = "Set (slew) the time with adjtime()";
doc = <<- _EndOfDoc_
_EndOfDoc_;
};
+flag = {
+ name = hostlist;
+ value = h;
+ descrip = "Specify a list of ntp servers";
+ doc = <<- _EndOfDoc_
+ Comma seperated list of ntp server hosts like
+ \"time.foo.org,time.bar.org,time.baz.org\"
+ _EndOfDoc_;
+};
+
detail = <<- _END_DETAIL
.I sntp
can be used as a SNTP client to query a NTP or SNTP server and either display
.TP
.B \-r
indicates that the system clock should be reset by
-.IR settimeofday .
+.IR settod .
Naturally, this will work only if the user has enough privilege.
.TP
.B \-a
--- /dev/null
+#include "utilities.h"
+
+void
+pkt_output (
+ struct pkt *dpkg,
+ int pkt_length,
+ FILE *output
+ )
+{
+ register int a;
+
+ unsigned char *cpy = (unsigned char *) malloc(sizeof(char) * pkt_length);
+
+ for(a=0; a<pkt_length; a++)
+ cpy[a] = ((unsigned char *) dpkg)[a];
+
+
+ fprintf(output, HLINE);
+
+ for(a=0; a<pkt_length; a++) {
+ if(a > 0 && a%8 == 0)
+ fprintf(output, "\n");
+
+ fprintf(output, "%i: %x \t", a, cpy[a]);
+ }
+
+ fprintf(output, "\n");
+ fprintf(output, HLINE);
+}
+
+void
+l_fp_output (
+ l_fp *ts,
+ FILE *output
+ )
+{
+ register int a;
+
+ fprintf(output, HLINE);
+
+ for(a=0; a<8; a++)
+ fprintf(output, "%i: %x \t", a, ((unsigned char *) ts)[a]);
+
+ fprintf(output, "\n");
+ fprintf(output, HLINE);
+
+}
+
+void
+l_fp_output_bin (
+ l_fp *ts,
+ FILE *output
+ )
+{
+ register int a, b, bexp;
+
+ fprintf(output, HLINE);
+
+ for(a=0; a<8; a++) {
+ short tmp = ((unsigned char *) ts)[a];
+ tmp++;
+
+ fprintf(output, "%i: ", a);
+
+ for(b=7; b>=0; b--) {
+ int texp = (int) pow(2, b);
+
+ if(tmp - texp > 0) {
+ fprintf(output, "1");
+ tmp -= texp;
+ }
+ else {
+ fprintf(output, "0");
+ }
+ }
+
+ fprintf(output, " ");
+ }
+
+ fprintf(output, "\n");
+ fprintf(output, HLINE);
+}
+
+void
+l_fp_output_dec (
+ l_fp *ts,
+ FILE *output
+ )
+{
+ register int a;
+
+ fprintf(output, HLINE);
+
+ for(a=0; a<8; a++)
+ fprintf(output, "%i: %i \t", a, ((unsigned char *) ts)[a]);
+
+ fprintf(output, "\n");
+ fprintf(output, HLINE);
+
+}
+
--- /dev/null
+#ifndef UTILITIES_H
+#define UTILITIES_H
+
+#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <ntp_fp.h>
+#include <ntp.h>
+
+#define HLINE "--------------------------------------------------------------------------------\n"
+#define PHLINE fprintf(output, HLINE);
+#define STDLINE printf(HLINE);
+
+
+void pkt_output (struct pkt *dpkg, int pkt_length, FILE *output);
+void l_fp_output (l_fp *ts, FILE *output);
+void l_fp_output_bin (l_fp *ts, FILE *output);
+void l_fp_output_dec (l_fp *ts, FILE *output);
+
+
+#endif