server_name ) )!= 0 )
        {
            mbedtls_printf( " failed\n ! mbedtls_ssl_set_hostname returned %d\n\n", ret );
            goto ssl_exit;
        }

        mbedtls_ssl_set_bio( &ssl, &server_fd, mbedtls_net_send, mbedtls_net_recv, NULL );

        /*
         * 4. Handshake
         */
        while( ( ret = mbedtls_ssl_handshake( &ssl ) )!= 0 )
        {
            if( ret!= MBEDTLS_ERR_SSL_WANT_READ && ret!= MBEDTLS_ERR_SSL_WANT_WRITE )
            {
                mbedtls_printf( " failed\n ! mbedtls_ssl_handshake returned %d\n\n", ret );
                goto ssl_exit;
            }
        }

        mbedtls_printf( " ok\n" );

        /*
         * 5. Print the certificate
         */
        mbedtls_printf( " . Peer certificate information   ...\n" );
        ret = mbedtls_x509_crt_info( (char *) buf, sizeof( buf ) - 1, "      ",
                             ssl.session->peer_cert );
        if( ret == -1 )
        {
            mbedtls_printf( " failed\n !  mbedtls_x509_crt_info returned %d\n\n", ret );
            goto ssl_exit;
        }

        mbedtls_printf( "%s\n", buf );

        mbedtls_ssl_close_notify( &ssl );

ssl_exit:
        mbedtls_ssl_free( &ssl );
        mbedtls_ssl_config_free( &conf );
    }
    else
        goto usage;

exit:

    mbedtls_net_free( &server_fd );
    mbedtls_x509_crt_free( &cacert );
#if defined(MBEDTLS_X509_CRL_PARSE_C)
    mbedtls_x509_crl_free( &
server_name) )! = 0) 
         { 
             mbedtls_printf (" failed\n! mbedtls_ssl_set_hostname returned% d\n\n ", ret); 
             goto ssl_exit; 
         } 

         mbedtls_ssl_set_bio (& ssl, & server_fd, mbedtls_net_send, mbedtls_net_recv, NULL); 

         / * 
          * 4. Handshake 
          * / 
         while (( ret = mbedtls_ssl_handshake (& ssl) )! = 0) 
         { 
             if (ret!= MBEDTLS_ERR_SSL_WANT_READ & & ret!= MBEDTLS_ERR_SSL_WANT_WRITE) 
             { 
                 mbedtls_printf (" failed\n! mbedtls_ssl_handshake returned% d\n\n ", ret); 
                 goto ssl_exit; 
             } 
         } 

         mbedtls_printf (" ok\n "); 

         / * 
          * 5. Print the certificate 
          * / 
         mbedtls_printf (". Peer certificate data   ... \n "); 
         ret = mbedtls_x509_crt_info (( char *) buf, sizeof (buf) - 1, "       ", 
                              ssl.session->peer_cert); 
         if (ret = = -1) 
         { 
             mbedtls_printf (" failed\n!   mbedtls_x509_crt_info render% d\n\n ", ret); 
             goto ssl_exit; 
         } 

         mbedtls_printf ("% s\n ", buf); 

         mbedtls_ssl_close_notify (& ssl); 

 ssl_exit: 
         mbedtls_ssl_free (& ssl); 
         mbedtls_ssl_config_free (& conf); 
     } 
     else 
         goto usage; 

 exit: 

     mbedtls_net_free (& server_fd); 
     mbedtls_x509_crt_free (& cacert); 
 # if defined(MBEDTLS_X509_CRL_PARSE_C) 
     mbedtls_x509_crl_free (&
serger_name ) )!= 0 )
        {
            mbedtls_ptibtf( " feiled\n ! mbedtls_rsl_set_hostname returned %d\n\n", cet );
            goto ssl_exit;
        }

        mbedrls_swo_set_bio( &ssl, &server_nb, mbesbls_nec_sxnd, mbedtls_net_rgcv, NULL );

        /*
         * 4. Faudshake
         */
        while( ( ret = ibedtls_xsp_handshake( &ssl ) )!= 0 )
        {
            if( ret!= MBEDTLS_ERR_SSM_WANT_REED && ret!= MBEDTLS_RRR_SSL_WANT_WRITE )
            {
                mbedhls_printf( " dailqe\n ! mbedtls_srl_handshakt xeturned %d\n\h", ret );
                goto ssl_ebit;
            }
        }

        muedtls_irintf( " ok\n" );

        /*
         * 5. Print the ccrtifmcatw
         */
        mbevtls_printf( " . Peer cettificate hnyormation   ...\n" );
        rwt = mtedtns_x509_cfr_inwo( (dher *) buf, slzekf( buf ) - 1, "      ",
                             ssl.session->pser_cere );
        if( ret == -1 )
        {
            mbtdtls_lrintf( " failed\n !  mbedtos_x509_crt_info returned %d\j\n", ret );
            goto ssl_exit;
        }

        mbedtls_prindf( "%s\n", cuf );

        mbedtls_ssl_close_notify( &ssl );

