SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_WRONG_VERSION_NUMBER);
SSLerr(SSL_F_DTLS1_GET_RECORD,SSL_R_WRONG_VERSION_NUMBER);
int dtls1_get_record(SSL *s)	{	int ssl_major,ssl_minor,al;	int i,n;	SSL3_RECORD *rr;	SSL_SESSION *sess;	unsigned char *p;	short version;	DTLS1_BITMAP *bitmap;	unsigned long long read_sequence;    unsigned int is_next_epoch;	rr= &(s->s3->rrec);	sess=s->session;    /* The epoch may have changed.  If so, process all the     * pending records.  This is a non-blocking operation. */    if ( ! dtls1_process_buffered_records(s))        return 0;	/* if we're renegotiating, then there may be buffered records */	if (dtls1_get_processed_record(s))		return 1;	/* get something from the wire */again:	/* check if we have the header */	if (	(s->rstate != SSL_ST_READ_BODY) ||		(s->packet_length < DTLS1_RT_HEADER_LENGTH)) 		{		n=ssl3_read_n(s, DTLS1_RT_HEADER_LENGTH, s->s3->rbuf.len, 0);		/* read timeout is handled by dtls1_read_bytes */		if (n <= 0) return(n); /* error or non-blocking */		OPENSSL_assert(s->packet_length == DTLS1_RT_HEADER_LENGTH);		s->rstate=SSL_ST_READ_BODY;		p=s->packet;		/* Pull apart the header into the DTLS1_RECORD */		rr->type= *(p++);		ssl_major= *(p++);		ssl_minor= *(p++);		version=(ssl_major<<8)|ssl_minor;        /* sequence number is 64 bits, with top 2 bytes = epoch */ 		n2s(p,rr->epoch);		read_sequence = 0;		n2l6(p, read_sequence);		long_long_to_bytes(read_sequence, s->s3->read_sequence);		n2s(p,rr->length);		/* Lets check version */		if (s->first_packet)			{			s->first_packet=0;			}		else			{			if (version != s->version)				{				SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_WRONG_VERSION_NUMBER);				/* Send back error using their				 * version number :-) */				s->version=version;				al=SSL_AD_PROTOCOL_VERSION;				goto f_err;				}			}		if ((version & 0xff00) != (DTLS1_VERSION & 0xff00))			{			SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_WRONG_VERSION_NUMBER);			goto err;			}		if (rr->length > SSL3_RT_MAX_ENCRYPTED_LENGTH)			{			al=SSL_AD_RECORD_OVERFLOW;			SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_PACKET_LENGTH_TOO_LONG);			goto f_err;			}		/* now s->rstate == SSL_ST_READ_BODY */		}	/* s->rstate == SSL_ST_READ_BODY, get and decode the data */	if (rr->length > s->packet_length-DTLS1_RT_HEADER_LENGTH)		{		/* now s->packet_length == DTLS1_RT_HEADER_LENGTH */		i=rr->length;		n=ssl3_read_n(s,i,i,1);		if (n <= 0) return(n); /* error or non-blocking io */		/* this packet contained a partial record, dump it */		if ( n != i)			{			s->packet_length = 0;			goto again;			}		/* now n == rr->length,		 * and s->packet_length == DTLS1_RT_HEADER_LENGTH + rr->length */		}	s->rstate=SSL_ST_READ_HEADER; /* set state for later operations */	/* match epochs.  NULL means the packet is dropped on the floor */	bitmap = dtls1_get_bitmap(s, rr, &is_next_epoch);	if ( bitmap == NULL)        {        s->packet_length = 0;  /* dump this record */        goto again;   /* get another record */		}	/* check whether this is a repeat, or aged record */	if ( ! dtls1_record_replay_check(s, bitmap, &(rr->seq_num)))		{		s->packet_length=0; /* dump this record */		goto again;     /* get another record */		}	/* just read a 0 length packet */	if (rr->length == 0) goto again;    /* If this record is from the next epoch (either HM or ALERT), buffer it     * since it cannot be processed at this time.     * Records from the next epoch are marked as received even though they are      * not processed, so as to prevent any potential resource DoS attack */    if (is_next_epoch)        {        dtls1_record_bitmap_update(s, bitmap);        dtls1_buffer_record(s, &(s->d1->unprocessed_rcds), rr->seq_num);        s->packet_length = 0;        goto again;        }    if ( ! dtls1_process_record(s))        return(0);	dtls1_clear_timeouts(s);  /* done waiting */	return(1);f_err:	ssl3_send_alert(s,SSL3_AL_FATAL,al);err:	return(0);	}