FreeCalypso > hg > themwi-system-sw
comparison smpp-trx-sa/log.c @ 222:9d6e8d99d2b1
smpp-trx-sa: new program
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 03 Aug 2023 21:13:41 -0800 |
parents | |
children | a375639e4190 |
comparison
equal
deleted
inserted
replaced
221:e1d7db9d734c | 222:9d6e8d99d2b1 |
---|---|
1 /* | |
2 * This module implements smpp-trx-sa log file output. | |
3 */ | |
4 | |
5 #include <sys/types.h> | |
6 #include <stdio.h> | |
7 #include <stdlib.h> | |
8 #include <string.h> | |
9 #include <strings.h> | |
10 #include <time.h> | |
11 | |
12 extern FILE *logF; | |
13 extern time_t curtime; | |
14 extern int init_done; | |
15 | |
16 static char fmt_time[32]; | |
17 | |
18 static void | |
19 format_time() | |
20 { | |
21 struct tm *tm; | |
22 | |
23 tm = gmtime(&curtime); | |
24 sprintf(fmt_time, "%d-%02d-%02dT%02d:%02d:%02dZ", | |
25 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, | |
26 tm->tm_hour, tm->tm_min, tm->tm_sec); | |
27 } | |
28 | |
29 void | |
30 log_fatal_error(cause) | |
31 char *cause; | |
32 { | |
33 if (!init_done) | |
34 return; | |
35 format_time(); | |
36 fprintf(logF, "\n%s %s\n", fmt_time, cause); | |
37 } | |
38 | |
39 static void | |
40 pdu_hexdump(pdu, pdulen) | |
41 u_char *pdu; | |
42 unsigned pdulen; | |
43 { | |
44 unsigned off, chunk; | |
45 int i, c; | |
46 | |
47 for (off = 0; off < pdulen; off += chunk) { | |
48 fprintf(logF, "%04X: ", off); | |
49 chunk = pdulen - off; | |
50 if (chunk > 16) | |
51 chunk = 16; | |
52 for (i = 0; i < 16; i++) { | |
53 if (i < chunk) | |
54 fprintf(logF, "%02X ", pdu[off + i]); | |
55 else | |
56 fputs(" ", logF); | |
57 if (i == 7 || i == 15) | |
58 putc(' ', logF); | |
59 } | |
60 for (i = 0; i < chunk; i++) { | |
61 c = pdu[off + i]; | |
62 if (c < ' ' || c > '~') | |
63 c = '.'; | |
64 putc(c, logF); | |
65 } | |
66 putc('\n', logF); | |
67 } | |
68 } | |
69 | |
70 void | |
71 log_rx_pdu(pdu, pdulen) | |
72 u_char *pdu; | |
73 unsigned pdulen; | |
74 { | |
75 format_time(); | |
76 fprintf(logF, "\n%s Received PDU:\n", fmt_time); | |
77 pdu_hexdump(pdu, pdulen); | |
78 } | |
79 | |
80 void | |
81 log_sent_pdu(pdu, pdulen) | |
82 u_char *pdu; | |
83 unsigned pdulen; | |
84 { | |
85 format_time(); | |
86 fprintf(logF, "\n%s Sent PDU:\n", fmt_time); | |
87 pdu_hexdump(pdu, pdulen); | |
88 } |