]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
log.h, log.c:
authorJohannes Maximilian Kuehn <kuehn@ntp.org>
Tue, 22 Jul 2008 18:52:14 +0000 (03:52 +0900)
committerJohannes Maximilian Kuehn <kuehn@ntp.org>
Tue, 22 Jul 2008 18:52:14 +0000 (03:52 +0900)
  Changed name of debug output function to avoid name collision with opt flag variable
kod_management.c:
  Changed from fgets to fscanf (easier data extraction)

bk: 48862c5eW1GYMr0q-evEaH8KVflhxw

gsoc_sntp/Makefile
gsoc_sntp/Makefile.in
gsoc_sntp/kod_management.c
gsoc_sntp/kod_management.h
gsoc_sntp/log.c
gsoc_sntp/log.h
gsoc_sntp/networking.c
gsoc_sntp/networking.h

index e442e6c551cd03de63d6432ce250ec7c4ead501a..b8cf2e5ca96aa7e636f583e8cbd49e52fca9b0f9 100644 (file)
@@ -41,13 +41,10 @@ POST_UNINSTALL = :
 build_triplet = i386-unknown-freebsd7.0
 host_triplet = i386-unknown-freebsd7.0
 bin_PROGRAMS = sntp$(EXEEXT)
-DIST_COMMON = $(am__configure_deps) $(srcdir)/../config.guess \
-       $(srcdir)/../config.sub $(srcdir)/../depcomp \
-       $(srcdir)/../install-sh $(srcdir)/../ltmain.sh \
-       $(srcdir)/../missing $(srcdir)/Makefile.am \
+DIST_COMMON = $(am__configure_deps) $(srcdir)/Makefile.am \
        $(srcdir)/Makefile.in $(srcdir)/bincheck.mf \
        $(srcdir)/config.h.in $(top_srcdir)/configure config.guess \
-       config.sub
+       config.sub depcomp install-sh ltmain.sh missing
 subdir = .
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
 am__aclocal_m4_deps = $(top_srcdir)/configure.ac
@@ -67,7 +64,7 @@ sntp_OBJECTS = $(am_sntp_OBJECTS)
 sntp_LDADD = $(LDADD)
 sntp_DEPENDENCIES =
 DEFAULT_INCLUDES = -I.
-depcomp = $(SHELL) $(top_srcdir)/../depcomp
+depcomp = $(SHELL) $(top_srcdir)/depcomp
 am__depfiles_maybe = depfiles
 COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
        $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
@@ -93,12 +90,12 @@ DIST_ARCHIVES = $(distdir).tar.gz
 GZIP_ENV = --best
 distuninstallcheck_listfiles = find . -type f -print
 distcleancheck_listfiles = find . -type f -print
-ACLOCAL = ${SHELL} /home/Amidamaru/projects/sntp/dev/missing --run aclocal-1.10
-AMTAR = ${SHELL} /home/Amidamaru/projects/sntp/dev/missing --run tar
+ACLOCAL = ${SHELL} /geom_mobile/home/Amidamaru/projects/sntp/repo/gsoc_sntp/missing --run aclocal-1.10
+AMTAR = ${SHELL} /geom_mobile/home/Amidamaru/projects/sntp/repo/gsoc_sntp/missing --run tar
 AR = ar
-AUTOCONF = ${SHELL} /home/Amidamaru/projects/sntp/dev/missing --run autoconf
-AUTOHEADER = ${SHELL} /home/Amidamaru/projects/sntp/dev/missing --run autoheader
-AUTOMAKE = ${SHELL} /home/Amidamaru/projects/sntp/dev/missing --run automake-1.10
+AUTOCONF = ${SHELL} /geom_mobile/home/Amidamaru/projects/sntp/repo/gsoc_sntp/missing --run autoconf
+AUTOHEADER = ${SHELL} /geom_mobile/home/Amidamaru/projects/sntp/repo/gsoc_sntp/missing --run autoheader
+AUTOMAKE = ${SHELL} /geom_mobile/home/Amidamaru/projects/sntp/repo/gsoc_sntp/missing --run automake-1.10
 AWK = gawk
 BINSUBDIR = bin
 CC = gcc
@@ -134,8 +131,8 @@ LIBS = -lm
 LIBTOOL = $(SHELL) $(top_builddir)/libtool
 LN_S = ln -s
 LTLIBOBJS = 
