I used tcp to send a data to python server. The data is like:
struct protocol
{
unsigned char prot;
int id;
char name[32];
}
Look at the name
field, it is a null terminated string max size is 32. Now I use strcpy
.
protocol p;
memset(&p, 0, sizeof(p));
strcpy(name, "abc");
Now I unpack it using python.
prot,id,name = struct.unpack("@Bi32s")
Now the len(name)
is 32. But I need get the string of "abc"
when the length is 3.
How can I do that?