#include #include #include "openssl/ssl.h" #include "openssl/bio.h" #include "openssl/err.h" int main() { BIO * bio; SSL_CTX * ctx; int p; char *request = "GET / HTTP/1.1 \r\n Accept:*/* \r\n Host: mail.google.com \r\n Connection: Keep-Alive\r\n\r\n"; char r[1024]; /* Set up the library */ SSL_library_init(); ERR_load_BIO_strings(); SSL_load_error_strings(); OpenSSL_add_all_algorithms(); /* Set up the SSL context */ ctx = SSL_CTX_new(SSLv23_client_method()); /* Setup the connection */ bio = BIO_new_ssl_connect(ctx); /* Create and setup the connection */ BIO_set_conn_hostname(bio, "mail.google.com:https"); if(BIO_do_connect(bio) <= 0) { fprintf(stderr, "Error attempting to connect\n"); ERR_print_errors_fp(stderr); BIO_free_all(bio); SSL_CTX_free(ctx); return 0; } /* Send the request */ BIO_write(bio, request, strlen(request)); /* Read in the response */ for(;;) { p = BIO_read(bio, r, 1023); if(p <= 0) break; r[p] = 0; /* printf("%s", r); */ } printf ("FINISHED\n"); /* Close the connection and free the context */ BIO_free_all(bio); SSL_CTX_free(ctx); return 0; }