我想向服务器发送请求,但是Python以某种方式将4字节值转换为8字节值:
struct.pack("H", socket.ntohs(v1)) + struct.pack("?", v2) + struct.pack("?", v3) + struct.pack("L", socket.ntohl(v5)) + struct.pack("L", socket.ntohl(v6)) + struct.pack("L", socket.ntohl(v7)) + struct.pack("L", socket.ntohl(v8)) + struct.pack("H", socket.ntohs(v9))直到v5,一切都很好,但是在v5之后,我总是得到8字节的值,而不是4 4Bytes。Wireshark捕获:高达0003 e8,一切正常:
0040 4d 65 01 00 00 00 01 00 00 01 01 00 00 03 e8 00 Me...... ........
0050 00 00 00 00 00 07 d0 00 00 00 00 00 00 0b b8 00 ........ ........
0060 00 00 00 00 00 0f a0 00 00 00 00 13 88 00 00 00 ........ ........发布于 2014-03-26 15:46:00
由于不指定其他方法,所以您使用的是long的本机表示形式。尝试添加=说明符(本机字节顺序,标准大小):
struct.pack("=H??LLLLH",
socket.ntohs(v1),
v2,
v3,
socket.ntohl(v5),
socket.ntohl(v6),
socket.ntohl(v7),
socket.ntohl(v8),
socket.ntohs(v9))参考文献:
https://stackoverflow.com/questions/22665833
复制相似问题