-MAKEINFO = ${SHELL} /home/Amidamaru/projects/sntp/dev/missing --run makeinfo
-MKDIR_P = ./../install-sh -c -d
+MAKEINFO = ${SHELL} /geom_mobile/home/Amidamaru/projects/sntp/repo/gsoc_sntp/missing --run makeinfo
+MKDIR_P = ./install-sh -c -d
 NMEDIT = 
 OBJEXT = o
 PACKAGE = msntp
@@ -151,10 +148,10 @@ SET_MAKE =
 SHELL = /usr/local/bin/bash
 STRIP = strip
 VERSION = 1.6
-abs_builddir = /home/Amidamaru/projects/sntp/dev/sntp
-abs_srcdir = /home/Amidamaru/projects/sntp/dev/sntp
-abs_top_builddir = /home/Amidamaru/projects/sntp/dev/sntp
-abs_top_srcdir = /home/Amidamaru/projects/sntp/dev/sntp
+abs_builddir = /geom_mobile/home/Amidamaru/projects/sntp/repo/gsoc_sntp
+abs_srcdir = /geom_mobile/home/Amidamaru/projects/sntp/repo/gsoc_sntp
+abs_top_builddir = /geom_mobile/home/Amidamaru/projects/sntp/repo/gsoc_sntp
+abs_top_srcdir = /geom_mobile/home/Amidamaru/projects/sntp/repo/gsoc_sntp
 ac_ct_CC = gcc
 ac_ct_CXX = g++
 ac_ct_F77 = f77
@@ -183,13 +180,13 @@ host_vendor = unknown
 htmldir = ${docdir}
 includedir = ${prefix}/include
 infodir = ${datarootdir}/info
-install_sh = $(SHELL) /home/Amidamaru/projects/sntp/dev/install-sh
+install_sh = $(SHELL) /geom_mobile/home/Amidamaru/projects/sntp/repo/gsoc_sntp/install-sh
 libdir = ${exec_prefix}/lib
 libexecdir = ${exec_prefix}/libexec
 localedir = ${datarootdir}/locale
 localstatedir = ${prefix}/var
 mandir = ${datarootdir}/man
-mkdir_p = $(top_builddir)/./../install-sh -c -d
+mkdir_p = $(top_builddir)/./install-sh -c -d
 oldincludedir = /usr/include
 pdfdir = ${docdir}
 prefix = /usr/local
index 77a6afd09e064278ded20dfca180b80e4d7a18a2..a504b7128935792f7eba3b9cb0294ae8210f0961 100644 (file)
@@ -41,13 +41,10 @@ POST_UNINSTALL = :
 build_triplet = @build@
 host_triplet = @host@
 bin_PROGRAMS = sntp$(EXEEXT)
-DIST_COMMON = $(am__configure_deps) $(srcdir)/../config.guess \
-       $(srcdir)/../config.sub $(srcdir)/../depcomp \
-       $(srcdir)/../install-sh $(srcdir)/../ltmain.sh \
-       $(srcdir)/../missing $(srcdir)/Makefile.am \
+DIST_COMMON = $(am__configure_deps) $(srcdir)/Makefile.am \
        $(srcdir)/Makefile.in $(srcdir)/bincheck.mf \
        $(srcdir)/config.h.in $(top_srcdir)/configure config.guess \
-       config.sub
+       config.sub depcomp install-sh ltmain.sh missing
 subdir = .
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
 am__aclocal_m4_deps = $(top_srcdir)/configure.ac
@@ -67,7 +64,7 @@ sntp_OBJECTS = $(am_sntp_OBJECTS)
 sntp_LDADD = $(LDADD)
 sntp_DEPENDENCIES =
 DEFAULT_INCLUDES = -I.@am__isrc@
-depcomp = $(SHELL) $(top_srcdir)/../depcomp
+depcomp = $(SHELL) $(top_srcdir)/depcomp
 am__depfiles_maybe = depfiles
 COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
        $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
index da980c95645825e3fccd1b5d7d965e708baa4906..9b6d144520a07e35d635e369c6a53773ece94ad7 100644 (file)
@@ -40,7 +40,6 @@ search_entry (
        return resc;
 }
 
