Hi I designed a code to get the length of unknown data coming in to the socket I need help because I can't find where my code get stuck in this function. Thanks for any help
int recvlen(int s){ //peak all received data and returns the length
char *request;
int total;
total= 1024;//initial size
int numbytes;
printf("\n entered recvlen\n");
while(1){
if(( request= (char *)realloc(request,sizeof(char)*total+1)) <=0){
fprintf(stderr,"error in realloc no memory or fail");
return -1;
}
if((numbytes= recv(s,request,sizeof(request),MSG_PEEK))==-1){//get request
fprintf(stderr,"\n error in receiveall \n");
free(request);
return -1;
}
if(numbytes != strlen(request)){
total = numbytes+1;
free(request);
printf("\n recvlen returned total: %d\n",total);
return total;//when the size is found
}
total += total;
}
}