Cryptography Reference
In-Depth Information
if ( receive_ssl_message( connection, NULL, 0, parameters ) == -1 )
{
return -1;
}
}
receive_ssl_message in Listing C-15 thus reads the data available from the
socket, strips off the SSL header, and, if it's a handshake message, processes it.
Listing C-15: “ssl.c” receive_ssl_message
static int receive_ssl_message( int connection,
char *target_buffer,
int target_bufsz,
SSLParameters *parameters )
{
int status = 0;
unsigned short message_len;
unsigned short bytes_read;
unsigned short remaining;
unsigned char *buffer, *bufptr;
// New message - read the length first
if ( recv( connection, &message_len, 2, 0 ) <= 0 )
{
return -1;
}
message_len = ntohs( message_len );
if ( message_len & 0x8000 )
{
// two-byte length
message_len &= 0x7FFF;
}
// else TODO
// Now read the rest of the message. This will fail if enough memory
// isn't available, but this really should never be the case.
bufptr = buffer = malloc( message_len );
remaining = message_len;
bytes_read = 0;
while ( remaining )
{
if ( ( bytes_read = recv( connection, bufptr,
remaining, 0 ) ) <= 0 )
{
return -1;
}
bufptr += bytes_read;
remaining -= bytes_read;
 
Search WWH ::




Custom Search