Bug 294334 - nc(1) doesn't print any error message when connection is refused
Summary: nc(1) doesn't print any error message when connection is refused
Status: Closed Works As Intended
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 15.0-STABLE
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2026-04-08 15:42 UTC by Yuri Victorovich
Modified: 2026-04-11 19:38 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Yuri Victorovich freebsd_committer freebsd_triage 2026-04-08 15:42:43 UTC
Example:

> $ telnet ollama.org 12499
> Trying 176.123.6.177...
> telnet: connect to address 176.123.6.177: Connection refused
> telnet: Unable to connect to remote host
> $ nc ollama.org 12499 
> $ echo $?
> 1
> $ 

telnet prints the correct error message, but nc doesn't. nc just fails with exit_code=1.
Comment 1 Dag-Erling Smørgrav freebsd_committer freebsd_triage 2026-04-11 19:38:31 UTC
This is intentional: netcat is designed to try any number of addresses and ports until one succeeds (for instance, if you give it a host name which resolves to multiple addresses) and there is no correct answer to the question of which error(s) to report in such a scenario: all, or just one?  If just one, which one?  What if one is more significant than the others?  etc.

Use the -v option if you want explicit error messages for every failed operation.