문제

I want to send requests to a Server, but somehow Python converts 4Byte values to 8 byte Values:

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))

up to v5 everything works fine but after v5 i always get 8Byte values instead of 4Bytes. Wireshark Capturing: up 00 00 03 e8 everything works fine:

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   ........ ........
도움이 되었습니까?

해결책

Since you don't specify otherwise, you are using the native representation for your longs. Try adding the = specifier (native byte order, standard size):

struct.pack("=H??LLLLH",  
            socket.ntohs(v1),
            v2,
            v3,
            socket.ntohl(v5),
            socket.ntohl(v6),
            socket.ntohl(v7),
            socket.ntohl(v8),
            socket.ntohs(v9))

References:

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top