Variable length packets?

Dan Nelson dnelson at allantgroup.com
Mon Aug 30 19:11:00 PDT 2004


In the last episode (Aug 30), Lucas (a.k.a T-Bird or bsdfan3) said:
> I am trying to implement a custom protocol that sends and receives
> variable-length packets on top of TCP/IPv4.  The problem is that the
> length field of the packet is silently being mangled first becoming 0
> and then getting turned into a very large number (about 2-3 billion). 
> The length field is a u_int32_t and I am using the byteorder
> routines.  Source code snippets follow:
> 
> --decl of struct packet_t--
> struct packet_t
> {
>  u_int16_t num;
>  u_int32_t len;
>  char data[0];
> };

If these are different OSes, the structure may be packed differently.
There's almost certainly two bytes of padding between num and len to
ensure that len is 32-bit aligned, for example.

If you run ktrace on your client (or server), the kdump output will
include a hexdump of all data read or written, which might help you
determine what's going wrong.

-- 
	Dan Nelson
	dnelson at allantgroup.com


More information about the freebsd-questions mailing list