This is a snippet of code from the darkspell gadgets.  
(Replace read with SSL_read and you have a reader for an SSL enabled
connection).

My question is why does this print out some code that is less then 4096
bytes...ever? 
It seems that this would not return and print the 'buf' until its read
'readSize' (4096) worth of characters.

I am running this on an openssl s_server, and the only way i get the client
to continue is to CTRLD or CTRLC the server (that seems to abort the read, i
guess returning a 0!

However, short of user interaction to kill the server, how does this work,
so that it will receive an arbitrary reply, without hanging forever until
waiting on 4096 bytes?  IE:  Where is it reading the 'content-length' field
so it really knows how much data to get?

Thanx,
   brian


[receiving/printing code snippet below from darkspell gadgets]

 // helper function to get the bytes off the socket
int readn(int sock, char *buf,int readSize) {
unsigned char *p;
int i;
int numRead;

p = (unsigned char *)buf;
i = 0;
while(i < readSize) {
numRead = read(sock, p, readSize - i);
if (numRead <= 0) 
return(i);
p += numRead;
i += numRead;
}
return(i); 
} 

// public function we'll call
void printServerResponse(int sock) {
int bytesRead;
int readSize = 4096;
char buf[readSize + 2];

memset (buf, 0, sizeof(buf));
while (bytesRead = readn(sock, buf, readSize)) {
printf(buf);
memset (buf, 0, sizeof(buf));
}
close (sock);
} 

Brian Snyder.vcf

Reply via email to