当我试图通过TCP将数据从Linux客户机发送到服务器时,我看到额外的零被添加到数据中。有人能告诉我为什么我会得到那些额外的零吗?数据包格式见下文。

#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;

最佳答案

Linux套接字传输正在添加额外的零填充
不,当然不是。你可能读得不对。你忽略了recv()返回的值。
但首先不应该使用struct作为网络协议。

10-06 06:22