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 2008-02-25 19:01:50.000000000 -0500 +++ netcat-1.10/netcat.c 2008-06-19 16:46:19.000000000 -0400 @@ -1360,6 +1360,28 @@ 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 @@ 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 @@ -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 */