pjbnc

This page is about my replacement for netcat.

The key differences between the netcat (nc) and my program (pjbnc) are:

 ncpjbnc
ProtocolsTCP (including TELNET), UDPTCP only
DebuggingPacket hex dumpNone
EOFTerminates after inactivity timeout on remaining channelCloses that half of the TCP connection using shutdown()
Read errorsfd closedfd closed, error logged, non-zero exit status
Write errorsfd closed after 8200 attempts to write, non-zero exit statusfd closed, error logged, non-zero exit status
Multiple A recordsUses first address onlyOn connect, tries all addresses
On listen, binds to all addresses
Arbitrary limitsFails with fds > 16None
Process modelsingle 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.

Download

Source: pjbnc-1.0.tar.bz2
Browse sources
Binaries: pjbnc

Valid HTML 4.01! Valid CSS!

Peter Benie <peterb@chiark.greenend.org.uk>
Linux