Partial Packets in NIO ?

LOL. At the ACCU conference, I read all of the security books. They’re all crap.

One particularly memorable one has “world’s best security reference” as part of the cover text. And yet, with a whole chapter on Samba, it “forgets” to mention the hashing scheme used by Samba - MD4, otherwise known as “crackable by any moron in approximately 3 hours, and soon to be crackable instantaneously, we’re just waiting for the freely available kit to be completed”.

This is quite apart from failing to explain the key elements of the SMB password system, and the main gotchas, DESPITE the fact that I know they are written in to the manpages!

So much crap out there in books. Sigh.

I have used two terminator methods in packets over NIO socket.
a) terminator byte
I’ve usually used 0x00 (NULL) byte at the end of packet. Then I just read until a terminator is found and handle the completed packet. You cannot send random binary data this way if it might contain null bytes within data. Text based packets usually are fine.

b) length terminated
send length of data at the start of each packet, then read given num of bytes and handle the completed packet. Handles any random binary data.

Writing back to non-blocking socket is quite hard as you need to handle all-or-nothing pattern. I’ve added inQueue and outQueue lists to a socket class and queue pending outgoing packets. Then I just take oldest one and write it until bytebuffer.available() returns false. I use Selector OP_WRITE to flag writable sockets. Soon as I’ve completed all outgoing packets I remove OP_WRITE and socket is kept in OP_READ mode.

That’s good to know. I’ve been wondering whether sizing my ByteBuffer to suit my packets, would leave me open to buffer overruns, if a spurious large 3rd party packet arrived.

Alan