On Sat, 22 Dec 2018 19:29:01 -0500, "Ted Unangst" <t...@tedunangst.com> wrote:
> Stuart Henderson wrote: > > But I can't imagine scanning a range by name as being much used > > (tcpmux-socks or something just doesn't make sense). > > > > What I think would be least disruptive is to continue to allow - > > where the rest of the parameter is numeric. For alphabetic > > parameters try parsing the whole word as a service; use it if > > valid. If not, *either* it could just error out (simple and > > unambiguous) *or* it could try parsing as a named range. But I > > don't think you will hurt anyone by just erroring out in that > > case. > > This is my attempt at that. I think it is the most sensible approach. Because otherwise someone will probably complain that they tried `nc -z ms-sql-s-ms-sql-m` and it didn't work. I didn't want to manually test all the diffs for all the cases so I wrote a regress test. The tests listen on ms-sql-s 1433/tcp Microsoft-SQL-Server ms-sql-m 1434/tcp Microsoft-SQL-Monitor because I think it's unlikely someone runs that on the machine where the regress tests run and there's plenty of dash for testing. I tried all the diff—genuine being nc without any patch and the one called "sthedu" is the one tedu made based on the suggestion from sthen ;). The results are: testing patch from genuine # nc is /usr/src/usr.bin/nc/nc-genuine FAILED: test number 2 with ms-sql-s with norange FAILED: test number 2 with ms-sql-m with norange FAILED: test number 4 with ms-sql-s with range-dash FAILED: test number 4 with ms-sql-m with range-dash FAILED: test number 5 with 1433 with range-colon FAILED: test number 5 with 1434 with range-colon FAILED: test number 6 with ms-sql-s with range-colon FAILED: test number 6 with ms-sql-m with range-colon *** Error 1 in /usr/src/regress/usr.bin/nc (Makefile:6 'regress': env NC=/usr/src/usr.bin/nc/nc-genuine sh /usr/src/regress/usr.bin/nc/regre...) testing patch from jca # nc is /usr/src/usr.bin/nc/nc-jca FAILED: test number 4 with ms-sql-s with range-dash FAILED: test number 4 with ms-sql-m with range-dash *** Error 1 in /usr/src/regress/usr.bin/nc (Makefile:6 'regress': env NC=/usr/src/usr.bin/nc/nc-jca sh /usr/src/regress/usr.bin/nc/regress.s...) testing patch from tedu # nc is /usr/src/usr.bin/nc/nc-tedu FAILED: test number 4 with ms-sql-s with range-dash FAILED: test number 4 with ms-sql-m with range-dash *** Error 1 in /usr/src/regress/usr.bin/nc (Makefile:6 'regress': env NC=/usr/src/usr.bin/nc/nc-tedu sh /usr/src/regress/usr.bin/nc/regress....) testing patch from sthedu # nc is /usr/src/usr.bin/nc/nc-sthedu FAILED: test number 4 with ms-sql-s with range-dash FAILED: test number 4 with ms-sql-m with range-dash FAILED: test number 5 with 1433 with range-colon FAILED: test number 5 with 1434 with range-colon FAILED: test number 6 with ms-sql-s with range-colon FAILED: test number 6 with ms-sql-m with range-colon *** Error 1 in /usr/src/regress/usr.bin/nc (Makefile:6 'regress': env NC=/usr/src/usr.bin/nc/nc-sthedu sh /usr/src/regress/usr.bin/nc/regres...) Diff for the regress tests inline or you can fetch the directory from https://chown.me/iota/nc.tgz jca told me running the regress tests multiple times lead to different results (it should not) but I haven't been able to reproduce it. Cheers, Daniel Index: nc/Makefile =================================================================== RCS file: nc/Makefile diff -N nc/Makefile --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ nc/Makefile 25 Dec 2018 18:25:22 -0000 @@ -0,0 +1,8 @@ +# $OpenBSD$ + +NC?=nc + +regress: + env NC=${NC} sh ${.CURDIR}/regress.sh + +.include <bsd.regress.mk> Index: nc/regress.sh =================================================================== RCS file: nc/regress.sh diff -N nc/regress.sh --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ nc/regress.sh 25 Dec 2018 18:25:22 -0000 @@ -0,0 +1,75 @@ +#!/bin/sh + +ret=0 +NC=${NC-nc} +echo "# nc is ${NC}" + +# ms-sql-s 1433/tcp Microsoft-SQL-Server +# ms-sql-m 1434/tcp Microsoft-SQL-Monitor + +clean(){ + if [ "${2}" = "numerals" ]; then + ports[0]=1433 + ports[1]=1434 + fi + if [ "${2}" = "names" ]; then + ports[0]=ms-sql-s + ports[1]=ms-sql-m + fi + for port in "${ports[@]}"; do + # if pkill found a nc process, that's not good + pkill -xf "${NC} -l ${port}" + if [ $? -ne 1 ]; then + echo "FAILED: test number ${1} with ${port} with ${3}" + ret=1 + fi + done +} + +listen(){ + ${NC} -l "${1}" & +} + +connect(){ + ${NC} -z localhost "${1}" 2> /dev/null +} + +# test 1: ports through numbers and without range +listen 1433 +listen 1434 +connect 1433 +connect 1434 +clean 1 numerals norange + +# test 2: ports through names and without range +listen ms-sql-s +listen ms-sql-m +connect ms-sql-s +connect ms-sql-m +clean 2 names norange + +# test 3: ports through numbers and with range with a dash +listen 1433 +listen 1434 +connect 1433-1434 +clean 3 numerals range-dash + +# test 4: ports through names and with range with a dash +listen ms-sql-s +listen ms-sql-m +connect ms-sql-s-ms-sql-m +clean 4 names range-dash + +# test 5: ports through numbers and with range with a colon +listen 1433 +listen 1434 +connect 1433:1434 +clean 5 numerals range-colon + +# test 6: ports through names and with range with a colon +listen ms-sql-s +listen ms-sql-m +connect ms-sql-s:ms-sql-m +clean 6 names range-colon + +exit $ret