Socket programming: Getting same response when request sent using openssl library - c

I am sending two different https header to different address on same host. I am getting the same response from both test() and test1() functions... It seems like something can be used only once.... thanks in advance :)
#include <iostream>
#include <errno.h>
#include <unistd.h>
#include <malloc.h>
#include <string.h>
#include <sys/socket.h>
#include <resolv.h>
#include <netdb.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
#define FAIL -1
using namespace std;
SSL_CTX* InitCTX(void);
void test(SSL_CTX* ctx, int server);
void test1(SSL_CTX* ctx, int server);
int OpenConnection(char *hostname, int port);
int main()
{
SSL_CTX *ctx;
char *host = "academics.vit.ac.in";
char *port = "443";
SSL_library_init();
ctx = InitCTX();
int server = OpenConnection(host, atoi(port));
test(ctx, server);
test1(ctx, server);// Both functions prints exactly same data
return 0;
}
void test(SSL_CTX* ctx, int server)
{
char buf[9999];
int bytes;
SSL *ssl;
ssl = SSL_new(ctx);
SSL_set_fd(ssl, server);
if(SSL_connect(ssl) == FAIL)
{
ERR_print_errors_fp(stderr);
}
else
{
printf("Connected with %s encryption\n", SSL_get_cipher(ssl));
char*msg = "GET /student/captcha.asp HTTP/1.1\nHost: academics.vit.ac.in\nCookie: ASPSESSIONIDCUTRADAT=OMDEAOKCPOLOKCLJMPAALAJN\n\n";
SSL_write(ssl, msg, strlen(msg));
bytes = SSL_read(ssl, buf, sizeof(buf));
buf[bytes] = 0;
printf("%s",buf);
SSL_free(ssl);
}
}
void test1(SSL_CTX* ctx, int server)
{
char buf[9999];
int bytes;
SSL *ssl;
ssl = SSL_new(ctx);
SSL_set_fd(ssl, server);
if(SSL_connect(ssl) == FAIL)
{
ERR_print_errors_fp(stderr);
}
else
{
printf("Connected with %s encryption\n", SSL_get_cipher(ssl));
char*msg = "GET / HTTP/1.1\nHost: academics.vit.ac.in\nCookie: ASPSESSIONIDCUTRADAT=OMDEAOKCPOLOKCLJMPAALAJN\n\n";
SSL_write(ssl, msg, strlen(msg));
bytes = SSL_read(ssl, buf, sizeof(buf));
buf[bytes] = 0;
printf("%s",buf);
SSL_free(ssl);
}
}
SSL_CTX* InitCTX(void)
{
const SSL_METHOD *method;
SSL_CTX *ctx;
OpenSSL_add_all_algorithms();
SSL_load_error_strings();
method = SSLv3_client_method();
ctx = SSL_CTX_new(method);
if ( ctx == NULL )
{
ERR_print_errors_fp(stderr);
abort();
}
return ctx;
}
int OpenConnection(char *hostname, int port)
{
int sd;
struct hostent *host;
struct sockaddr_in addr;
if ( (host = gethostbyname(hostname)) == NULL )
{
perror(hostname);
abort();
}
sd = socket(PF_INET, SOCK_STREAM, 0);
bzero(&addr, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
addr.sin_addr.s_addr = *(long*)(host->h_addr);
if ( connect(sd, (struct sockaddr*)&addr, sizeof(addr)) != 0 )
{
close(sd);
perror(hostname);
abort();
}
return sd;
}
The response i am getting is
Connected with RC4-SHA encryption
HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Type: image/bmp
Expires: Tue, 25 Jun 2013 08:27:30 GMT
Server: Microsoft-IIS/7.0
Content-Disposition: inline; filename=captcha.bmp
Set-Cookie: ASPSESSIONIDCUSTBBBT=BHEANFEAHBBCBIJDIBNOPDAI; secure; path=/
X-Powered-By: ASP.NET
Date: Tue, 25 Jun 2013 08:28:30 GMT
Connection: close
Connected with (NONE) encryption
HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Type: image/bmp
Expires: Tue, 25 Jun 2013 08:27:30 GMT
Server: Microsoft-IIS/7.0
Content-Disposition: inline; filename=captcha.bmp
Set-Cookie: ASPSESSIONIDCUSTBBBT=BHEANFEAHBBCBIJDIBNOPDAI; secure; path=/
X-Powered-By: ASP.NET
Date: Tue, 25 Jun 2013 08:28:30 GMT
Connection: close

Related

Using a simple C program how to load HTTPS web page

I am using a C web page loading program. When I ask for a page with an"http://" prefix it loads successfully. However, when I ask for "https://" it crashes. If I remove the "s" then I receive:
Host: a.b.c
nr 90 (90)
Full Buffer header HTTP/1.1 301 Moved Permanently
Date: Mon, 17 Oct 2022 10:02:05 GMT
Transfer-Encoding: chunked
Connection: keep-alive
Cache-Control: max-age=3600
Expires: Mon, 17 Oct 2022 11:02:05 GMT
Location: https://a.b.c/ViewDocument.aspx?fileid=12345678
Server: cloudflare
This "moved" location is the original URL that I am requesting.
When this address is used in a browser it will automatically download a PDF file - which is the ultimate aim of this code.
Some relevant coding:
#include "stdio.h"
#include "string.h"
#include "stdlib.h"
#include <unistd.h>
#include "stdint.h"
#ifdef __linux
#include "netinet/in.h"
#include "sys/socket.h"
#include <arpa/inet.h>
#include <netdb.h>
#include <fcntl.h>
#endif
...
void receive(char *ip, char *domain, char *page){
int sockfd, portno;
struct sockaddr_in server_addr;
char header[512];
portno = 80;
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if(sockfd == -1){
printf("error opening socket\n");
return;
}else{
printf("socket opened\n");
}
memset((char *) &server_addr, 0, sizeof(server_addr));
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(portno);
#ifdef __WIN32
server_addr.sin_addr.s_addr = inet_addr(ip);
#else
inet_pton(AF_INET, ip, &(server_addr.sin_addr) );
#endif
int err = 0;
if( (err = connect(sockfd, (struct sockaddr *) &server_addr, sizeof(server_addr)) ) < 0){
printf("failed to connect %d\n", err);
return;
}else{
printf("connection successful\n");
}
snprintf(header, 512, "GET %s HTTP/1.1\r\nHost: %s\r\n\r\n", page, domain);
printf("Header %s\n", header);
int nr = send(sockfd, header, tec_string_length(header), 0);
if(nr){
printf("nr %d (%u)\n", nr, tec_string_length(header));
}
char *buf;
buf = (char *) malloc(BUF_SIZE_INC * sizeof(char));
memset(buf, 0, BUF_SIZE_INC);
ssize_t bytes_received = recv(sockfd, buf, BUF_SIZE, 0);
int size = 0;
char *new_buffer = process_header(buf, &size);
memmove(buf, new_buffer, BUF_SIZE_INC - (new_buffer - buf) );
load_body(sockfd, buf, size);
puts("*****");
#ifdef __WIN32
closesocket(sockfd);
WSACleanup();
#else
close(sockfd);
#endif
}//receive*/
The code is from https://gitlab.com/greggink/youtube_episode_loading_webpage (using the main_final.c file).
Ubuntu 20.04
Thank you.

TCP socket hangs when reading response from custom HTTP request - C

I have the following code that I have written which is suppose to send a simple http request over a TCP socket, I get a response but as soon as I try to read in the loop it hangs, in the 2nd read operation (tried it manually)
if anyone has an idea of why this might fail I will appreciate it a lot
attached below is the entire code
I am running the program like this: ./http_client yahoo.com
I get this response text at first:
HTTP/1.1 301 Moved Permanently
Date: Sat, 06 Aug 2022 08:07:11 GMT
Connection: keep-alive
Server: ATS
Cache-Control: no-store, no-cache
Content-Type: text/html
Content-Language: en
X-Frame-Options: SAMEORIGIN
Location: https://www.yahoo.com/
Content-Length: 8
redirect
and then it hangs and closes the socket, it shouldn't hang at all, it should run and exit without a delay or anything
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
int main(int argc, char *argv[]) {
int sockfd;
struct sockaddr_in cli_name;
struct sockaddr_in *saddr;
char *hostname;
struct addrinfo *res;
int port = 80;
if (argc != 2) {
perror("Usage: establish tcp connection to: <hostname>\n");
exit(1);
}
hostname = argv[1];
printf("Client is alive and establishing socket connection %s.\n", hostname);
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd < 0) {
perror("Error opening channel");
close(sockfd);
exit(1);
}
if (0 != getaddrinfo(hostname, NULL, NULL, &res)) {
fprintf(stderr, "Error in resolving hostname %s\n", hostname);
exit(1);
}
bzero(&cli_name, sizeof(cli_name));
cli_name.sin_family = AF_INET;
saddr = (struct sockaddr_in *) res->ai_addr;
cli_name.sin_addr.s_addr = inet_addr(inet_ntoa(saddr->sin_addr));
cli_name.sin_port = htons(port);
fflush(stdout);
if (connect(sockfd, (struct sockaddr *) &cli_name, sizeof(cli_name)) < 0) {
perror("Error establishing communications");
close(sockfd);
exit(1);
}
char header[100];
int cx;
char buf[2056];
size_t byte_count = 0;
size_t sent_byte_count = 0;
cx = snprintf(header, 100, "GET / HTTP/1.1\r\nHost: %s:%d\r\n\r\n", hostname, port);
size_t total = strlen(header);
size_t sent = 0;
do {
sent_byte_count = write(sockfd, header + sent, total - sent);
if (sent_byte_count < 0)
printf("ERROR writing message to socket");
if (sent_byte_count == 0)
break;
sent += sent_byte_count;
} while (sent < total);
memset(buf,0,sizeof(buf));
while ((byte_count = read(sockfd, buf, 2054)) > 0) {
buf[byte_count] = '\0';
printf("%s", buf); // <-- give printf() the actual data size
fflush(stdout);
}
printf("Exiting now.\n");
close(sockfd);
exit(0);
}

