forked from EnderUNIX/VoIPong
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvoipongcdr.c
73 lines (61 loc) · 1.6 KB
/
voipongcdr.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <errno.h>
#include <fcntl.h>
#include <pcap.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <netinet/in_systm.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#define __USE_BSD 1
#define __FAVOR_BSD 1
#include <netinet/ip.h>
#include <netinet/udp.h>
#include <miscutil.h>
#include <voipong.h>
#include <voipongvoip.h>
#include <voipongworker.h>
#include <voipongpcap.h>
extern char goutdir[256];
extern char gcdrfile[256];
void
checkcdrfile()
{
struct stat st;
FILE *fp;
if (stat(gcdrfile, &st) == -1)
if (errno == ENOENT) {
if ((fp = fopen(gcdrfile, "a")) == NULL) {
misc_debug(0, "checkcdrfile: fopen(%s): %s\n", gcdrfile, strerror(errno));
return;
}
writew_lock(fileno(fp));
fprintf(fp, "Start;End;Duration(seconds);Session Id;Party1 RTP Pair; Party 2 RTP Pair;Encoding;Rate\n");
fclose(fp);
}
}
int
add2cdr(worker *w)
{
FILE *fp;
char stime[256];
char etime[256];
checkcdrfile();
if ((fp = fopen(gcdrfile, "a")) == NULL) {
misc_debug(0, "add2cdr: fopen(%s): %s\n", gcdrfile, strerror(errno));
return -1;
}
writew_lock(fileno(fp));
misc_strftimegiven(stime, sizeof(stime) - 2, "%a %b %d %H:%M:%S %Y", w->stime);
misc_strftimegiven(etime, sizeof(etime) - 2, "%a %b %d %H:%M:%S %Y", w->etime);
fprintf(fp, "%s;%s;%d;%d;%s:%d;%s:%d;%d;%d\n", stime, etime, (w->etime - w->stime), getpid(),
misc_inet_ntoa(w->rtp->ip1), w->rtp->port1,
misc_inet_ntoa(w->rtp->ip2), w->rtp->port2, w->rtp->enc, w->rtp->rate);
fclose(fp);
return 0;
}