Reputation: 365
While I am trying to send data from Linux Client to Server over TCP I see extra zeros being added to the data. Can anyone please let me know why am I getting those additional zeroes? Please see below for the data packet format.
#define INT32 int32_t
#define UCHAR unsigned char
#define UINT8 u_int8_t
typedef struct cstruct_t {
UINT8 typ;
UINT8 l;
unsigned char buf[20];
} cksum_t;
cstruct_t cs;
INT32 fnlength;
Upvotes: 0
Views: 404
Reputation: 365
Since we dint want to add additional zeroes to make it 4-byte long as mentioned by @Soren we used
#pragma pack(push, 1)
#pragma pack(pop)
This worked perfectly for us.
Upvotes: 0
Reputation: 310956
Linux socket transfer is adding extra zero padding
No it certainly is not. You probably aren't reading it correctly. London to a brick you are ignoring the value returned by recv()
.
But you shouldn't be using a struct
as a network protocol in the first place.
Upvotes: 2