|
-
February 17th, 2009, 04:40 PM
#1
[resolved] transfer an unsigned byte
Hi all,
I don't know how I solve the problem, but the problem magically disappeared.... :/
///////////////////////////////////////////
Hi all,
I am using C/C++ to construct and transmit packet to a server, and I am having trouble sending the correct byte if the value is greater than decimal 127.
Let's say this is the layout of my packet:
Code:
typedef struct
{
BYTE bHeader ;
BYTE bText1 ;
char szText2[ 5 ] ;
char szText3[ 2 ] ;
BYTE bText4 ;
unsigned char cText5 ;
} ClientToServer ;
cText5 may occasionally contain an unsigned value, so I use "unsigned char" as its data type.
When I run through my code in debug mode, I see cText5 is equal to 204, then I send the whole packet with the send() API:
Code:
send( sock, ( char* )&ClientToServer , sizeof( ClientToServer ), 0 ) ;
However, when I perform a packet capture, it shows that the last byte I sent, which is cText5, is equal to 1
Does anyone have an idea what I did wrong?
Thank you,
kab
Last edited by kabilius; February 17th, 2009 at 06:31 PM.
-
February 22nd, 2009, 04:04 AM
#2
Re: transfer an unsigned byte
I hope what you have done is
ClientToServer cltosv;
...
send( sock, ( char* )&cltosv , sizeof( ClientToServer ), 0 ) ;
You could also try to put #pragma pack(1) before declaring the structure.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|