From d3e22101f0fd3e398a9d5fff801d68aec8db98a5 Mon Sep 17 00:00:00 2001 From: Alexander Babayants Date: Fri, 9 Apr 2021 00:42:32 +0300 Subject: [PATCH 1/3] Actually use netcat provided by NC env var --- dhcp.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dhcp.sh b/dhcp.sh index a8de9c2..d1c7cb7 100755 --- a/dhcp.sh +++ b/dhcp.sh @@ -93,7 +93,7 @@ fi # Handle requests while server is running while [[ "$RUNNING" == "1" ]]; do # One netcat handles only one broadcast packet - nc -lup 67 -w0 | stdbuf -o0 od -v -w1 -t x1 -An | { + "$NC" -lup 67 -w0 | stdbuf -o0 od -v -w1 -t x1 -An | { function read_dhcp() { # Read beginning with constant size @@ -232,7 +232,7 @@ while [[ "$RUNNING" == "1" ]]; do for i in ${raw_opt[*]}; do printf "\x$i" >> /tmp/dhcp.payload done - cat /tmp/dhcp.payload | nc -ub 255.255.255.255 68 -s $SERVER -p 67 -w0 + cat /tmp/dhcp.payload | "$NC" -ub 255.255.255.255 68 -s $SERVER -p 67 -w0 [[ "$DEBUG" != "1" ]] && rm /tmp/dhcp.payload } From 6ce84eaec091c8c44379ab2052987e19333ad817 Mon Sep 17 00:00:00 2001 From: Alexander Babayants Date: Fri, 9 Apr 2021 00:46:55 +0300 Subject: [PATCH 2/3] Improve netcat detection (support Fedora-flavor of OpenBSD netcat) --- dhcp.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dhcp.sh b/dhcp.sh index d1c7cb7..7896949 100755 --- a/dhcp.sh +++ b/dhcp.sh @@ -61,7 +61,7 @@ while getopts "s:m:i:g:l:p:hd" opt; do esac done -if [[ $($NC -h 2>&1 | head -1 | grep -q OpenBSD; echo $?) == "1" ]]; then +if [[ $("$NC" -w 0 2>&1 | head -1 | grep -q "nvalid.*time"; echo $?) == "0" ]]; then echo "Not supported nc." echo "This solution works only with OpenBSD netcat." echo "Your netcat: $NC" From 3ad923f8d249970858ff9ba676eef3f5cf384b5e Mon Sep 17 00:00:00 2001 From: Alexander Babayants Date: Fri, 9 Apr 2021 00:59:36 +0300 Subject: [PATCH 3/3] Fix port selection syntax --- dhcp.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dhcp.sh b/dhcp.sh index 7896949..2daf553 100755 --- a/dhcp.sh +++ b/dhcp.sh @@ -93,7 +93,7 @@ fi # Handle requests while server is running while [[ "$RUNNING" == "1" ]]; do # One netcat handles only one broadcast packet - "$NC" -lup 67 -w0 | stdbuf -o0 od -v -w1 -t x1 -An | { + "$NC" -ul 67 -w0 | stdbuf -o0 od -v -w1 -t x1 -An | { function read_dhcp() { # Read beginning with constant size