Skip to content

Commit a5daab2

Browse files
author
olevole
committed
expose: continue to work, even if nc shows that the port is busy for UDP
1 parent c8debda commit a5daab2

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

tools/expose

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ pf_del()
201201

202202
fw_expose_add()
203203
{
204-
local _ret _inaddr
204+
local _ret= _inaddr= _res= _test=
205205

206206
[ "${inaddr}" = "nodeip" ] && inaddr="0"
207207

@@ -242,16 +242,27 @@ fw_expose_add()
242242

243243
case "${proto}" in
244244
tcp)
245-
res=$( ${NC_CMD} -w1 -z ${_inaddr} ${in} 2>/dev/null )
245+
_test="${NC_CMD} -w1 -z ${_inaddr} ${in}"
246246
;;
247247
udp)
248-
res=$( ${NC_CMD} -u -w1 -z ${_inaddr} ${in} 2>/dev/null )
248+
_test="${NC_CMD} -u -w1 -z ${_inaddr} ${in}"
249249
;;
250250
esac
251251

252-
if [ $? -eq 0 ]; then
253-
${ECHO} "${W1_COLOR}${CBSD_APP} warning: ${N1_COLOR}port already in use on ${_inaddr}: ${N2_COLOR}${proto}/${in}${N0_COLOR}"
254-
return 1
252+
${_test} 2>/dev/null
253+
_ret=$?
254+
255+
if [ ${_ret} -eq 0 ]; then
256+
${ECHO} "${W1_COLOR}${CBSD_APP} warning: ${N1_COLOR}port already in use on ${_inaddr}?: ${N2_COLOR}${proto}/${in}${N0_COLOR}"
257+
case "${proto}" in
258+
tcp)
259+
${ECHO} "${N1_COLOR}Test string: '${N2_COLOR}${_test}${N1_COLOR}' (check errcode)${N0_COLOR}"
260+
return 1
261+
;;
262+
udp)
263+
${ECHO} "${N1_COLOR}Test string: '${N2_COLOR}${_test}${N1_COLOR}' (check errcode). Possible false positive for UDP, let's try to continue${N0_COLOR}"
264+
;;
265+
esac
255266
fi
256267

257268
if [ -z "${fromips}" ]; then

0 commit comments

Comments
 (0)