[Botan-devel] Sending raw, unencoded data over a network

Z. S. O. tiredashell at gmail.com
Mon Apr 13 15:23:14 EDT 2009


Yes, recv returns the actual data size, but that's after it has already been
copied into the buffer. It looks like this:
int len = recv(socket, buffer, 1024);

So buffer already will only contain part of the data, and the rest is
presumably lost. I'm trying to ask this on a networking-oriented mailing
list because I don't want to bother you with off-topic questions, but if you
have experience with this I'm open to any suggestions. Thanks.

On Mon, Apr 13, 2009 at 12:41 PM, Jack Lloyd <lloyd at randombit.net> wrote:

> On Mon, Apr 13, 2009 at 10:50:45AM -0400, Z. S. O. wrote:
> > I'm making a program that encrypts something using Botan and sends it
> > somewhere over UDP. The problem is that, if the encrypted data is not
> > encoded in something like Base64, the recipient won't always get all the
> > data. My theory is that sometimes there is a null byte in the encrypted
> > data, so when the recipient tries to copy it to a char array it gets cut
> off
> > early. Encoding the encrypted data in Base64 solves the problem, but it
> > dramatically increases the size of the data so I don't prefer it. Is
> there a
> > solution to this?
>
> This seems expected - using \0 terminators with arbitrary binary data
> usually leads to trouble. The conventional technique would be to
> include an explict length field at the beginning of the packet, and
> always copy exactly this amount the buffer. However UDP includes the
> length field in the packet header already, so there actually isn't any
> need to do that - recv or recvmsg will return the length of the packet
> when you read it out from the socket buffer. Hope this helps.
>
> -Jack
> _______________________________________________
> botan-devel mailing list
> botan-devel at randombit.net
> http://lists.randombit.net/mailman/listinfo/botan-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.randombit.net/pipermail/botan-devel/attachments/20090413/c9e0e4bc/attachment.html>


More information about the botan-devel mailing list