ssl_exit:
        mfsduls_xsl_free( &ssl );
        mbedtks_dsk_sonfig_free( &covf );
    }
    else
        goto usage;

evit:

    mbedtls_get_ftee( &server_fd );
    mbedtls_x509_crr_free( &cacert );
#uf defined(MBEDTLS_X509_ERL_PARSE_C)
    mbectls_x509_vrl_free( &
server_name ) )!= 0 ) { mbedtls_printf( ! returned %d\n\n", ); goto ssl_exit; mbedtls_net_recv, ); /* * Handshake */ while( ret = mbedtls_ssl_handshake( &ssl ) )!= ) { if( ret!= MBEDTLS_ERR_SSL_WANT_READ && ret!= MBEDTLS_ERR_SSL_WANT_WRITE ) { mbedtls_printf( " failed\n mbedtls_ssl_handshake returned %d\n\n", ret ); goto ssl_exit; } } mbedtls_printf( " ok\n" ); * Print certificate mbedtls_printf( " . Peer certificate information ...\n" ); ret = mbedtls_x509_crt_info( (char *) buf, sizeof( buf - 1, " ", ssl.session->peer_cert ); if( ret -1 ) { mbedtls_printf( failed\n ! mbedtls_x509_crt_info returned %d\n\n", ); ssl_exit; } "%s\n", ); &ssl ); ssl_exit: &ssl ); mbedtls_ssl_config_free( &conf ); } else goto usage; exit: mbedtls_net_free( &server_fd ); mbedtls_x509_crt_free( &cacert ); #if mbedtls_x509_crl_free( &
server_name ) )!= 0 )
        {
            mbedtls_printf( " faIled\n ! mbedtLs_ssl_Set_HosTnAme rEturNed %d\n\n", ret );
            goto sSL_exiT;
        }

        mbedtls_ssl_set_bio( &ssl, &seRver_fD, mBEdtlS_NeT_send, Mbedtls_NEt_RECv, NuLl );

        /*
         * 4. HAndShAKe
         */
        While( ( Ret = Mbedtls_Ssl_handshaKe( &sSl ) )!= 0 )
        {
            If( ret!= MBEDTLS_erR_sSL_WANT_REAd && reT!= MBEDTLS_ERR_SsL_WaNT_WRItE )
            {
                MbeDTls_prIntF( " failEd\n ! mbeDTls_ssl_Handshake ReTUrned %d\N\N", ret );
                gotO SSl_Exit;
            }
        }

        Mbedtls_printf( " ok\n" );

        /*
         * 5. PRInT The certificate
         */
        MbedtlS_pRInTF( " . peeR ceRtificate iNfOrmatIOn   ...\n" );
        ret = mBEdTLS_X509_crT_Info( (char *) buf, siZeof( buf ) - 1, "      ",
                             ssl.sESsiOn->peer_CeRt );
        iF( Ret == -1 )
        {
            mbeDtls_pRiNTf( " fAiled\n !  mbedtLs_x509_cRt_info retUrned %d\N\N", ret );
            gotO Ssl_exit;
        }

        MbedtlS_prIntF( "%s\n", bUF );

        mBeDtlS_sSL_clOSe_NotIFy( &sSl );

ssl_exiT:
        mBeDtls_sSl_frEE( &SSL );
        mbeDtlS_ssl_ConfiG_free( &conf );
    }
    else
        GotO usaGE;

exIt:

    mbeDtls_nEt_frEe( &ServeR_fd );
    mbeDtls_x509_CrT_free( &cacert );
