Cryptography Reference
In-Depth Information
buffer = malloc( buf_len );
buffer[ 0 ] = message_type;
memcpy( buffer + 1, data, data_len );
if ( send_message( connection, buffer, buf_len, parameters ) == -1 )
{
return -1;
}
free( buffer );
return 0;
}
The send_message function in Listing C-13 actually writes something onto
the socket itself.
Listing C-13: “ssl.c” send_message
static int send_message( int connection,
const unsigned char *data,
unsigned short data_len,
SSLParameters *parameters )
{
unsigned char *buffer;
int buf_len;
unsigned short header_len;
buf_len = data_len + 2;
buffer = malloc( buf_len );
header_len = htons( data_len );
memcpy( buffer, &header_len, 2 );
buffer[ 0 ] |= 0x80; // indicate two-byte length
memcpy( buffer + 2, data, data_len );
if ( send( connection, ( void * ) buffer, buf_len, 0 ) < buf_len )
{
return -1;
}
free( buffer );
return 0;
}
This function, like the last, just prepends yet another header in front of the
data to be sent. This header consists of the two-byte length of the payload, fol-
lowed by the payload. In the case of a handshake message, the fi rst byte of the
payload is a byte indicating which handshake message this is. Note that there's
 
Search WWH ::




Custom Search