X-Git-Url: https://ruderich.org/simon/gitweb/?p=tlsproxy%2Ftlsproxy.git;a=blobdiff_plain;f=tests%2Fclient.c;h=7ed4f05a1519de553a18ef46d381ec5c763d9951;hp=fe10c8ce8b1f0983375797b1d44dcc9c548d1abe;hb=7eba49d24d56288d83746f3f0ce383d7c0c36552;hpb=c51f4531e09a0fcf27aa9f3b5150fbadcf4f1a79 diff --git a/tests/client.c b/tests/client.c index fe10c8c..7ed4f05 100644 --- a/tests/client.c +++ b/tests/client.c @@ -1,7 +1,7 @@ /* * Simple GnuTLS client used for testing. * - * Copyright (C) 2011-2013 Simon Ruderich + * Copyright (C) 2011-2014 Simon Ruderich * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,7 +20,9 @@ #include #include +#include #include +#include #include #include #include @@ -98,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; } @@ -224,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) { @@ -269,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()"); @@ -287,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;