/* * Copyright (C) 2016 Red Hat, Inc. * Copyright (C) 2013-2016 Nikos Mavrogiannopoulos * * This file is part of GnuTLS. * * GnuTLS is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * GnuTLS is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GnuTLS; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ #ifdef HAVE_CONFIG_H #include #endif #include #include #if defined(_WIN32) || !defined(ENABLE_ALPN) int main(int argc, char **argv) { exit(77); } #else #include #include #include #include #include #include #include #include #include #include "utils.h" static void terminate(void); /* This program tests whether the gnutls_record_get_state() works as * expected. */ static void server_log_func(int level, const char *str) { fprintf(stderr, "server|<%d>| %s", level, str); } static void client_log_func(int level, const char *str) { fprintf(stderr, "client|<%d>| %s", level, str); } /* These are global */ static pid_t child; /* A very basic DTLS client, with anonymous authentication, that negotiates SRTP */ static void dump(const char *name, uint8_t *data, unsigned data_size) { unsigned i; fprintf(stderr, "%s", name); for (i=0;i 0 || ret == GNUTLS_E_AGAIN || ret == GNUTLS_E_INTERRUPTED); if (ret < 0) { fail("error: %s\n", gnutls_strerror(ret)); } /* do not wait for the peer to close the connection. */ gnutls_bye(session, GNUTLS_SHUT_WR); close(fd); gnutls_deinit(session); gnutls_anon_free_server_credentials(anoncred); gnutls_dh_params_deinit(dh_params); gnutls_global_deinit(); if (debug) success("server: finished\n"); } static void start(void) { int fd[2]; int ret; ret = socketpair(AF_UNIX, SOCK_STREAM, 0, fd); if (ret < 0) { perror("socketpair"); exit(1); } child = fork(); if (child < 0) { perror("fork"); fail("fork"); exit(1); } if (child) { int status; /* parent */ server(fd[0]); wait(&status); check_wait_status(status); } else { close(fd[0]); client(fd[1]); exit(0); } } void doit(void) { start(); } #endif /* _WIN32 */