|
@@ -18,6 +18,7 @@
|
18
|
18
|
#include <openssl/aes.h>
|
19
|
19
|
#include <openssl/md5.h>
|
20
|
20
|
|
|
21
|
+#include "libfuncs/libfuncs.h"
|
21
|
22
|
#include "libts/tsfuncs.h"
|
22
|
23
|
|
23
|
24
|
#include "util.h"
|
|
@@ -62,6 +63,7 @@ void LOG_func(const char *msg) {
|
62
|
63
|
}
|
63
|
64
|
|
64
|
65
|
enum CA_system req_CA_sys = CA_CONNAX;
|
|
66
|
+int server_fd = -1;
|
65
|
67
|
char *camd35_server = "10.0.1.78";
|
66
|
68
|
struct in_addr camd35_server_ip;
|
67
|
69
|
uint16_t camd35_port = 2233;
|
|
@@ -76,6 +78,28 @@ enum e_flag {
|
76
|
78
|
TYPE_ECM
|
77
|
79
|
};
|
78
|
80
|
|
|
81
|
+static int connect_to(struct in_addr ip, int port) {
|
|
82
|
+ ts_LOGf("Connecting to %s:%d\n", inet_ntoa(ip), port);
|
|
83
|
+
|
|
84
|
+ int fd = socket(PF_INET, SOCK_STREAM, 0);
|
|
85
|
+ if (fd < 0) {
|
|
86
|
+ ts_LOGf("Could not create socket | %s\n", strerror(errno));
|
|
87
|
+ return -1;
|
|
88
|
+ }
|
|
89
|
+
|
|
90
|
+ struct sockaddr_in sock;
|
|
91
|
+ sock.sin_family = AF_INET;
|
|
92
|
+ sock.sin_port = htons(port);
|
|
93
|
+ sock.sin_addr = ip;
|
|
94
|
+ if (do_connect(fd, (struct sockaddr *)&sock, sizeof(sock), 1000) < 0) {
|
|
95
|
+ ts_LOGf("Could not connect to %s:%d | %s\n", inet_ntoa(ip), port, strerror(errno));
|
|
96
|
+ return -1;
|
|
97
|
+ }
|
|
98
|
+
|
|
99
|
+ ts_LOGf("Connected with fd:%d\n", fd);
|
|
100
|
+ return fd;
|
|
101
|
+}
|
|
102
|
+
|
79
|
103
|
void savefile(uint8_t *data, int datasize, enum e_flag flag) {
|
80
|
104
|
static int cnt = 0;
|
81
|
105
|
char *fname;
|
|
@@ -104,6 +128,11 @@ static void camd35_init_auth(char *user, char *pass) {
|
104
|
128
|
AES_set_decrypt_key(dump, 128, &camd35_aes_decrypt_key);
|
105
|
129
|
}
|
106
|
130
|
|
|
131
|
+static void camd35_connect() {
|
|
132
|
+ if (server_fd < 0)
|
|
133
|
+ server_fd = connect_to(camd35_server_ip, camd35_port);
|
|
134
|
+}
|
|
135
|
+
|
107
|
136
|
static int camd35_recv(uint8_t *data, int *data_len) {
|
108
|
137
|
int i;
|
109
|
138
|
|
|
@@ -125,6 +154,8 @@ static int camd35_send(uint8_t *data, uint8_t data_len, enum e_flag tp) {
|
125
|
154
|
uint8_t buf[BUF_SIZE];
|
126
|
155
|
uint8_t *bdata = buf + 4;
|
127
|
156
|
|
|
157
|
+ camd35_connect();
|
|
158
|
+
|
128
|
159
|
if (!camd35_auth)
|
129
|
160
|
camd35_init_auth(camd35_user, camd35_pass);
|
130
|
161
|
|
|
@@ -371,6 +402,7 @@ void show_help() {
|
371
|
402
|
|
372
|
403
|
void parse_options(int argc, char **argv) {
|
373
|
404
|
int j, ca_err = 0, server_err = 0;
|
|
405
|
+ inet_aton(camd35_server, &camd35_server_ip);
|
374
|
406
|
while ((j = getopt(argc, argv, "C:S:P:u:p:h")) != -1) {
|
375
|
407
|
switch (j) {
|
376
|
408
|
case 'C':
|
|
@@ -385,7 +417,7 @@ void parse_options(int argc, char **argv) {
|
385
|
417
|
break;
|
386
|
418
|
case 'S':
|
387
|
419
|
camd35_server = optarg;
|
388
|
|
- if (inet_aton(optarg, &camd35_server_ip) == 0)
|
|
420
|
+ if (inet_aton(camd35_server, &camd35_server_ip) == 0)
|
389
|
421
|
server_err = 1;
|
390
|
422
|
break;
|
391
|
423
|
case 'P':
|
|
@@ -413,8 +445,9 @@ void parse_options(int argc, char **argv) {
|
413
|
445
|
}
|
414
|
446
|
fprintf(stderr, "CA System : %s\n", ts_get_CA_sys_txt(req_CA_sys));
|
415
|
447
|
fprintf(stderr, "Server\n");
|
416
|
|
- fprintf(stderr, " Addr : %s:%d\n", camd35_server, camd35_port);
|
|
448
|
+ fprintf(stderr, " Addr : %s:%d\n", inet_ntoa(camd35_server_ip), camd35_port);
|
417
|
449
|
fprintf(stderr, " Auth : %s / %s\n", camd35_user, camd35_pass);
|
|
450
|
+ camd35_connect();
|
418
|
451
|
}
|
419
|
452
|
|
420
|
453
|
#define FRAME_SIZE (188 * 7)
|
|
@@ -434,5 +467,6 @@ int main(int argc, char **argv) {
|
434
|
467
|
} while (readen == FRAME_SIZE);
|
435
|
468
|
ts_free(&ts);
|
436
|
469
|
|
|
470
|
+ shutdown_fd(&server_fd);
|
437
|
471
|
exit(0);
|
438
|
472
|
}
|