*/
int main(int argc, char **argv)
{
- const char msg[] = "GET / HTTP/1.0\r\nHost: www.openssl.org\r\n\r\n";
+ static char msg[384], host_port[300];
SSL_CTX *ctx = NULL;
BIO *b = NULL;
char buf[2048];
int l, res = 1;
+ if (argc < 3) {
+ fprintf(stderr, "usage: %s host port\n", argv[0]);
+ goto fail;
+ }
+
+ snprintf(host_port, sizeof(host_port), "%s:%s\n", argv[1], argv[2]);
+ snprintf(msg, sizeof(msg),
+ "GET / HTTP/1.0\r\nHost: %s\r\n\r\n", argv[1]);
+
ctx = create_ssl_ctx();
if (ctx == NULL) {
fprintf(stderr, "could not create context\n");
goto fail;
}
- b = new_conn(ctx, "www.openssl.org:443");
+ b = new_conn(ctx, host_port);
if (b == NULL) {
fprintf(stderr, "could not create conn\n");
goto fail;
*/
int main(int argc, char **argv)
{
- const char tx_msg[] = "GET / HTTP/1.0\r\nHost: www.openssl.org\r\n\r\n";
+ static char tx_msg[384], host_port[300];
const char *tx_p = tx_msg;
char rx_buf[2048];
int res = 1, l, tx_len = sizeof(tx_msg)-1;
int timeout = 2000 /* ms */;
APP_CONN *conn = NULL;
- SSL_CTX *ctx;
+ SSL_CTX *ctx = NULL;
+
+ if (argc < 3) {
+ fprintf(stderr, "usage: %s host port\n", argv[0]);
+ goto fail;
+ }
+
+ snprintf(host_port, sizeof(host_port), "%s:%s", argv[1], argv[2]);
+ snprintf(tx_msg, sizeof(tx_msg),
+ "GET / HTTP/1.0\r\nHost: %s\r\n\r\n", argv[1]);
ctx = create_ssl_ctx();
if (ctx == NULL) {
goto fail;
}
- conn = new_conn(ctx, "www.openssl.org:443");
+ conn = new_conn(ctx, host_port);
if (conn == NULL) {
fprintf(stderr, "cannot establish connection\n");
goto fail;
int main(int argc, char **argv)
{
int rc, fd = -1, l, res = 1;
- const char msg[] = "GET / HTTP/1.0\r\nHost: www.openssl.org\r\n\r\n";
+ static char msg[300];
struct addrinfo hints = {0}, *result = NULL;
SSL *ssl = NULL;
- SSL_CTX *ctx;
+ SSL_CTX *ctx = NULL;
char buf[2048];
+ if (argc < 3) {
+ fprintf(stderr, "usage: %s host port\n", argv[0]);
+ goto fail;
+ }
+
+ snprintf(msg, sizeof(msg),
+ "GET / HTTP/1.0\r\nHost: %s\r\n\r\n", argv[1]);
+
ctx = create_ssl_ctx();
if (ctx == NULL) {
fprintf(stderr, "cannot create context\n");
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_PASSIVE;
- rc = getaddrinfo("www.openssl.org", "443", &hints, &result);
+ rc = getaddrinfo(argv[1], argv[2], &hints, &result);
if (rc < 0) {
fprintf(stderr, "cannot resolve\n");
goto fail;
goto fail;
}
- ssl = new_conn(ctx, fd, "www.openssl.org");
+ ssl = new_conn(ctx, fd, argv[1]);
if (ssl == NULL) {
fprintf(stderr, "cannot create connection\n");
goto fail;
int main(int argc, char **argv)
{
int rc, fd = -1, res = 1;
- const char tx_msg[] = "GET / HTTP/1.0\r\nHost: www.openssl.org\r\n\r\n";
+ static char tx_msg[300];
const char *tx_p = tx_msg;
char rx_buf[2048];
int l, tx_len = sizeof(tx_msg)-1;
int timeout = 2000 /* ms */;
APP_CONN *conn = NULL;
struct addrinfo hints = {0}, *result = NULL;
- SSL_CTX *ctx;
+ SSL_CTX *ctx = NULL;
+
+ if (argc < 3) {
+ fprintf(stderr, "usage: %s host port\n", argv[0]);
+ goto fail;
+ }
+
+ snprintf(tx_msg, sizeof(tx_msg),
+ "GET / HTTP/1.0\r\nHost: %s\r\n\r\n", argv[1]);
ctx = create_ssl_ctx();
if (ctx == NULL) {
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_PASSIVE;
- rc = getaddrinfo("www.openssl.org", "443", &hints, &result);
+ rc = getaddrinfo(argv[1], argv[2], &hints, &result);
if (rc < 0) {
fprintf(stderr, "cannot resolve\n");
goto fail;
goto fail;
}
- conn = new_conn(ctx, fd, "www.openssl.org");
+ conn = new_conn(ctx, fd, argv[1]);
if (conn == NULL) {
fprintf(stderr, "cannot establish connection\n");
goto fail;
int main(int argc, char **argv)
{
int rc, fd = -1, res = 1;
- const char tx_msg[] = "GET / HTTP/1.0\r\nHost: www.openssl.org\r\n\r\n";
+ static char tx_msg[300];
const char *tx_p = tx_msg;
char rx_buf[2048];
int l, tx_len = sizeof(tx_msg)-1;
int timeout = 2000 /* ms */;
APP_CONN *conn = NULL;
struct addrinfo hints = {0}, *result = NULL;
- SSL_CTX *ctx;
+ SSL_CTX *ctx = NULL;
+
+ if (argc < 3) {
+ fprintf(stderr, "usage: %s host port\n", argv[0]);
+ goto fail;
+ }
+
+ snprintf(tx_msg, sizeof(tx_msg),
+ "GET / HTTP/1.0\r\nHost: %s\r\n\r\n",
+ argv[1]);
ctx = create_ssl_ctx();
if (ctx == NULL) {
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_PASSIVE;
- rc = getaddrinfo("www.openssl.org", "443", &hints, &result);
+ rc = getaddrinfo(argv[1], argv[2], &hints, &result);
if (rc < 0) {
fprintf(stderr, "cannot resolve\n");
goto fail;
goto fail;
}
- conn = new_conn(ctx, "www.openssl.org");
+ conn = new_conn(ctx, argv[1]);
if (conn == NULL) {
fprintf(stderr, "cannot establish connection\n");
goto fail;
app_read_start(conn, post_read, NULL);
}
+char tx_msg[300];
+
static void post_connect(APP_CONN *conn, int status, void *arg)
{
int wr;
- const char tx_msg[] = "GET / HTTP/1.0\r\nHost: www.openssl.org\r\n\r\n";
if (status < 0) {
fprintf(stderr, "failed to connect: %d\n", status);
int main(int argc, char **argv)
{
int rc = 1;
- SSL_CTX *ctx;
+ SSL_CTX *ctx = NULL;
APP_CONN *conn = NULL;
struct addrinfo hints = {0}, *result = NULL;
+ if (argc < 3) {
+ fprintf(stderr, "usage: %s host port\n", argv[0]);
+ goto fail;
+ }
+
+ snprintf(tx_msg, sizeof(tx_msg),
+ "GET / HTTP/1.0\r\nHost: %s\r\n\r\n", argv[1]);
+
ctx = create_ssl_ctx();
if (!ctx)
goto fail;
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_PASSIVE;
- rc = getaddrinfo("www.openssl.org", "443", &hints, &result);
+ rc = getaddrinfo(argv[1], argv[2], &hints, &result);
if (rc < 0) {
fprintf(stderr, "cannot resolve\n");
goto fail;
}
- conn = new_conn(ctx, "www.openssl.org", result->ai_addr, result->ai_addrlen, post_connect, NULL);
+ conn = new_conn(ctx, argv[1], result->ai_addr, result->ai_addrlen, post_connect, NULL);
if (!conn)
goto fail;