📄 ntp_util.c
字号:
if(rawstats.prefix == &statsdir[0] && rawstats.fp != NULL) { fclose(rawstats.fp); rawstats.fp = NULL; filegen_setup(&rawstats, now.l_ui); } if(sysstats.prefix == &statsdir[0] && sysstats.fp != NULL) { fclose(sysstats.fp); sysstats.fp = NULL; filegen_setup(&sysstats, now.l_ui); }#ifdef OPENSSL if(cryptostats.prefix == &statsdir[0] && cryptostats.fp != NULL) { fclose(cryptostats.fp); cryptostats.fp = NULL; filegen_setup(&cryptostats, now.l_ui); }#endif /* OPENSSL */ } break; case STATS_PID_FILE: if ((fp = fopen(value, "w")) == NULL) { msyslog(LOG_ERR, "Can't open %s: %m", value); break; } fprintf(fp, "%d", (int) getpid()); fclose(fp);; break; default: /* oh well */ break; }}/* * record_peer_stats - write peer statistics to file * * file format: * day (mjd) * time (s past UTC midnight) * peer (ip address) * peer status word (hex) * peer offset (s) * peer delay (s) * peer error bound (s) * peer error (s)*/voidrecord_peer_stats( struct sockaddr_storage *addr, int status, double offset, double delay, double dispersion, double skew ){ l_fp now; u_long day; if (!stats_control) return; get_systime(&now); filegen_setup(&peerstats, now.l_ui); day = now.l_ui / 86400 + MJD_1900; now.l_ui %= 86400; if (peerstats.fp != NULL) { fprintf(peerstats.fp, "%lu %s %s %x %.9f %.9f %.9f %.9f\n", day, ulfptoa(&now, 3), stoa(addr), status, offset, delay, dispersion, skew); fflush(peerstats.fp); }}/* * record_loop_stats - write loop filter statistics to file * * file format: * day (mjd) * time (s past midnight) * offset (s) * frequency (approx ppm) * time constant (log base 2) */voidrecord_loop_stats( double offset, double freq, double jitter, double stability, int spoll ){ l_fp now; u_long day; if (!stats_control) return; get_systime(&now); filegen_setup(&loopstats, now.l_ui); day = now.l_ui / 86400 + MJD_1900; now.l_ui %= 86400; if (loopstats.fp != NULL) { fprintf(loopstats.fp, "%lu %s %.9f %.3f %.9f %.6f %d\n", day, ulfptoa(&now, 3), offset, freq * 1e6, jitter, stability * 1e6, spoll); fflush(loopstats.fp); }}/* * record_clock_stats - write clock statistics to file * * file format: * day (mjd) * time (s past midnight) * peer (ip address) * text message */voidrecord_clock_stats( struct sockaddr_storage *addr, const char *text ){ l_fp now; u_long day; if (!stats_control) return; get_systime(&now); filegen_setup(&clockstats, now.l_ui); day = now.l_ui / 86400 + MJD_1900; now.l_ui %= 86400; if (clockstats.fp != NULL) { fprintf(clockstats.fp, "%lu %s %s %s\n", day, ulfptoa(&now, 3), stoa(addr), text); fflush(clockstats.fp); }}/* * record_raw_stats - write raw timestamps to file * * * file format * time (s past midnight) * peer ip address * local ip address * t1 t2 t3 t4 timestamps */voidrecord_raw_stats( struct sockaddr_storage *srcadr, struct sockaddr_storage *dstadr, l_fp *t1, l_fp *t2, l_fp *t3, l_fp *t4 ){ l_fp now; u_long day; if (!stats_control) return; get_systime(&now); filegen_setup(&rawstats, now.l_ui); day = now.l_ui / 86400 + MJD_1900; now.l_ui %= 86400; if (rawstats.fp != NULL) { fprintf(rawstats.fp, "%lu %s %s %s %s %s %s %s\n", day, ulfptoa(&now, 3), stoa(srcadr), stoa(dstadr), ulfptoa(t1, 9), ulfptoa(t2, 9), ulfptoa(t3, 9), ulfptoa(t4, 9)); fflush(rawstats.fp); }}/* * record_sys_stats - write system statistics to file * * file format * time (s past midnight) * time since startup (hr) * packets recieved * packets processed * current version * previous version * bad version * access denied * bad length or format * bad authentication * rate exceeded */voidrecord_sys_stats(void){ l_fp now; u_long day; if (!stats_control) return; get_systime(&now); filegen_setup(&sysstats, now.l_ui); day = now.l_ui / 86400 + MJD_1900; now.l_ui %= 86400; if (sysstats.fp != NULL) { fprintf(sysstats.fp, "%lu %s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu\n", day, ulfptoa(&now, 3), sys_stattime / 3600, sys_received, sys_processed, sys_newversionpkt, sys_oldversionpkt, sys_unknownversion, sys_restricted, sys_badlength, sys_badauth, sys_limitrejected); fflush(sysstats.fp); proto_clr_stats(); }}#ifdef OPENSSL/* * record_crypto_stats - write crypto statistics to file * * file format: * day (mjd) * time (s past midnight) * peer (ip address) * text message */voidrecord_crypto_stats( struct sockaddr_storage *addr, const char *text ){ l_fp now; u_long day; if (!stats_control) return; get_systime(&now); filegen_setup(&cryptostats, now.l_ui); day = now.l_ui / 86400 + MJD_1900; now.l_ui %= 86400; if (cryptostats.fp != NULL) { if (addr == NULL) fprintf(cryptostats.fp, "%lu %s %s\n", day, ulfptoa(&now, 3), text); else fprintf(cryptostats.fp, "%lu %s %s %s\n", day, ulfptoa(&now, 3), stoa(addr), text); fflush(cryptostats.fp); }}#endif /* OPENSSL *//* * getauthkeys - read the authentication keys from the specified file */voidgetauthkeys( char *keyfile ){ int len; len = strlen(keyfile); if (len == 0) return; if (key_file_name != 0) { if (len > (int)strlen(key_file_name)) { (void) free(key_file_name); key_file_name = 0; } } if (key_file_name == 0) {#ifndef SYS_WINNT key_file_name = (char*)emalloc((u_int) (len + 1));#else key_file_name = (char*)emalloc((u_int) (MAXPATHLEN));#endif }#ifndef SYS_WINNT memmove(key_file_name, keyfile, (unsigned)(len+1));#else if (!ExpandEnvironmentStrings(keyfile, key_file_name, MAXPATHLEN)) { msyslog(LOG_ERR, "ExpandEnvironmentStrings(KEY_FILE) failed: %m\n"); }#endif /* SYS_WINNT */ authreadkeys(key_file_name);}/* * rereadkeys - read the authentication key file over again. */voidrereadkeys(void){ if (key_file_name != 0) authreadkeys(key_file_name);}/* * sock_hash - hash an sockaddr_storage structure */intsock_hash( struct sockaddr_storage *addr ){ int hashVal; int i; int len; char *ch; hashVal = 0; len = 0; /* * We can't just hash the whole thing because there are hidden * fields in sockaddr_in6 that might be filled in by recvfrom(), * so just use the family, port and address. */ ch = (char *)&addr->ss_family; hashVal = 37 * hashVal + (int)*ch; if (sizeof(addr->ss_family) > 1) { ch++; hashVal = 37 * hashVal + (int)*ch; } switch(addr->ss_family) { case AF_INET: ch = (char *)&((struct sockaddr_in *)addr)->sin_addr; len = sizeof(struct in_addr); break; case AF_INET6: ch = (char *)&((struct sockaddr_in6 *)addr)->sin6_addr; len = sizeof(struct in6_addr); break; } for (i = 0; i < len ; i++) hashVal = 37 * hashVal + (int)*(ch + i); hashVal = hashVal % 128; /* % MON_HASH_SIZE hardcoded */ if (hashVal < 0) hashVal += 128; return hashVal;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -