This is a design flaw in the nmap version of
ncat that is used in RHEL7. I am looking at the source code of version 7.70 (RHEL7 is 7.50, Fedora 28 is 7.60 and I don't think this aspect of the code will have changed much between that and 7.70).
ncat_connect.c I can see code to:
- exit after EOF on stdin in
- exit after EOF on the socket in
but, if in neither
--recv-only mode, there is nothing in
ncat_connect.c to handle exit when we've seen EOF on both stdin and the socket.
So we look at the lower-level code in
nsock_loop function. This loop will quit if
ms->quit it set (by the above-mentioned
--recv-only code) or if there are no
But here's the bug: the timeout counts in events_pending. So
nsock_loop goes "OK, I know stdin has been EOF'd and the socket has been EOF'd, but I'm still not going to quit yet, because there's still an event pending" (the timeout), so it just sits there until the timeout fires and then nc error-exits, even if everything has actually worked just fine.
So I think we should submit a bug report directly to nmap (not to your distro: they are likely to say "that's upstream behaviour we are not qualified to evaluate", whereas upstream maintainers will be able to evaluate it): we point out that the above design effectively means
-i is useless unless either (1) used along with
--recv-only or (2) used in a situation where
nc's error code is ignored.
Meanwhile, one of the following workarounds might help:
--recv-only (if appropriate to your use-case),
- Wrap the
nc command in a
timeout command instead of using
- Manually install a different version of
nc, such as GNU Netcat or the original nc-1.10—but to do this on RHEL7 or Fedora 28 you will need to install manually, as packages (currently) provide only