1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
   |  
 while(1){
      memset(buf,'\0',sizeof(buf));
      memset(sbuf,'\0',sizeof(sbuf));
      /* ask the user to write an HTTP request */
      FD_ZERO(&writefds);
      FD_SET(fileno(stdout),&writefds);
      nb_bytes_written = write(fileno(stdout),"Enter an HTTP request:\n",strlen("Enter an HTTP request:\n"));
      if(nb_bytes_written <= 0){
	BIO_printf(bio_err,"error in the request writing %d\n",SSL_get_error(ssl,nb_bytes_written));
	goto end;
      }
 
      /* read the request on stdin */
      FD_SET(fileno(stdin),&readfds);
      nb_bytes_read = read(fileno(stdin),buf,sizeof(buf));
      if(nb_bytes_read <= 0){
	BIO_printf(bio_err,"error in the request reading %d\n",SSL_get_error(ssl,nb_bytes_read));
	goto end;
      }
 
      /* send the client request to the server */
      FD_ZERO(&writefds);
      FD_SET(SSL_get_fd(ssl),&writefds);
      c_request_len = SSL_write(ssl,buf,nb_bytes_read);
      if (c_request_len <= 0){
	BIO_printf(bio_err,"error in SSL_write %d\n",SSL_get_error(ssl,c_request_len));
	goto end;
      }
 
      while(1){
	/* read the server response (block of 4096) */
	FD_ZERO(&readfds);
	FD_SET(SSL_get_fd(ssl),&readfds);
	s_response_len = SSL_read(ssl,sbuf,4096);
	if (s_response_len < 0){
	  BIO_printf(bio_err,"error in SSL_read %d\n",SSL_get_error(ssl,s_response_len));
	  goto end;
	}
	if(s_response_len == 0)
	  break;
 
	/* display the server response on stdout */
	FD_ZERO(&writefds);
	FD_SET(SSL_get_fd(ssl),&writefds);
	nb_bytes_written = write(fileno(stdout),sbuf,s_response_len);
	if(nb_bytes_written <= 0){
	  BIO_printf(bio_err,"error in the response writing %d\n",SSL_get_error(ssl,nb_bytes_written));
	  goto end;
	}
      }
    } | 
Partager