  	if (! nopoll_conn_is_ok (conn)) {
  		printf ("ERROR: Expected to find proper client connection status, but found error..\n");
  		return nopoll_false;
-@@ -972,7 +972,7 @@ nopoll_bool test_06 (void) {
+@@ -958,6 +1074,50 @@ nopoll_bool test_05 (void) {
+ 	return nopoll_true;
+ }
+ 
++
++nopoll_bool test_05_hostname_validation (void) {
++
++	char * fileName = "hostname-check.pem";
++	char *hostname_valid = "test.nopoll.com";
++	char *hostname_invalid = "invalid.com";
++	FILE *fp = NULL;
++
++	#if defined(NOPOLL_OS_WIN32)
++	fp = fopen (fileName, "rb");
++    #else
++	fp = fopen (fileName, "r");
++    #endif
++    
++    if(!fp)
++    {
++	    printf("unable to open cert file for hostname validation: %s\n", fileName);
++	    return nopoll_false;
++    }
++
++    X509 *cert = PEM_read_X509(fp, NULL, NULL, NULL);
++    if(!cert)
++    {
++	    printf("unable to parse certificate for hostname validation : %s\n", fileName);
++	    fclose(fp);
++	    return nopoll_false;
++    }
++   
++    if(nopoll_validate_hostname(hostname_valid, cert))
++    {
++        printf("hostname %s doesn't match with dnsname \n",hostname_valid);
++        return nopoll_false;
++    }
++    
++    if(!nopoll_validate_hostname(hostname_invalid, cert))
++    {
++        printf("hostname %s matched with dnsname \n",hostname_invalid);
++        return nopoll_false;
++    }
++    X509_free(cert);
++    fclose(fp);
++	return nopoll_true;
++}
++
+ nopoll_bool test_06 (void) {
+ 
+ 	noPollCtx      * ctx;
+@@ -972,7 +1132,7 @@ nopoll_bool test_06 (void) {
  	nopoll_conn_opts_ssl_peer_verify (opts, nopoll_false);
  
  	/* call to create a connection */

 
 	/* send a cleanup message */
 	bytes_written = nopoll_conn_send_text (conn, "release-message", 15);
@@ -757,14 +757,14 @@ nopoll_bool test_04c (void) {
 	ctx = create_ctx ();
 
 	/* call to create a connection */

 		nopoll_log (conn->ctx, NOPOLL_LEVEL_DEBUG, "SSL: sent %d bytes (requested: %d)..", res, buffer_size); 
 
 		/* call to handle error */
@@ -449,12 +584,17 @@ int nopoll_conn_tls_send (noPollConn * conn, char * buffer, int buffer_size)
 		/* nopoll_log (conn->ctx, NOPOLL_LEVEL_DEBUG, "   SSL: after processing error, sent %d bytes (requested: %d)..",  res, buffer_size); */
 
 		if (! needs_retry)
