1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
Summary: Allow ports with dashes in the human-readable name to be
specified as such rather than attempting to parse them as
ranges.
Contributor: Mike Sullivan <msully4321@gmail.com>
Index: netcat-1.10/netcat.c
===================================================================
--- netcat-1.10.orig/netcat.c
+++ netcat-1.10/netcat.c
@@ -1360,6 +1360,28 @@ Debug (("wrote %d to net, errno %d", rr,
return (0);
} /* readwrite */
+/* 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;
+ while (p < end) /* copy string back one char, overwriting backslash */
+ *(p++) = *(p+1);
+ end--;
+ }
+
+ return start;
+} /* unescape */
+
/* main :
now we pull it all together... */
main (argc, argv)
@@ -1627,13 +1649,21 @@ Debug (("after go: x now %c, optarg %x o
argument, so we can control the pattern somewhat. */
while (argv[optind]) {
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? */
if (cp) {
- *cp = '\0';
- cp++;
- hiport = getportpoop (cp, 0);
- if (hiport == 0)
- bail ("invalid port %s", cp);
+ while (cp && *(cp-1) == '\\') /* if dash escaped by backslash */
+ cp = strchr (cp+1, '-');
+
+ if (cp) { /* it's a range */
+ *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 */
loport = getportpoop (argv[optind], 0);
if (loport == 0)
@@ -1746,7 +1776,8 @@ options:");
-v verbose [use twice to be more verbose]\n\
-w secs timeout for connects and final net reads\n\
-z zero-I/O mode [used for scanning]");
- bail ("port numbers can be individual or ranges: lo-hi [inclusive]");
+ bail ("port numbers can be individual or ranges: lo-hi [inclusive];\n\
+hyphens in port names must be backslash escaped (e.g. 'ftp\\-data').");
} /* helpme */
#endif /* HAVE_HELP */
|