-
 void 
 add_entry (
                char *hostname,
@@ -49,7 +48,7 @@ add_entry (
 {
        if(kod_init) {
                struct kod_entry *new_entry = (struct kod_entry *) malloc(sizeof(struct kod_entry));
-               new_entry->hostname = hostname;
+               strcpy(new_entry->hostname, hostname);
                strlcpy(new_entry->type, type, 4);
                new_entry->next = NULL;
 
@@ -93,9 +92,6 @@ delete_entry (
                }
        }
 }
-                                                               
-
-
 
 void 
 write_kod_db (
@@ -138,8 +134,11 @@ kod_init_kod_db (
 
        register int a, b;
 
-       char *fbuf = (char *) malloc(sizeof(char) * 80);
+       /* Max. of 255 characters for hostname, 10 for timestamp, 4 for kisscode, 2 for format : and 1 for \n */
+       char *fbuf = (char *) malloc(sizeof(char) * 272);
        char *obuf = fbuf;
+       char error = 0;
+
 
        db_s = fopen(db_file, "r");
 
@@ -149,13 +148,13 @@ kod_init_kod_db (
                snprintf(msg, 80, "Cannot open KOD db file %s", db_file);
 
                if(debug) 
-                       debug(msg);
+                       debug_msg(msg);
 
                log_msg(msg, 2);
        }
 
        /* First let's see how many entries there are and check for right syntax */
-       while(fread(&fbuf, 80, sizeof(char), db_s) != 0) {
+       while(fgets(fbuf, 272, db_s) != 0) {
                int sepc = 0;
                for(a=0; a<strlen(fbuf); a++) {
                        if(fbuf[a] == ':') 
@@ -164,10 +163,10 @@ kod_init_kod_db (
                        if(fbuf[a] == '\n') {
                                if(sepc != 2) {
                                        char msg[80];
-                                       snprintf(msg, 80, "Syntax error in KOD db file %s in line %i", db_file, (entryc + 1));
+                                       snprintf(msg, 80, "Syntax error in KOD db file %s in line %i (missing :)", db_file, (entryc + 1));
 
                                        if(debug)
-                                               debug(msg);
+                                               debug_msg(msg);
 
                                        log_msg(msg, 1);
 
@@ -184,62 +183,28 @@ kod_init_kod_db (
 
        kod_db = (struct kod_entry *) malloc(sizeof(struct kod_entry) * entryc);
 
-
        /* Read contents of file and make a linked list */
        for(b=0; (!feof(db_s) || !ferror(db_s)) && b<entryc; b++) {
-               fbuf = obuf;
-               fgets(fbuf, 80,  db_s);
-
-               char fstart = 0;
-               int limit = strlen(fbuf);
-               char argn;
-
-               for(a=0; a<limit; a++) {
-                       argn = 0;
-
-                       if(fbuf[a] == ':' || fbuf[a] == '\n' || fbuf[a] == '\0') {
-                               char *tmp;
-                               switch(argn) {
-                                       case 0: 
-                                               kod_db[b].hostname = (char *) malloc(sizeof(char) * a);
-                                               strlcpy(kod_db[b].hostname, fbuf, a);
-                                               break;
-
-                                       case 1: 
-                                               tmp = (char *) malloc(sizeof(char) * a);
-                                               strlcpy(tmp, fbuf, a);
-                                               kod_db[b].timestamp = atoi(tmp);
-                                               free(tmp);
-                                               break;
-
-                                       case 2:
-                                               tmp = (char *) malloc(sizeof(char) * a);
-                                               strlcpy(tmp, fbuf, a);
-                                               strlcpy(kod_db[b].type, tmp, 4);
-                                               free(tmp);
-                                               break;
-
-                               }
-
-                               fstart = a+1;
-                               fbuf = &fbuf[fstart];
-                               limit -= fstart;
-                               a = 0;
-                               argn++;
-                       }
+               if(!fscanf(db_s, 
+                         "%s:%u:%s", kod_db[a].hostname, 
+                         kod_db[a].timestamp, 
+                         kod_db[a].type)) {
+                       b = entryc;
+                       error = 1;
+               } 
+               else {
+                       if(b > 0) 
+                               kod_db[b-1].next = &kod_db[b];
                }
 
-               if(b > 0) 
-                       kod_db[b-1].next = &kod_db[b];
-
        }
 
-       if(ferror(db_s)) {
+       if(ferror(db_s) || error) {
                char msg[80];
-               snprintf(msg, 80, "ferror indicates an error after parsing KOD db file %s", db_file);
+               snprintf(msg, 80, "An error occured while parsing the KOD db file %s", db_file);
 
                if(debug)
-                       debug(msg);
+                       debug_msg(msg);
 
                log_msg(msg, 2);
 
index d2feeeeeea8a6758470ac6f8aae6c956fd26c1cf..b119687f44b04977f77e128fd8f92eabf5eec91c 100644 (file)
@@ -2,7 +2,7 @@
 #define KOD_MANAGEMENT_H
 
 struct kod_entry {
-       char *hostname;
+       char hostname[255];
        unsigned int timestamp;
        char type[4];
        struct kod_entry *next;
index e77b068a64f0b8c860cb2978d8599b38dd65c314..f587979073f2cbc257d1e83d0e5c32046a2475ba 100644 (file)
@@ -30,7 +30,7 @@ void log_msg(char *message, int type) {
        }
 }
 
-void debug(char *message) {
+void debug_msg(char *message) {
        if(HAVE_OPT(FILELOG)) {
                fprintf(stderr, message);
        }
index 2aaf89a6a554f00b721c51fc66b88bed397b3bc2..aa359c39798dfda358e605192982b2414e410bab 100644 (file)
@@ -10,7 +10,7 @@
 #include <stdarg.h>
 
 void log_msg(char *message, char type);
-void debug(char *message);
+void debug_msg(char *message);
 
 char init = 0;
 FILE *log_file;
index 3fa7ed920c89167f414479400a9a70631de6e185..afcebfce65f227acb87a717a1a5def8e8db09cfa 100644 (file)
@@ -5,7 +5,13 @@
 #include "log.h"
 
 
-int resolve_hosts (char **hosts, int hostc, struct addrinfo **res) {
+int 
+resolve_hosts (
+               char **hosts, 
+               int hostc, 
+               struct addrinfo **res
+       ) 
+{
        register unsigned int a, b;
        unsigned int entryc = 0; 
 
@@ -65,11 +71,11 @@ int resolve_hosts (char **hosts, int hostc, struct addrinfo **res) {
 }
 
 /* Send a packet */
-static void
+void
 sendpkt (
-       struct sockaddr_storage *dest,
-       struct pkt *pkt,
-       int len
+               struct sockaddr_storage *dest,
+               struct pkt *pkt,
+               int len
        )
 {
        int sock;
@@ -190,7 +196,7 @@ recvpkt (
        /* 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
+        * don't want this function to do on-wire stuff. Sanity checks are right here I think
         *
        server->leap = PKT_LEAP(rpkt->li_vn_mode);
        server->stratum = PKT_TO_STRATUM(rpkt->stratum);
@@ -213,7 +219,9 @@ recvpkt (
  *                 (non-blocking).
  */
 int
-is_reachable (struct addrinfo *dst)
+is_reachable (
+               struct addrinfo *dst
+       )
 {
        SOCKET sockfd;
 
@@ -254,17 +262,17 @@ filter_reachable (
 
        for(a=0; a<filter_elements; a++) 
                cpyres[a] = res[index[a]];
-
-
+       
+       
        for(a=0, b=0; a<resc; a++) {
                if(a == index[b]) 
                        b++;
                else 
                        freeaddrinfo(res[a]);
        }
-
+       
        res = cpyres;
-
+       
        return filter_elements;
 }
 
@@ -275,4 +283,5 @@ filter_ntp (
                int resc
           )
 {
+       return 0;
 }
index da185555d90726a94f2e304cef4484494d881060..1dccf310e4ae5b03e0f6638f651253efd7b5a536 100644 (file)
 
 /* FIXME, see portability issue 1 */ /* irrelevant for now */
 #ifndef SYS_WINNT
-# define SOCKET        int
-# define INVALID_SOCKET        -1
-# define SOCKET_ERROR  -1
-# define closesocket close
+#define SOCKET int
+#define INVALID_SOCKET -1
+#define SOCKET_ERROR   -1
+#define closesocket close
 #endif
 
 /* Check if necessary or not */