Change how client option -s interprets ':'
Old version recognizes the first ':', which prevents use of ':' in host names. They are used in numerical IPv6 addresses. New version recognizes the last ':', which prevents use of ':' in service names. Old version treats empty host or port specially (use default). Documentation suggests ':' is required, but the code doesn't do that. Instead, the argument is interpreted as host, even when it's empty. New version makes the HOST: part optional. You can't specify host and default the port. Tough. Keeps documentation and code as simple as possible. Compare: old version new version argument host port host port "" "" default default "" "A" "A" default default "A" ":" default default "" "" "A:" "A" default "A" "" ":B" default "B" "" "B" "A:B" "A" "B" "A" "B"
This commit is contained in:
parent
f4fe7da1fb
commit
464094a693
2 changed files with 10 additions and 17 deletions
|
@ -37,11 +37,8 @@ Help. Print brief usage information and exit.
|
||||||
.B \-k
|
.B \-k
|
||||||
If someone else is connected to your country, kill their connection.
|
If someone else is connected to your country, kill their connection.
|
||||||
.TP
|
.TP
|
||||||
.BI \-s " host:port"
|
.BI \-s " [host:]port"
|
||||||
Specify host and port to which to connect.
|
Specify server \fIhost\fR and \fIport\fR.
|
||||||
.IP
|
|
||||||
Connect to \fIhost\fR using port \fIport\fR. You can specify only
|
|
||||||
one; just leave the other empty (include the colon).
|
|
||||||
.TP
|
.TP
|
||||||
.B \-u
|
.B \-u
|
||||||
Use UTF-8 rather than ASCII character set.
|
Use UTF-8 rather than ASCII character set.
|
||||||
|
|
|
@ -69,7 +69,7 @@ print_usage(char *program_name)
|
||||||
printf("Usage: %s [OPTION]...[COUNTRY [PASSWORD]]\n"
|
printf("Usage: %s [OPTION]...[COUNTRY [PASSWORD]]\n"
|
||||||
" -2 FILE Append log of session to FILE\n"
|
" -2 FILE Append log of session to FILE\n"
|
||||||
" -k Kill connection\n"
|
" -k Kill connection\n"
|
||||||
" -s HOST:PORT Set host and port to connect\n"
|
" -s [HOST:]PORT Specify server HOST and PORT\n"
|
||||||
" -u Use UTF-8\n"
|
" -u Use UTF-8\n"
|
||||||
" -h display this help and exit\n"
|
" -h display this help and exit\n"
|
||||||
" -v display version information and exit\n",
|
" -v display version information and exit\n",
|
||||||
|
@ -89,6 +89,7 @@ main(int argc, char **argv)
|
||||||
char *country;
|
char *country;
|
||||||
char *passwd;
|
char *passwd;
|
||||||
char *uname;
|
char *uname;
|
||||||
|
char *colon;
|
||||||
int sock;
|
int sock;
|
||||||
|
|
||||||
while ((opt = getopt(argc, argv, "2:ks:uhv")) != EOF) {
|
while ((opt = getopt(argc, argv, "2:ks:uhv")) != EOF) {
|
||||||
|
@ -100,17 +101,12 @@ main(int argc, char **argv)
|
||||||
send_kill = 1;
|
send_kill = 1;
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
host = strdup(optarg);
|
port = strdup(optarg);
|
||||||
port = strchr(host, ':');
|
colon = strrchr(port, ':');
|
||||||
if (port == host) { /* if no host specified, then set to null */
|
if (colon) {
|
||||||
host = NULL;
|
*colon = 0;
|
||||||
}
|
host = port;
|
||||||
if (port) { /* make port the bit after the colon */
|
port = colon + 1;
|
||||||
port[0] = 0;
|
|
||||||
port++;
|
|
||||||
if (port[0] == 0) { /* handle colon-at-end-of-string */
|
|
||||||
port = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'u':
|
case 'u':
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue