Browse Source

Allow camd server address to be resolved, not only set by IP address.

The limitation is that resolving the hostname is performed only
once at tsdecrypt startup. If DNS changes while tsdecrypt is running,
tsdecrypt won't notice that.
Georgi Chorbadzhiyski 11 years ago
parent
commit
5c19959d1f
4 changed files with 31 additions and 11 deletions
  1. 2
    0
      ChangeLog
  2. 1
    1
      README
  3. 5
    4
      tsdecrypt.1
  4. 23
    6
      tsdecrypt.c

+ 2
- 0
ChangeLog View File

@@ -3,6 +3,8 @@
3 3
    disabled if there is no currently received code word.
4 4
  * Remove deprecated --output-filter option. The option you should use is
5 5
   --no-output-filter.
6
+ * Allow camd server address (--camd-server, -s) to be resolved, not only
7
+   set by IP address.
6 8
 
7 9
 2012-04-19 : Version 8.1
8 10
  * Add support for Bulcrypt CAS.

+ 1
- 1
README View File

@@ -142,7 +142,7 @@ CA options:
142 142
 CAMD server options:
143 143
  -A --camd-proto <proto>    | Set CAMD network protocol.
144 144
                             . Valid protocols are: CS378X (default) and NEWCAMD
145
- -s --camd-server <addr>    | Set CAMD server ip_address:port (1.2.3.4:2233).
145
+ -s --camd-server <host>    | Set CAMD server address. Default port: 2233
146 146
  -U --camd-user <user>      | Set CAMD server user. Default: user
147 147
  -P --camd-pass <pass>      | Set CAMD server password. Default: pass
148 148
  -B --camd-des-key <key>    | Set DES key for newcamd protocol.

+ 5
- 4
tsdecrypt.1 View File

@@ -177,10 +177,11 @@ Set CAMD server protocol. Valid protocols are \fBCS378X\fR and \fBNEWCAMD\fR.
177 177
 If this option is not used the default protocol is \fBCS378X\fR (camd35 over
178 178
 tcp).
179 179
 .TP
180
-\fB\-s\fR, \fB\-\-camd\-server\fR <addr[:port]>
181
-Set CAMD server ip and port (10.0.1.1:2233). Is not set default port
182
-is \fB2233\fR. 2233 is the default port CS378X protocol, for NEWCAMD
183
-protocol you probably should choose other port.
180
+\fB\-s\fR, \fB\-\-camd\-server\fR <host[:port]>
181
+Set CAMD server address. You can use IP address or hostname. If the port is not
182
+set then \fB2233\fR is used as default port. 2233 is the default port for
183
+CS378X protocol but for NEWCAMD protocol you probably should choose other
184
+port number.
184 185
 .TP
185 186
 \fB\-U\fR, \fB\-\-camd\-user\fR <username>
186 187
 Set CAMD user name. The default is \fBuser\fR.

+ 23
- 6
tsdecrypt.c View File

@@ -180,7 +180,7 @@ static void show_help(struct ts *ts) {
180 180
 	printf("CAMD server options:\n");
181 181
 	printf(" -A --camd-proto <proto>    | Set CAMD network protocol.\n");
182 182
 	printf("                            . Valid protocols are: CS378X (default) and NEWCAMD\n");
183
-	printf(" -s --camd-server <addr>    | Set CAMD server ip_address:port (1.2.3.4:2233).\n");
183
+	printf(" -s --camd-server <host>    | Set CAMD server address. Default port: 2233\n");
184 184
 	printf(" -U --camd-user <user>      | Set CAMD server user. Default: %s\n", ts->camd.user);
185 185
 	printf(" -P --camd-pass <pass>      | Set CAMD server password. Default: %s\n", ts->camd.pass);
186 186
 	printf(" -B --camd-des-key <key>    | Set DES key for newcamd protocol.\n");
@@ -250,6 +250,8 @@ static int parse_io_param(struct io *io, char *opt, int open_flags, mode_t open_
250 250
 }
251 251
 
252 252
 static void parse_options(struct ts *ts, int argc, char **argv) {
253
+	int h_err;
254
+	struct addrinfo hints, *addrinfo = NULL;
253 255
 	int j, i, ca_err = 0, server_err = 1, input_addr_err = 0, output_addr_err = 0, output_intf_err = 0, ident_err = 0, port_set = 0;
254 256
 	while ((j = getopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
255 257
 		char *p = NULL;
@@ -425,10 +427,25 @@ static void parse_options(struct ts *ts, int argc, char **argv) {
425 427
 					ts->camd.server_port = atoi(p + 1);
426 428
 					port_set = 1;
427 429
 				}
428
-				if (inet_aton(optarg, &ts->camd.server_addr) == 0)
429
-					server_err = 1;
430
-				else
431
-					server_err = 0;
430
+				server_err = 1;
431
+
432
+				memset(&hints, 0, sizeof hints);
433
+				hints.ai_family = AF_INET;
434
+				hints.ai_socktype = SOCK_STREAM;
435
+				h_err = getaddrinfo(optarg, NULL, &hints, &addrinfo);
436
+				if (h_err == 0) {
437
+					int num_addrs = 0;
438
+					struct addrinfo *addr;
439
+					for (addr = addrinfo; addr != NULL; addr = addr->ai_next) {
440
+						struct sockaddr_in *ipv4 = (struct sockaddr_in *)addr->ai_addr;
441
+						if (!ts->camd.server_addr.s_addr) // Get the first IP address
442
+							ts->camd.server_addr = ipv4->sin_addr;
443
+						num_addrs++;
444
+					}
445
+					freeaddrinfo(addrinfo);
446
+					if (num_addrs)
447
+						server_err = 0;
448
+				}
432 449
 				break;
433 450
 			case 'U': // --camd-user
434 451
 				if (strlen(optarg) < 64)
@@ -530,7 +547,7 @@ static void parse_options(struct ts *ts, int argc, char **argv) {
530 547
 		if (ca_err)
531 548
 			fprintf(stderr, "ERROR: Requested CA system is unsupported.\n");
532 549
 		if (server_err)
533
-			fprintf(stderr, "ERROR: CAMD server IP address is not set or it is invalid.\n");
550
+			fprintf(stderr, "ERROR: CAMD server address is not set or it is invalid.\n");
534 551
 		if (input_addr_err)
535 552
 			fprintf(stderr, "ERROR: Input IP address is invalid.\n");
536 553
 		if (output_addr_err)

Loading…
Cancel
Save