문제

I have a python client who packs some data doing this:

#MOUNT UDP PACKET (unsigned char type, 5 char ext, 50 char user)
pqtUDP = pack('B5s50s', REGISTER, ext, user) 

And now I'm receiving that on a C client, so to read correct data I suppose I have to unpack it and save it in different vars, no? How can I do it in C?

I need to read REGISTER, ext and user from received data.

도움이 되었습니까?

해결책

Something like this should work in C:

// assumes input packet is [const char* data]
unsigned char reg;
char ext[6];
char user[51];
reg = data[0];
memcpy(ext, data + 1, 5);
ext[5] = 0; // set null terminator
memcpy(user, data + 6, 50);
user[50] = 0; // set null terminator
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top