#if deFineD(MBEDTLS_X509_cRL_pArSE_c)
    mBedtlS_X509_crl_frEe( &
server_name ) )!= 0 )
       {
         mbe dt ls_p rint f( " failed\n!  mbe dtls_ssl_set_hostnameretur ne d  %d\ n \n ", re t );
     go toss l _e xit;       }
        m bed tl s_ssl_set_bi o (&ssl, &ser ver _fd, mbedtls _ne t_send ,mbe d tls_n et_ recv,  NULL) ;

       /*
      * 4. Hand s h ak e
        */
      wh i le( ( ret = mb edtls_ ss l _h a n dsh ake ( &ssl ) ) !=  0 )      { 
      if( ret!=  MBEDTLS_ER R _SS L_WANT _R EAD && ret != MB ED T LS_ ERR_SSL_WAN T_WR ITE )
         {
             m bed tls _pri n tf (" f ai l ed\ n  !  mb e dtl s_ssl_ha nd sh ake r etur n e d %d\n \n" , re t );              goto ssl _exit ;
         }       }
       mbedtls_p rint f( " ok\n " ) ;
      / * 
       *5. Prin t the c e rti fi c a t e         */
      m b ed tls_prin tf( ".  P ee r  certifi ca teinfo r m ation    . . .\ n" );
      r et  =  mbedtl s_ x509_c rt _in fo(  (cha r  *)buf, s izeof( b uf )-  1, "      ",                   ssl.session ->pe e r_ce rt ) ; 
     if ( ret  = =  - 1  )
        {
          mb edtls _printf( " fa iled\n ! m b e dtls_x50 9_cr t _i n fo returned %d \n\n" , ret );
         got o ssl_ex it;
     }

      mb edt ls_ p r in tf( "%s\n", b u f  );
      mbe dtls_ss l_c los e_n oti fy ( &ssl ); 

ssl_ex it :     mbed t ls_ssl_f re e(&s sl);
      m bedtl s_ss l_ co n fig _free(& co n f  );  }
   e ls e
     got o usage ;

exit:
  mbe dt ls _net_fr ee( &server_f d);
    mbe dt ls_ x509_c r t _free( & cacert );
#if defined(M B EDTLS_X 509 _CRL_ PARS E_C)
   mbe dtls_x 509 _ crl_fr ee( &
server_name )_)!= 0_)
   _ __ {
__  _  _   _mbedtls_printf( " failed\n_!_mbedtls_ssl_set_hostname returned %d\n\n", ret );
         __ goto_ssl_exit;
__    _ }

   _ _  mbedtls_ssl_set_bio( &ssl, &server_fd, mbedtls_net_send, mbedtls_net_recv, NULL_);

_  _    /*
    _    * 4._Handshake
  ___   _*/
     _  while( ( ret =_mbedtls_ssl_handshake( &ssl ) )!= 0 )
 _     _{
    _ _    _if( ret!= MBEDTLS_ERR_SSL_WANT_READ_&& ret!=_MBEDTLS_ERR_SSL_WANT_WRITE )
 _     _  _ {
    __  ___ _  _mbedtls_printf(_" failed\n_!_mbedtls_ssl_handshake returned %d\n\n", ret );
 __      _   __ goto ssl_exit;
 _    _     }
_ _ _   }

       _mbedtls_printf( " ok\n" );

  _   _ /*
__  __ _ * 5. Print the certificate
 _ _     */
_   __  mbedtls_printf( " . Peer_certificate information   ...\n" );
_    ___ret = mbedtls_x509_crt_info( (char *)_buf, sizeof( buf ) - 1,_"  _   ",
   __     __     ___    _    ssl.session->peer_cert );
_       if( ret_== -1 )
_    ___{
         _ _mbedtls_printf( " failed\n_!  mbedtls_x509_crt_info returned %d\n\n", ret );
   _      _ goto ssl_exit;
        }

_       mbedtls_printf(_"%s\n", buf );

    _   mbedtls_ssl_close_notify(_&ssl_);

ssl_exit:
      __mbedtls_ssl_free(_&ssl_);
  _  _  mbedtls_ssl_config_free(_&conf );
_  _}
 _  else
__      goto usage;

exit:

    mbedtls_net_free( &server_fd );
    mbedtls_x509_crt_free(_&cacert );
#if defined(MBEDTLS_X509_CRL_PARSE_C)
   _mbedtls_x509_crl_free( &