/*
* 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
#include <config.h>
#include <arpa/inet.h>
+#include <assert.h>
#include <errno.h>
+#include <limits.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
if (argc != 5 && argc != 6) {
fprintf(stderr,
"Usage: %s <ca-file> <hostname> <port> <hostname-verify> "
- "[<digest-authentication>]\n",
+ "[<digest-authentication>]\n"
+ "\n"
+ "tlsproxy must be running on port 4711, "
+ "<port> is the <hostname> port.\n",
argv[0]);
return EXIT_FAILURE;
}
}
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;
}
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 */
+#endif
;
gai_return = getaddrinfo(hostname, port, &gai_hints, &gai_result);
if (gai_return != 0) {
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()");
if (ferror(client_fd)) {
perror("read_http_request(): fgets()");
return -1;
+ } else if (feof(client_fd)) {
+ return -2;
}
return 0;