This page is about my replacement for netcat.
The key differences between the netcat (nc) and my program (pjbnc) are:
nc | pjbnc | |
---|---|---|
Protocols | TCP (including TELNET), UDP | TCP only |
Debugging | Packet hex dump | None |
EOF | Terminates after inactivity timeout on remaining channel | Closes that half of the TCP connection using shutdown() |
Read errors | fd closed | fd closed, error logged, non-zero exit status |
Write errors | fd closed after 8200 attempts to write, non-zero exit status | fd closed, error logged, non-zero exit status |
Multiple A records | Uses first address only | On connect, tries all addresses On listen, binds to all addresses |
Arbitrary limits | Fails with fds > 16 | None |
Process model | single process, select loop, blocking I/O | single process, select loop, non-blocking I/O |
Despite appearances, nc will reliably detect write errors - 8200 attempts to do a blocking write cannot occur with its buffer size of 8192.
On the other hand, its handling of EOF is broken. Consider the case where you send a GET request to an HTTP server followed by EOF. nc may drop the connection before the server has had a chance to reply unless you set the timeout to be very large. A premature timeout is impossible for nc to detect so the problem won't be revealed in nc's exit status.
nc can cause deadlocks due to its use of blocking I/O. the other half of the connection needs to be read to unblock the system. For this reason, pjbnc uses non-blocking I/O. pjbnc will only stall if the remote application has also stalled; if deadlock occurs, it is because the protocol is unsound.
In practice, you are very unlikely to trip over nc's fd limit. This will only happen if the nc process inherits lots of fds such that the fds it allocates are too high for its fd_set.
pjbnc fixes the above problems, but it doesn't have anywhere near the functionality of nc. It may acquire additional functionality at some point in the future, but it is unlikely to ever have udp support since that doesn't fit naturally into pjbnc's model.
Source: | pjbnc-1.0.tar.bz2 Browse sources |
---|---|
Binaries: | pjbnc |
Peter Benie <peterb@chiark.greenend.org.uk>
Linux