char* quickrecv(SOCKET* sock) {
int ilen;
char* len = (char*)malloc(4);
recv(*sock, len, 4, 0);
memcpy(&ilen, len, sizeof(ilen));
char* buf = (char*)malloc(ilen);
//no matter what value ilen is, sizeof buf is always 4 when it shouldn't be
recv(*sock, buf, ilen, 0);
return buf;
}
Hello everyone! Bit of a noob question here. I am creating a simple socket protocol in c++ for fun. I tried making a receive function for convenience however it is not working. When I receive the data, it either adds characters to the output to make the output four characters long or it cuts off the output so it is only four characters long. I did some debugging and apparently my char pointer "buf" is only the size of four bytes. Even though "ilen" is different every time (I checked with printf), buf ends up only being four bytes of allocated memory. Why is the size of buf only four even though the parameter for malloc is different everytime? Thank you!