L
Lothar Behrens
Hi,
I have a client that sends a structure like this:
typedef struct packet_struct{
int16_t p1
int16_t p2
u_int32_t p3;
int16_t p4
char buffer[10240];
}packet;
The packet structure gets filled with random values and then filled
with the real values. The string is a null terminated C string. Then
the buffer gets sent over the wire with a buffer size of 10252 via
sizeof().
After figuring out that the alingment fools me I changed my
ClientSocket recieve buffer size to 10252.
Now I get random bytes at the end of the string in my recived buffer
like this:
int bufferSize = 10252;
myClientSocket.ReceiveBufferSize = bufferSize;
byte[] buffer = new byte[bufferSize];
lock (parameterCarrier)
{
int status = myClientSocket.Receive(buffer);
To avoid this and because there is an alingment, I strip the last two
bytes of the buffer part.
I got this because of sniffing the packet sent over the wire and I
have seen the starting of the buffer with an
offset of ten bytes.
Thus I assume the alingment is done at the end of the structure at all
and thus I get the random values.
Is that correct, or do I have trapped another pittfall?
Thanks
Lothar
I have a client that sends a structure like this:
typedef struct packet_struct{
int16_t p1
int16_t p2
u_int32_t p3;
int16_t p4
char buffer[10240];
}packet;
The packet structure gets filled with random values and then filled
with the real values. The string is a null terminated C string. Then
the buffer gets sent over the wire with a buffer size of 10252 via
sizeof().
After figuring out that the alingment fools me I changed my
ClientSocket recieve buffer size to 10252.
Now I get random bytes at the end of the string in my recived buffer
like this:
int bufferSize = 10252;
myClientSocket.ReceiveBufferSize = bufferSize;
byte[] buffer = new byte[bufferSize];
lock (parameterCarrier)
{
int status = myClientSocket.Receive(buffer);
To avoid this and because there is an alingment, I strip the last two
bytes of the buffer part.
I got this because of sniffing the packet sent over the wire and I
have seen the starting of the buffer with an
offset of ten bytes.
Thus I assume the alingment is done at the end of the structure at all
and thus I get the random values.
Is that correct, or do I have trapped another pittfall?
Thanks
Lothar