FreeCalypso > hg > themwi-system-sw
view smpp-trx-sa/log.c @ 240:c7a3ba56c636
themwi-short-dial: fix bug in printf arguments
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 14 Aug 2023 15:37:59 -0800 |
parents | 9d6e8d99d2b1 |
children | a375639e4190 |
line wrap: on
line source
/* * This module implements smpp-trx-sa log file output. */ #include <sys/types.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <strings.h> #include <time.h> extern FILE *logF; extern time_t curtime; extern int init_done; static char fmt_time[32]; static void format_time() { struct tm *tm; tm = gmtime(&curtime); sprintf(fmt_time, "%d-%02d-%02dT%02d:%02d:%02dZ", tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec); } void log_fatal_error(cause) char *cause; { if (!init_done) return; format_time(); fprintf(logF, "\n%s %s\n", fmt_time, cause); } static void pdu_hexdump(pdu, pdulen) u_char *pdu; unsigned pdulen; { unsigned off, chunk; int i, c; for (off = 0; off < pdulen; off += chunk) { fprintf(logF, "%04X: ", off); chunk = pdulen - off; if (chunk > 16) chunk = 16; for (i = 0; i < 16; i++) { if (i < chunk) fprintf(logF, "%02X ", pdu[off + i]); else fputs(" ", logF); if (i == 7 || i == 15) putc(' ', logF); } for (i = 0; i < chunk; i++) { c = pdu[off + i]; if (c < ' ' || c > '~') c = '.'; putc(c, logF); } putc('\n', logF); } } void log_rx_pdu(pdu, pdulen) u_char *pdu; unsigned pdulen; { format_time(); fprintf(logF, "\n%s Received PDU:\n", fmt_time); pdu_hexdump(pdu, pdulen); } void log_sent_pdu(pdu, pdulen) u_char *pdu; unsigned pdulen; { format_time(); fprintf(logF, "\n%s Sent PDU:\n", fmt_time); pdu_hexdump(pdu, pdulen); }