X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=tests%2Fclient.c;h=4995536c548bdd14f4e2fcd661c9c3e175b20205;hb=93c48dd90c3ae976b997b3a776a3775167b42369;hp=41ddf5d1a3a2573de54a85e901f533ca42e08dd1;hpb=5c495b3f7f1e4553c7f8212675b212f2b2a6fdb2;p=tlsproxy%2Ftlsproxy.git diff --git a/tests/client.c b/tests/client.c index 41ddf5d..4995536 100644 --- a/tests/client.c +++ b/tests/client.c @@ -20,7 +20,9 @@ #include #include +#include #include +#include #include #include #include @@ -39,6 +41,12 @@ static int fdopen_read_write(int socket, FILE **read_fd, FILE **write_fd); static int connect_to_host(const char *hostname, const char *port); static int read_http_request(FILE *client_fd, char *request, size_t length); +#if 0 +static void log_function_gnutls(int level, const char *string) { + (void)level; + fprintf(stderr, " => %s", string); +} +#endif int main (int argc, char *argv[]) { int result, response; @@ -65,6 +73,11 @@ int main (int argc, char *argv[]) { gnutls_global_init(); gnutls_certificate_allocate_credentials(&xcred); +#if 0 + gnutls_global_set_log_level(10); + gnutls_global_set_log_function(log_function_gnutls); +#endif + gnutls_certificate_set_x509_trust_file(xcred, argv[1], GNUTLS_X509_FMT_PEM); @@ -87,7 +100,7 @@ int main (int argc, char *argv[]) { } fprintf(fd_write, "\r\n"); fflush(fd_write); - if (read_http_request(fd_read, buffer, sizeof(buffer)) == -1) { + if (read_http_request(fd_read, buffer, sizeof(buffer)) != 0) { fprintf(stderr, "invalid proxy response\n"); return EXIT_FAILURE; } @@ -104,7 +117,12 @@ int main (int argc, char *argv[]) { return EXIT_FAILURE; } +#ifdef HAVE_GNUTLS_TRANSPORT_SET_INT2 + /* gnutls_transport_set_int() is a macro. */ + gnutls_transport_set_int(session, server); +#else gnutls_transport_set_ptr(session, (gnutls_transport_ptr_t)server); +#endif result = gnutls_handshake(session); if (result != GNUTLS_E_SUCCESS) { @@ -208,8 +226,10 @@ static int connect_to_host(const char *hostname, const char *port) { gai_hints.ai_socktype = SOCK_STREAM; gai_hints.ai_protocol = 0; gai_hints.ai_flags = AI_NUMERICSERV /* given port is numeric */ +#ifdef AI_ADDRCONFIG | AI_ADDRCONFIG /* supported by this computer */ - | AI_V4MAPPED; /* support IPv4 through IPv6 */ +#endif + ; gai_return = getaddrinfo(hostname, port, &gai_hints, &gai_result); if (gai_return != 0) { if (gai_return == EAI_SYSTEM) { @@ -253,6 +273,7 @@ static int connect_to_host(const char *hostname, const char *port) { static int read_http_request(FILE *client_fd, char *request, size_t length) { char buffer[MAX_REQUEST_LINE]; + assert(length <= INT_MAX); if (fgets(request, (int)length, client_fd) == NULL) { if (ferror(client_fd)) { perror("read_http_request(): fgets()"); @@ -271,6 +292,8 @@ static int read_http_request(FILE *client_fd, char *request, size_t length) { if (ferror(client_fd)) { perror("read_http_request(): fgets()"); return -1; + } else if (feof(client_fd)) { + return -2; } return 0;