* ensures the server certificate doesn't change. Normally this isn't detected
* if a trusted CA for the new server certificate is installed.
*
* ensures the server certificate doesn't change. Normally this isn't detected
* if a trusted CA for the new server certificate is installed.
*
*
* 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
*
* 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
/* For gnutls_*() functions. */
#define GNUTLS_ERROR_EXIT(error, message) \
/* For gnutls_*() functions. */
#define GNUTLS_ERROR_EXIT(error, message) \
fprintf(stderr, "%s: %s\n", message, gnutls_strerror(error)); \
exit(EXIT_FAILURE); \
}
/* Server should shut down. Set by SIGINT handler. */
fprintf(stderr, "%s: %s\n", message, gnutls_strerror(error)); \
exit(EXIT_FAILURE); \
}
/* Server should shut down. Set by SIGINT handler. */
parse_arguments(argc, argv);
port = atoi(argv[argc - 1]);
parse_arguments(argc, argv);
port = atoi(argv[argc - 1]);
action.sa_handler = sigint_handler;
sigaction(SIGINT, &action, NULL);
#endif
action.sa_handler = sigint_handler;
sigaction(SIGINT, &action, NULL);
#endif
result = pthread_create(&thread, NULL,
(void * (*)(void *))&worker_thread,
NULL);
result = pthread_create(&thread, NULL,
(void * (*)(void *))&worker_thread,
NULL);
int socket_option = 1;
setsockopt(server_socket, SOL_SOCKET, SO_REUSEADDR,
&socket_option, sizeof(socket_option));
int socket_option = 1;
setsockopt(server_socket, SOL_SOCKET, SO_REUSEADDR,
&socket_option, sizeof(socket_option));
server_in.sin6_addr = in6addr_any; /* bind to any address */
server_in.sin6_port = htons((uint16_t)port); /* port to bind to */
#endif
server_in.sin6_addr = in6addr_any; /* bind to any address */
server_in.sin6_port = htons((uint16_t)port); /* port to bind to */
#endif
- if (-1 == bind(server_socket, (struct sockaddr *)&server_in,
- sizeof(server_in))) {
+ if (bind(server_socket, (struct sockaddr *)&server_in,
+ sizeof(server_in)) == -1) {
while (!done) {
/* Accept new connection. */
client_socket = accept(server_socket, NULL, NULL);
while (!done) {
/* Accept new connection. */
client_socket = accept(server_socket, NULL, NULL);
P(ringbuffer_free);
ringbuffer[ringbuffer_write] = client_socket;
ringbuffer_write = (ringbuffer_write + 1) % RINGBUFFER_SIZE;
P(ringbuffer_free);
ringbuffer[ringbuffer_write] = client_socket;
ringbuffer_write = (ringbuffer_write + 1) % RINGBUFFER_SIZE;
}
for (i = 0; i < thread_count; i++) {
errno = pthread_join(threads[i], NULL);
}
for (i = 0; i < thread_count; i++) {
errno = pthread_join(threads[i], NULL);
- if (NULL == (position = strchr(optarg, ':'))
- || position == optarg
- || 0 == strlen(position + 1)
- || 0 >= atoi(position + 1)
- || 0xffff < atoi(position + 1)) {
+ if ((position = strchr(optarg, ':')) == NULL
+ || optarg == position
+ || strlen(position + 1) == 0
+ || atoi(position + 1) <= 0
+ || atoi(position + 1) > 0xffff) {
- fprintf(stderr, "\ninvalid -p, format host:port\n");
+ fprintf(stderr, "\ninvalid -p: '%s', format host:port\n",
+ optarg);
GNUTLS_ERROR_EXIT(result, "gnutls_global_init()");
/* Setup GnuTLS cipher suites. */
GNUTLS_ERROR_EXIT(result, "gnutls_global_init()");
/* Setup GnuTLS cipher suites. */
GNUTLS_ERROR_EXIT(result, "gnutls_priority_init()");
/* Generate Diffie-Hellman parameters. */
GNUTLS_ERROR_EXIT(result, "gnutls_priority_init()");
/* Generate Diffie-Hellman parameters. */
GNUTLS_ERROR_EXIT(result, "gnutls_dh_params_generate2()");
}
static void deinitialize_gnutls(void) {
GNUTLS_ERROR_EXIT(result, "gnutls_dh_params_generate2()");
}
static void deinitialize_gnutls(void) {