Why Have I got a question mark instead of the HTML content?

Here is my code where I tried to make an HTTP request
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
int main(int argc, char* argv[]) {
//create the socket
int network_socket;
network_socket = socket(AF_INET, SOCK_STREAM, 0);
//specify an address for the socket
struct sockaddr_in server_address;
server_address.sin_family = AF_INET;
server_address.sin_port = htons(80);
inet_pton(AF_INET, "208.97.177.124", &server_address.sin_addr);
//connect
int connection_status = connect(network_socket, (struct sockaddr *) &server_address, sizeof(server_address));
if (connection_status == -1) {
printf("There was an error making a connection to the remote socket\n\n");
}
//send information
char message[1024];
strcpy(message , "GET /index.html HTTP/1.1\r\nHost: perdu.com\r\nUser-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)\r\nAccept-Language: en-us\r\nAccept-Encoding: gzip, deflate\r\nConnection: Keep-Alive\r\n\r\n");
send(network_socket, message, sizeof(message), 0);
//receive information
char server_response[2048];
memset(server_response, '0',sizeof(server_response));
int size = recv(network_socket, &server_response, sizeof(server_response), 0);
//print the size
printf("size is %d\n\n", size);
//print the data
printf("The server sent the response : %s\n", server_response);
//close the socket
close(network_socket);
return 0;
}
The server sent the response :
HTTP/1.1 200 OK
Date: Wed, 25 Mar 2020 14:29:19 GMT
Server: Apache
Upgrade: h2
Connection: Upgrade, Keep-Alive
Last-Modified: Thu, 02 Jun 2016 06:01:08 GMT
ETag: "cc-5344555136fe9-gzip"
Accept-Ranges: bytes
Cache-Control: max-age=600
Expires: Wed, 25 Mar 2020 14:39:19 GMT
Vary: Accept-Encoding,User-Agent
Content-Encoding: gzip
Content-Length: 163
Keep-Alive: timeout=2, max=100
Content-Type: text/html
?
And it ends with a question mark "?" instead of the HTML content. Why ?

