|
@@ -12,6 +12,9 @@
|
12
|
12
|
#include "process.h"
|
13
|
13
|
#include "udp.h"
|
14
|
14
|
|
|
15
|
+const char *program_name = "tsdecrypt";
|
|
16
|
+const char *program_version = "v1.1";
|
|
17
|
+
|
15
|
18
|
static void LOG_func(const char *msg) {
|
16
|
19
|
char date[64];
|
17
|
20
|
struct tm tm;
|
|
@@ -23,10 +26,16 @@ static void LOG_func(const char *msg) {
|
23
|
26
|
}
|
24
|
27
|
|
25
|
28
|
static void show_help(struct ts *ts) {
|
26
|
|
- printf("tsdecrypt v1.0 (git %s) (build date %s)\n", GIT_VER, BUILD_ID);
|
|
29
|
+ printf("%s %s (git %s) (build date %s)\n", program_name, program_version, GIT_VER, BUILD_ID);
|
27
|
30
|
printf("Copyright (c) 2011 Unix Solutions Ltd.\n");
|
28
|
31
|
printf("\n");
|
29
|
|
- printf(" Usage: tsdecrypt [opts]\n");
|
|
32
|
+ printf(" Usage: %s [opts]\n", program_name);
|
|
33
|
+ printf("\n");
|
|
34
|
+ printf(" Daemon options:\n");
|
|
35
|
+ printf(" -i server_ident | Format PROVIDER/CHANNEL (default: %s)\n", ts->ident);
|
|
36
|
+ printf(" -d pidfile | Daemonize %s and write pid file. (default: do not daemonize)\n", program_name);
|
|
37
|
+ printf(" -l syslog host | Where is the syslog server (default: disabled)\n");
|
|
38
|
+ printf(" -L Syslog port | What is the syslog server port (default: %d)\n", ts->syslog_port);
|
30
|
39
|
printf("\n");
|
31
|
40
|
printf(" Input options:\n");
|
32
|
41
|
printf(" -I input | Where to read from. Supports files and multicast\n");
|
|
@@ -92,10 +101,28 @@ static int parse_io_param(struct io *io, char *opt, int open_flags, mode_t open_
|
92
|
101
|
}
|
93
|
102
|
|
94
|
103
|
static void parse_options(struct ts *ts, int argc, char **argv) {
|
95
|
|
- int j, ca_err = 0, server_err = 1, input_addr_err = 0, output_addr_err = 0, output_intf_err = 0;
|
96
|
|
- while ((j = getopt(argc, argv, "c:s:I:O:o:t:U:P:ezpD:h")) != -1) {
|
|
104
|
+ int j, i, ca_err = 0, server_err = 1, input_addr_err = 0, output_addr_err = 0, output_intf_err = 0, ident_err = 0;
|
|
105
|
+ while ((j = getopt(argc, argv, "i:d:l:L:c:s:I:O:o:t:U:P:ezpD:h")) != -1) {
|
97
|
106
|
char *p = NULL;
|
98
|
107
|
switch (j) {
|
|
108
|
+ case 'i':
|
|
109
|
+ strncpy(ts->ident, optarg, sizeof(ts->ident) - 1);
|
|
110
|
+ ts->ident[sizeof(ts->ident) - 1] = 0;
|
|
111
|
+ break;
|
|
112
|
+ case 'd':
|
|
113
|
+ strncpy(ts->pidfile, optarg, sizeof(ts->pidfile) - 1);
|
|
114
|
+ ts->pidfile[sizeof(ts->pidfile) - 1] = 0;
|
|
115
|
+ ts->daemonize = 1;
|
|
116
|
+ break;
|
|
117
|
+ case 'l':
|
|
118
|
+ strncpy(ts->syslog_host, optarg, sizeof(ts->syslog_host) - 1);
|
|
119
|
+ ts->syslog_host[sizeof(ts->syslog_host) - 1] = 0;
|
|
120
|
+ ts->syslog_active = 1;
|
|
121
|
+ break;
|
|
122
|
+ case 'L':
|
|
123
|
+ ts->syslog_port = atoi(optarg);
|
|
124
|
+ break;
|
|
125
|
+
|
99
|
126
|
case 'c':
|
100
|
127
|
if (strcasecmp("IRDETO", optarg) == 0)
|
101
|
128
|
ts->req_CA_sys = CA_IRDETO;
|
|
@@ -164,8 +191,12 @@ static void parse_options(struct ts *ts, int argc, char **argv) {
|
164
|
191
|
exit(0);
|
165
|
192
|
}
|
166
|
193
|
}
|
167
|
|
- if (ca_err || server_err || input_addr_err || output_addr_err || ts->input.type == WTF_IO || ts->output.type == WTF_IO) {
|
|
194
|
+ if (ts->syslog_active && !ts->ident[0])
|
|
195
|
+ ident_err = 1;
|
|
196
|
+ if (ident_err || ca_err || server_err || input_addr_err || output_addr_err || ts->input.type == WTF_IO || ts->output.type == WTF_IO) {
|
168
|
197
|
show_help(ts);
|
|
198
|
+ if (ident_err)
|
|
199
|
+ fprintf(stderr, "ERROR: Syslog is enabled but ident was not set.\n");
|
169
|
200
|
if (ca_err)
|
170
|
201
|
fprintf(stderr, "ERROR: Requested CA system is unsupported.\n");
|
171
|
202
|
if (server_err)
|
|
@@ -178,6 +209,18 @@ static void parse_options(struct ts *ts, int argc, char **argv) {
|
178
|
209
|
fprintf(stderr, "ERROR: Output interface address is invalid.\n");
|
179
|
210
|
exit(1);
|
180
|
211
|
}
|
|
212
|
+ if (ts->ident[0])
|
|
213
|
+ ts_LOGf("Ident : %s\n", ts->ident);
|
|
214
|
+ else
|
|
215
|
+ ts_LOGf("Ident : *NOT SET*\n");
|
|
216
|
+ if (ts->pidfile[0])
|
|
217
|
+ ts_LOGf("Daemonize : %s pid file.\n", ts->pidfile);
|
|
218
|
+ else
|
|
219
|
+ ts_LOGf("Daemonize : no daemon\n");
|
|
220
|
+ if (ts->syslog_active)
|
|
221
|
+ ts_LOGf("Syslog : %s:%d\n", ts->syslog_host, ts->syslog_port);
|
|
222
|
+ else
|
|
223
|
+ ts_LOGf("Syslog : disabled\n");
|
181
|
224
|
ts_LOGf("CA System : %s\n", ts_get_CA_sys_txt(ts->req_CA_sys));
|
182
|
225
|
if (ts->input.type == NET_IO) {
|
183
|
226
|
ts_LOGf("Input addr : udp://%s:%u/\n", inet_ntoa(ts->input.addr), ts->input.port);
|
|
@@ -199,6 +242,13 @@ static void parse_options(struct ts *ts, int argc, char **argv) {
|
199
|
242
|
ts_LOGf("TS discont : %s\n", ts->ts_discont ? "report" : "ignore");
|
200
|
243
|
ts->threaded = !(ts->input.type == FILE_IO && ts->input.fd != 0);
|
201
|
244
|
ts_LOGf("Decoding : %s\n", ts->threaded ? "threaded" : "single thread");
|
|
245
|
+
|
|
246
|
+ for (i=0; i<(int)sizeof(ts->ident); i++) {
|
|
247
|
+ if (!ts->ident[i])
|
|
248
|
+ break;
|
|
249
|
+ if (ts->ident[i] == '/')
|
|
250
|
+ ts->ident[i] = '-';
|
|
251
|
+ }
|
202
|
252
|
}
|
203
|
253
|
|
204
|
254
|
int main(int argc, char **argv) {
|
|
@@ -206,12 +256,21 @@ int main(int argc, char **argv) {
|
206
|
256
|
uint8_t ts_packet[FRAME_SIZE];
|
207
|
257
|
struct ts ts;
|
208
|
258
|
|
209
|
|
- ts_set_log_func(LOG_func);
|
210
|
|
-
|
211
|
259
|
data_init(&ts);
|
212
|
260
|
|
213
|
261
|
parse_options(&ts, argc, argv);
|
214
|
262
|
|
|
263
|
+ if (ts.pidfile[0])
|
|
264
|
+ daemonize(ts.pidfile);
|
|
265
|
+
|
|
266
|
+ if (!ts.syslog_active) {
|
|
267
|
+ ts_set_log_func(LOG_func);
|
|
268
|
+ } else {
|
|
269
|
+ ts_set_log_func(LOG);
|
|
270
|
+ log_init(ts.ident, ts.syslog_active, ts.daemonize != 1, ts.syslog_host, ts.syslog_port);
|
|
271
|
+ ts_LOGf("Start %s %s (git %s) (build date %s)\n", program_name, program_version, GIT_VER, BUILD_ID);
|
|
272
|
+ }
|
|
273
|
+
|
215
|
274
|
if (ts.input.type == NET_IO && udp_connect_input(&ts.input) < 1)
|
216
|
275
|
goto EXIT;
|
217
|
276
|
if (ts.output.type == NET_IO && udp_connect_output(&ts.output) < 1)
|