support named ports with dashes in them
Normally netcat treats dashes as port ranges (e.g. "ssh-http"), but there are port names with dashes in them (e.g. "ftp-data"). Allow users to escape the dashes to support the latter mode.
This commit is contained in:
parent
3807536449
commit
af2ec70280
40
netcat.c
40
netcat.c
|
@ -1840,6 +1840,28 @@ options:");
|
||||||
} /* helpme */
|
} /* helpme */
|
||||||
#endif /* HAVE_HELP */
|
#endif /* HAVE_HELP */
|
||||||
|
|
||||||
|
/* unescape :
|
||||||
|
translate \-'s into -'s, returns start */
|
||||||
|
char * unescape (start)
|
||||||
|
char * start;
|
||||||
|
{
|
||||||
|
char * end;
|
||||||
|
char * next;
|
||||||
|
char * p;
|
||||||
|
|
||||||
|
end = start + strlen (start);
|
||||||
|
next = start;
|
||||||
|
|
||||||
|
while ((next = strstr (next+1, "\\-"))) {
|
||||||
|
p = next;
|
||||||
|
/* copy string back one char, overwriting backslash */
|
||||||
|
memmove (p, p+1, end-p);
|
||||||
|
end--;
|
||||||
|
}
|
||||||
|
|
||||||
|
return start;
|
||||||
|
} /* unescape */
|
||||||
|
|
||||||
/* main :
|
/* main :
|
||||||
now we pull it all together... */
|
now we pull it all together... */
|
||||||
int
|
int
|
||||||
|
@ -2168,13 +2190,21 @@ Debug (("after go: x now %c, optarg %x optind %d", x, optarg, optind))
|
||||||
argument, so we can control the pattern somewhat. */
|
argument, so we can control the pattern somewhat. */
|
||||||
while (argv[optind]) {
|
while (argv[optind]) {
|
||||||
hiport = loport = 0;
|
hiport = loport = 0;
|
||||||
|
/* I know it's ugly to have this test twice, but I'd rather not have
|
||||||
|
it do all of the dash code if there aren't any dashes at all */
|
||||||
cp = strchr (argv[optind], '-'); /* nn-mm range? */
|
cp = strchr (argv[optind], '-'); /* nn-mm range? */
|
||||||
if (cp) {
|
if (cp) {
|
||||||
*cp = '\0';
|
while (cp && *(cp-1) == '\\') /* if dash escaped by backslash */
|
||||||
cp++;
|
cp = strchr (cp+1, '-');
|
||||||
hiport = getportpoop (cp, 0);
|
|
||||||
if (hiport == 0)
|
if (cp) { /* it's a range */
|
||||||
bail ("invalid port %s", cp);
|
*cp = '\0';
|
||||||
|
unescape (++cp); /* turn \-'s into -'s */
|
||||||
|
hiport = getportpoop (cp, 0);
|
||||||
|
if (hiport == 0)
|
||||||
|
bail ("invalid port %s", cp);
|
||||||
|
}
|
||||||
|
unescape (argv[optind]); /* turn \-'s into -'s */
|
||||||
} /* if found a dash */
|
} /* if found a dash */
|
||||||
loport = getportpoop (argv[optind], 0);
|
loport = getportpoop (argv[optind], 0);
|
||||||
if (loport == 0)
|
if (loport == 0)
|
||||||
|
|
Loading…
Reference in New Issue