I've written a recv loop function that looks like this:
It reaches the end (but sometimes not) of a GET request (eg, "...</html>") and then segfaults before "Recept () done" appears -- apparently in getenv() from libc.so.6. I'm almost positive it worked fine yesturday, although I have changed the code which accounts for the connection on sock.Code:int Recept (int sock, char *buffer) { int count=0; char *ptr=buffer; if ((buffer=malloc(1))==NULL) return -2; while (recv(sock,ptr,1,0)>0) { printf("bytes=%6d\t%c\n",count,ptr[0]); // for debugging if ((ptr[0]=='\n') && (count > 0) && (buffer[count]=='\r')) { buffer[count]='\0'; puts ("Recept() done."); return count;} ptr++; count++; buffer=realloc(buffer,count+1); if (buffer==NULL) return -3; } return -1; }



LinkBack URL
About LinkBacks




