From: Johannes Maximilian Kuehn Date: Tue, 22 Jul 2008 18:52:14 +0000 (+0900) Subject: log.h, log.c: X-Git-Tag: NTP_4_2_5P142~37^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=680c77c1ef75bbf1e9f873f05512ebb7edd219e6;p=thirdparty%2Fntp.git log.h, log.c: 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 --- diff --git a/gsoc_sntp/Makefile b/gsoc_sntp/Makefile index e442e6c55..b8cf2e5ca 100644 --- a/gsoc_sntp/Makefile +++ b/gsoc_sntp/Makefile @@ -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 diff --git a/gsoc_sntp/Makefile.in b/gsoc_sntp/Makefile.in index 77a6afd09..a504b7128 100644 --- a/gsoc_sntp/Makefile.in +++ b/gsoc_sntp/Makefile.in @@ -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) diff --git a/gsoc_sntp/kod_management.c b/gsoc_sntp/kod_management.c index da980c956..9b6d14452 100644 --- a/gsoc_sntp/kod_management.c +++ b/gsoc_sntp/kod_management.c @@ -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 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); diff --git a/gsoc_sntp/kod_management.h b/gsoc_sntp/kod_management.h index d2feeeeee..b119687f4 100644 --- a/gsoc_sntp/kod_management.h +++ b/gsoc_sntp/kod_management.h @@ -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; diff --git a/gsoc_sntp/log.c b/gsoc_sntp/log.c index e77b068a6..f58797907 100644 --- a/gsoc_sntp/log.c +++ b/gsoc_sntp/log.c @@ -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); } diff --git a/gsoc_sntp/log.h b/gsoc_sntp/log.h index 2aaf89a6a..aa359c397 100644 --- a/gsoc_sntp/log.h +++ b/gsoc_sntp/log.h @@ -10,7 +10,7 @@ #include void log_msg(char *message, char type); -void debug(char *message); +void debug_msg(char *message); char init = 0; FILE *log_file; diff --git a/gsoc_sntp/networking.c b/gsoc_sntp/networking.c index 3fa7ed920..afcebfce6 100644 --- a/gsoc_sntp/networking.c +++ b/gsoc_sntp/networking.c @@ -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