Re: [dev] network protocol packing

2014-07-01 Thread Markus Wichmann
On Mon, Jun 30, 2014 at 08:54:52PM +0200, Markus Teich wrote: > Heyho, > > since I did not find any suckless project regarding this issue, I would like > to > ask you guys for some feedback: > > > unsigned char *msg; > size_t msg_size; > struct foo *msg_data; > struct bar *msg_signature; > > m

Re: [dev] network protocol packing

2014-07-01 Thread Steve Dee
On Tue, Jul 1, 2014 at 8:01 AM, Markus Teich wrote: > Rob wrote: >> You've got alignment issues here - msg will be aligned to support any >> type (as malloc's interface specifies) so msg+1 will most likely be on >> an odd address, one byte off a highly aligned address. This means if >> your struct

Re: [dev] network protocol packing

2014-07-01 Thread Dimitris Papastamos
On Tue, Jul 01, 2014 at 05:01:43PM +0200, Markus Teich wrote: > Rob wrote: > > You've got alignment issues here - msg will be aligned to support any > > type (as malloc's interface specifies) so msg+1 will most likely be on > > an odd address, one byte off a highly aligned address. This means if >

Re: [dev] network protocol packing

2014-07-01 Thread Markus Teich
Rob wrote: > You've got alignment issues here - msg will be aligned to support any > type (as malloc's interface specifies) so msg+1 will most likely be on > an odd address, one byte off a highly aligned address. This means if > your struct contains anything other than chars, you'll have UB. This i

Re: [dev] network protocol packing

2014-07-01 Thread Dimitris Papastamos
On Tue, Jul 01, 2014 at 01:56:04PM +0200, Markus Teich wrote: > struct msg_signed_data { > unsigned int op; > struct foo data; > struct bar signature; > }; If this is data that goes across the network then instead of directly mapping a struct on that data I'd simply have function

Re: [dev] network protocol packing

2014-07-01 Thread Martti Kühne
On Tue, Jul 1, 2014 at 2:56 PM, Markus Teich wrote: > thanks for your feedback. What about declaring a struct for each message-type: > > struct msg_signed_data { > unsigned int op; > struct foo data; > struct bar signature; > }; > > This should also solve the alignment issu

Re: [dev] network protocol packing

2014-07-01 Thread Markus Teich
Rob wrote: > You've got alignment issues here - msg will be aligned to support any > type (as malloc's interface specifies) so msg+1 will most likely be on > an odd address, one byte off a highly aligned address. This means if > your struct contains anything other than chars, you'll have UB. This i

Re: [dev] network protocol packing

2014-06-30 Thread Steve Dee
See also: https://kentonv.github.io/capnproto/

Re: [dev] network protocol packing

2014-06-30 Thread Rob
On 30/06/14, Markus Teich wrote: Heyho, Hello there, since I did not find any suckless project regarding this issue, I would like to ask you guys for some feedback: unsigned char *msg; size_t msg_size; struct foo *msg_data; struct bar *msg_signature; msg_size = sizeof(unsigned char)

[dev] network protocol packing

2014-06-30 Thread Markus Teich
Heyho, since I did not find any suckless project regarding this issue, I would like to ask you guys for some feedback: unsigned char *msg; size_t msg_size; struct foo *msg_data; struct bar *msg_signature; msg_size = sizeof(unsigned char)// op + sizeof(struct foo)// data