GCM ERROR 404 - Native socket https connection over openssl without gcm class

I want to connect to the gcm service without a gcm class (only native socket with openssl).
The ssl handshake works fine. But when I send the post request to https
server i got the http 404 error.
If I uncomment the line
"//strcat(FormBuffer1, "Host: gcm-http.googleapis.com\r\n");", the server returns nothing and the connection seems to hang.
I tried gcm-http.googleapis.com and android.googleapis.com.
Is there anywhere an https post example for GCM? I found only code sample which use gcm classes.
Thanks for your answers!
My C source:
//gcc -lssl -lcrypto sock.c -o sock.o
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <unistd.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/time.h>
#include <stdlib.h>
#include <memory.h>
#include <ifaddrs.h>
#include <net/if.h>
#include <stdarg.h>
#include <openssl/crypto.h>
#include <openssl/x509.h>
#include <openssl/pem.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
int main(int argc, char *argv[]){
int sd;
struct hostent *host;
struct sockaddr_in addr;
BIO *outbio = NULL;
SSL_METHOD *method;
SSL_CTX *ctx;
SSL *ssl;
char *req;
int req_len;
char hostname[] = "gcm-http.googleapis.com"; // https://gcm-http.googleapis.com/gcm/send
//char hostname[] = "www.gmx.de"; // https://gcm-http.googleapis.com/gcm/send
char certs[] = "/etc/ssl/certs/ca-certificates.crt";
int port = 443;
int bytes;
char buf[1];
char FormBuffer1[1024];
char FormBuffer2[1024];
int ContentLength;
char ContentLengthBuffer[10];
// added this to test
char dest_url[] = "https://gcm-http.googleapis.com/gcm/send";
BIO *certbio = NULL;
X509 *cert = NULL;
X509_NAME *certname = NULL;
BIO *outbio2 = NULL;
OpenSSL_add_all_algorithms();
ERR_load_BIO_strings();
ERR_load_crypto_strings();
SSL_load_error_strings();
outbio = BIO_new(BIO_s_file());
outbio = BIO_new_fp(stdout, BIO_NOCLOSE);
if(SSL_library_init() < 0){
BIO_printf(outbio, "Could not initialize the OpenSSL library !\n");
}
method = SSLv23_client_method();
ctx = SSL_CTX_new(method);
SSL_CTX_set_options(ctx, SSL_OP_NO_SSLv2);
host = gethostbyname(hostname);
sd = socket(AF_INET, SOCK_STREAM, 0);
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
addr.sin_addr.s_addr = *(long*)(host->h_addr);
if ( connect(sd, (struct sockaddr*)&addr, sizeof(addr)) == -1 ) {
BIO_printf(outbio, "%s: Cannot connect to host %s [%s] on port %d.\n", argv[0], hostname, inet_ntoa(addr.sin_addr), port);
}
ssl = SSL_new(ctx);
SSL_set_fd(ssl, sd);
SSL_connect(ssl);
// try something here
/* Get the remote certificate into the X509 structure */
printf("SSL_get_peer_certificate(ssl) \n");
cert = SSL_get_peer_certificate(ssl);
if (cert == NULL)
printf("Error: Could not get a certificate from: %s.\n", dest_url);
else
printf("Retrieved the server's certificate from: %s.\n", dest_url);
printf("\n");
/* extract various certificate information */
certname = X509_NAME_new();
certname = X509_get_subject_name(cert);
/* display the cert subject here */
BIO_printf(outbio, "Displaying the certificate subject data:\n");
X509_NAME_print_ex(outbio, certname, 0, 0);
BIO_printf(outbio, "\n\n");
/*
Format:
Content-Type:application/json
Authorization:key=....
{
"to" : ".......",
"data" : {
...
},
}*/
//req = "GET / HTTP/1.1\r\n Host: gcm-http.googleapis.com/gcm/send\r\n\r\n";
// header
strcpy(FormBuffer2, "{\"to\" : \"/topics/global\", \n \"data\": { \"message\" : \"Test123\", },\n }\n\r\n");
ContentLength = strlen(FormBuffer2);
sprintf(ContentLengthBuffer, "%d", ContentLength);
strcpy(FormBuffer1, "POST ");
strcat(FormBuffer1, "/gcm/send");
strcat(FormBuffer1, " HTTP/1.1\r\n");
//strcat(FormBuffer1, "Host: gcm-http.googleapis.com\r\n");
//strcat(FormBuffer1, "Host: android.googleapis.com\r\n ");
strcat(FormBuffer1, "Content-length: ");
strcat(FormBuffer1, ContentLengthBuffer);
strcat(FormBuffer1, "\r\nContent-Type:application/json\r\n");
strcat(FormBuffer1, "Authorization:key=AIzaSyA.....\r\n");
//strcat(FormBuffer, ContentLengthBuffer); // size of actual content
//strcat_s(FormBuffer, "\n\n");
req_len = strlen(FormBuffer1);
SSL_write(ssl, FormBuffer1, req_len);
req_len = strlen(FormBuffer2);
SSL_write(ssl, FormBuffer2, req_len);
memset(buf, '\0', sizeof(buf));
bytes = SSL_read(ssl, buf, sizeof(buf));
while(bytes > 0){
write(STDOUT_FILENO, buf, bytes);
memset(buf, '\0', sizeof(buf));
bytes = SSL_read(ssl, buf, sizeof(buf));
}
SSL_free(ssl);
close(sd);
SSL_CTX_free(ctx);
}
HTTP Answer:
SSL_get_peer_certificate(ssl)
Retrieved the server's certificate from: https://gcm-http.googleapis.com/gcm/send.
Displaying the certificate subject data:
C=US, ST=California, L=Mountain View, O=Google Inc, CN=*.googleapis.com
HTTP/1.1 404 Not Found
Content-Type: text/html; charset=UTF-8
Content-Length: 1569
Date: Sat, 21 Nov 2015 20:26:47 GMT
Server: GFE/2.0
Connection: close
<!DOCTYPE html>
<html lang=en>
<meta charset=utf-8>
<meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
<title>Error 404 (Not Found)!!1</title>
<style>
*{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}#media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/branding/googlelogo/1x/googlelogo_color_150x54dp.png) no-repeat;margin-left:-5px}#media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) 0}}#media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:54px;width:150px}
</style>
<a href=//www.google.com/><span id=logo aria-label=Google></span></a>
<p><b>404.</b> <ins>That’s an error.</ins>
<p>The requested URL <code>/gcm/send</code> was not found on this server. <ins>That’s all we know.</ins>

