FreeCalypso > hg > sipout-test-utils
comparison test-v22/sip_log.c @ 10:3c5734b88c20
sipout-test-v22 put together
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 07 Mar 2024 02:33:49 -0800 |
parents | test-fsk/sip_log.c@26383ed8b79f |
children |
comparison
equal
deleted
inserted
replaced
9:ff535725e01f | 10:3c5734b88c20 |
---|---|
1 /* | |
2 * In this module we implement debug logging of SIP Rx & Tx messages. | |
3 */ | |
4 | |
5 #include <sys/types.h> | |
6 #include <sys/socket.h> | |
7 #include <sys/time.h> | |
8 #include <netinet/in.h> | |
9 #include <arpa/inet.h> | |
10 #include <stdio.h> | |
11 #include <stdlib.h> | |
12 #include <string.h> | |
13 #include <strings.h> | |
14 | |
15 extern struct timeval cur_event_time; | |
16 | |
17 static FILE *logfile; | |
18 | |
19 open_sip_log_file(filename) | |
20 char *filename; | |
21 { | |
22 logfile = fopen(filename, "a"); | |
23 if (!logfile) { | |
24 perror(filename); | |
25 return(-1); | |
26 } | |
27 return(0); | |
28 } | |
29 | |
30 static void | |
31 log_common(msg, msglen, sin, dir) | |
32 char *msg, *dir; | |
33 unsigned msglen; | |
34 struct sockaddr_in *sin; | |
35 { | |
36 unsigned sec, ms; | |
37 | |
38 sec = cur_event_time.tv_sec % 86400; | |
39 ms = cur_event_time.tv_usec / 1000; | |
40 fprintf(logfile, "Msg %s %s:%u %u bytes %02u:%02u:%02u.%03u\n", dir, | |
41 inet_ntoa(sin->sin_addr), ntohs(sin->sin_port), msglen, | |
42 sec / 3600, (sec / 60) % 60, sec % 60, ms); | |
43 fwrite(msg, 1, msglen, logfile); | |
44 putc('\n', logfile); | |
45 fflush(logfile); | |
46 } | |
47 | |
48 void | |
49 log_sip_msg_rx(msg, msglen, sin) | |
50 char *msg; | |
51 unsigned msglen; | |
52 struct sockaddr_in *sin; | |
53 { | |
54 if (!logfile) | |
55 return; | |
56 log_common(msg, msglen, sin, "from"); | |
57 } | |
58 | |
59 void | |
60 log_sip_msg_tx(msg, msglen, sin) | |
61 char *msg; | |
62 unsigned msglen; | |
63 struct sockaddr_in *sin; | |
64 { | |
65 if (!logfile) | |
66 return; | |
67 log_common(msg, msglen, sin, "to"); | |
68 } |