mirror of
https://repo.or.cz/socat.git
synced 2025-07-16 16:13:24 +00:00
Permit -dd; print a useful error message when single character options appear to be merged
This commit is contained in:
parent
fbd72c295d
commit
710c54a254
3 changed files with 71 additions and 15 deletions
45
socat.c
45
socat.c
|
@ -53,6 +53,7 @@ struct {
|
|||
};
|
||||
|
||||
void socat_usage(FILE *fd);
|
||||
void socat_opt_hint(FILE *fd, char a, char b);
|
||||
void socat_version(FILE *fd);
|
||||
int socat(const char *address1, const char *address2);
|
||||
int _socat(void);
|
||||
|
@ -108,7 +109,8 @@ int main(int argc, const char *argv[]) {
|
|||
arg1 = argv+1; --argc;
|
||||
while (arg1[0] && (arg1[0][0] == '-')) {
|
||||
switch (arg1[0][1]) {
|
||||
case 'V': socat_version(stdout); Exit(0);
|
||||
case 'V': if (arg1[0][2]) { socat_usage(stderr); Exit(1); }
|
||||
socat_version(stdout); Exit(0);
|
||||
#if WITH_HELP
|
||||
case '?':
|
||||
case 'h':
|
||||
|
@ -116,9 +118,21 @@ int main(int argc, const char *argv[]) {
|
|||
xioopenhelp(stdout, (arg1[0][2]=='?'||arg1[0][2]=='h') ? (arg1[0][3]=='?'||arg1[0][3]=='h') ? 2 : 1 : 0);
|
||||
Exit(0);
|
||||
#endif /* WITH_HELP */
|
||||
case 'd': diag_set('d', NULL); break;
|
||||
case 'd':
|
||||
a = *arg1+1;
|
||||
while (*a) {
|
||||
if (*a == 'd') {
|
||||
diag_set('d', NULL);
|
||||
} else {
|
||||
socat_usage(stderr);
|
||||
Exit(1);
|
||||
}
|
||||
++a;
|
||||
}
|
||||
break;
|
||||
#if WITH_FILAN
|
||||
case 'D': socat_opts.debug = true; break;
|
||||
case 'D': if (arg1[0][2]) { socat_opt_hint(stderr, arg1[0][1], arg1[0][2]); Exit(1); }
|
||||
socat_opts.debug = true; break;
|
||||
#endif
|
||||
case 'l':
|
||||
switch (arg1[0][2]) {
|
||||
|
@ -156,8 +170,10 @@ int main(int argc, const char *argv[]) {
|
|||
break;
|
||||
}
|
||||
break;
|
||||
case 'v': socat_opts.verbose = true; break;
|
||||
case 'x': socat_opts.verbhex = true; break;
|
||||
case 'v': if (arg1[0][2]) { socat_opt_hint(stderr, arg1[0][1], arg1[0][2]); Exit(1); }
|
||||
socat_opts.verbose = true; break;
|
||||
case 'x': if (arg1[0][2]) { socat_opt_hint(stderr, arg1[0][1], arg1[0][2]); Exit(1); }
|
||||
socat_opts.verbhex = true; break;
|
||||
case 'b': if (arg1[0][2]) {
|
||||
a = *arg1+2;
|
||||
} else {
|
||||
|
@ -169,7 +185,7 @@ int main(int argc, const char *argv[]) {
|
|||
}
|
||||
socat_opts.bufsiz = strtoul(a, (char **)&a, 0);
|
||||
break;
|
||||
case 's':
|
||||
case 's': if (arg1[0][2]) { socat_opt_hint(stderr, arg1[0][1], arg1[0][2]); Exit(1); }
|
||||
diag_set_int('e', E_FATAL); break;
|
||||
case 't': if (arg1[0][2]) {
|
||||
a = *arg1+2;
|
||||
|
@ -199,9 +215,12 @@ int main(int argc, const char *argv[]) {
|
|||
socat_opts.total_timeout.tv_usec =
|
||||
(rto-socat_opts.total_timeout.tv_sec) * 1000000;
|
||||
break;
|
||||
case 'u': socat_opts.lefttoright = true; break;
|
||||
case 'U': socat_opts.righttoleft = true; break;
|
||||
case 'g': xioopts_ignoregroups = true; break;
|
||||
case 'u': if (arg1[0][2]) { socat_opt_hint(stderr, arg1[0][1], arg1[0][2]); Exit(1); }
|
||||
socat_opts.lefttoright = true; break;
|
||||
case 'U': if (arg1[0][2]) { socat_opt_hint(stderr, arg1[0][1], arg1[0][2]); Exit(1); }
|
||||
socat_opts.righttoleft = true; break;
|
||||
case 'g': if (arg1[0][2]) { socat_opt_hint(stderr, arg1[0][1], arg1[0][2]); Exit(1); }
|
||||
xioopts_ignoregroups = true; break;
|
||||
case 'L': if (socat_opts.lock.lockfile)
|
||||
Error("only one -L and -W option allowed");
|
||||
if (arg1[0][2]) {
|
||||
|
@ -236,6 +255,7 @@ int main(int argc, const char *argv[]) {
|
|||
#if WITH_IP6
|
||||
case '6':
|
||||
#endif
|
||||
if (arg1[0][2]) { socat_opt_hint(stderr, arg1[0][1], arg1[0][2]); Exit(1); }
|
||||
xioopts.default_ip = arg1[0][1];
|
||||
xioopts.preferred_ip = arg1[0][1];
|
||||
break;
|
||||
|
@ -333,7 +353,7 @@ void socat_usage(FILE *fd) {
|
|||
fputs(" -hh like -h, plus a list of all common address option names\n", fd);
|
||||
fputs(" -hhh like -hh, plus a list of all available address option names\n", fd);
|
||||
#endif /* WITH_HELP */
|
||||
fputs(" -d increase verbosity (use up to 4 times; 2 are recommended)\n", fd);
|
||||
fputs(" -d[ddd] increase verbosity (use up to 4 times; 2 are recommended)\n", fd);
|
||||
#if WITH_FILAN
|
||||
fputs(" -D analyze file descriptors before loop\n", fd);
|
||||
#endif
|
||||
|
@ -363,6 +383,11 @@ void socat_usage(FILE *fd) {
|
|||
#endif
|
||||
}
|
||||
|
||||
void socat_opt_hint(FILE *fd, char a, char b) {
|
||||
fprintf(fd, "Do not merge single character options, i.e. use \"-%c -%c\" instead of \"-%c%c\"\n",
|
||||
a, b, a, b);
|
||||
}
|
||||
|
||||
|
||||
void socat_version(FILE *fd) {
|
||||
struct utsname ubuf;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue