FreeCalypso > hg > sipout-test-utils
comparison test-voice/sip_log.c @ 0:35c0d9f03c0a
beginning with sipout-test-voice,
a copy of sip-manual-out from themwi-system-sw
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 03 Mar 2024 23:20:19 -0800 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:35c0d9f03c0a |
---|---|
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 } |