Convert dtls_write_records to use standard record layer functions