Google Custom Search results in C

I'm trying to write a simple client in C that will interface with the Google Search API and return search results. I am able to send a search request and get a response back with a 200 OK code and some header text, but there are no search results. Am I doing something wrong?
Here is my code:
#include sys/socket.h
#include sys/types.h
#include netinet/in.h
#include netdb.h
#include stdio.h
#include string.h
#include stdlib.h
#include unistd.h
#include errno.h
#include openssl/rand.h
#include openssl/ssl.h
#include openssl/err.h
// Simple structure to keep track of the handle, and
// of what needs to be freed later.
typedef struct {
int socket;
SSL *sslHandle;
SSL_CTX *sslContext;
} connection;
// For this example, we'll be testing on openssl.org
#define KEY "/customsearch/v1?key=AIzaSyAOdB5MgAEmvzglw05rR1OPYEYgFuZrT9o&cx=003397780648636422832:u25rx3s92ro&q="
#define SERVER "www.googleapis.com"
#define PORT 443
// Establish a regular tcp connection
int tcpConnect ()
{
int error, handle;
struct hostent *host;
struct sockaddr_in server;
host = gethostbyname (SERVER);
handle = socket (AF_INET, SOCK_STREAM, 0);
if (handle == -1)
{
perror ("Socket");
handle = 0;
}
else
{
server.sin_family = AF_INET;
server.sin_port = htons (PORT);
server.sin_addr = *((struct in_addr *) host->h_addr);
bzero (&(server.sin_zero), 8);
error = connect (handle, (struct sockaddr *) &server,
sizeof (struct sockaddr));
if (error == -1)
{
perror ("Connect");
handle = 0;
}
}
return handle;
}
// Establish a connection using an SSL layer
connection *sslConnect (void)
{
connection *c;
c = malloc (sizeof (connection));
c->sslHandle = NULL;
c->sslContext = NULL;
c->socket = tcpConnect ();
if (c->socket)
{
// Register the error strings for libcrypto & libssl
SSL_load_error_strings ();
// Register the available ciphers and digests
SSL_library_init ();
// New context saying we are a client, and using SSL 2 or 3
c->sslContext = SSL_CTX_new (SSLv23_client_method ());
if (c->sslContext == NULL)
ERR_print_errors_fp (stderr);
// Create an SSL struct for the connection
c->sslHandle = SSL_new (c->sslContext);
if (c->sslHandle == NULL)
ERR_print_errors_fp (stderr);
// Connect the SSL struct to our connection
if (!SSL_set_fd (c->sslHandle, c->socket))
ERR_print_errors_fp (stderr);
// Initiate SSL handshake
if (SSL_connect (c->sslHandle) != 1)
ERR_print_errors_fp (stderr);
}
else
{
perror ("Connect failed");
}
return c;
}
// Disconnect & free connection struct
void sslDisconnect (connection *c)
{
if (c->socket)
close (c->socket);
if (c->sslHandle)
{
SSL_shutdown (c->sslHandle);
SSL_free (c->sslHandle);
}
if (c->sslContext)
SSL_CTX_free (c->sslContext);
free (c);
}
// Read all available text from the connection
char *sslRead (connection *c)
{
const int readSize = 2048;
char *rc = NULL;
int received, count = 0;
char buffer[2048];
if (c)
{
while (1)
{
if (!rc)
rc = malloc (readSize * sizeof (char) + 1);
else
rc = realloc (rc, (count + 1) *
readSize * sizeof (char) + 1);
received = SSL_read (c->sslHandle, buffer, readSize);
buffer[received] = '\0';
if (received > 0)
strcat (rc, buffer);
if (received < readSize)
break;
count++;
}
}
return rc;
}
// Write text to the connection
void sslWrite (connection *c, char *text)
{
if (c)
SSL_write (c->sslHandle, text, strlen (text)
}
// Very basic main: we send GET / and print the response.
int main (int argc, char **argv)
{
connection *c;
char *response;
char request[512]="";
c = sslConnect ();
sprintf(request, "GET https://%s%s%s\r\n\r\n", SERVER, KEY, argv[1]);
printf("%s", request);
sslWrite (c, request);
response = sslRead (c);
printf ("%s\n", response);
sslDisconnect (c);
free (response);
return 0;
}
Here are my results (running "app_name stove"):
¸h ÆÁ*HTTP/1.0 200 OK
Expires: Wed, 23 May 2012 05:49:58 GMT
Date: Wed, 23 May 2012 05:49:58 GMT
Cache-Control: private, max-age=0, must-revalidate, no-transform
ETag: "ewDGMApuuzSJ2mUepyXm8PLTiIU/uPd2cbC0DjaL0y0Y6HiAvzSqSts"
Content-Type: application/json; charset=UTF-8
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
Server: GSE
There must certainly more information than nothing out there about stoves, right?
The two problems in the above code are #1) the start of rc is not initialized to zero after the malloc and before using strcat -- which results in the garbage characters, and #2) the line if (received < readSize) should be if (received == 0), since servers can potentially send the header and content as separate chunks.

Resources