2 * Open AnyConnect (SSL + DTLS) client
4 * © 2008 David Woodhouse <dwmw2@infradead.org>
6 * Permission to use, copy, modify, and/or distribute this software
7 * for any purpose with or without fee is hereby granted, provided
8 * that the above copyright notice and this permission notice appear
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
12 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
13 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
14 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
15 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
16 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
17 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
18 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
24 #include <sys/select.h>
27 #include "anyconnect.h"
29 int queue_new_packet(struct pkt **q, int type, void *buf, int len)
34 *q = malloc(sizeof(struct pkt) + len);
41 memcpy((*q)->data, buf, len);
45 int vpn_add_pollfd(struct anyconnect_info *vpninfo, int fd, short events)
48 vpninfo->pfds = realloc(vpninfo->pfds, sizeof(struct pollfd) * vpninfo->nfds);
50 fprintf(stderr, "Failed to reallocate pfds\n");
53 vpninfo->pfds[vpninfo->nfds - 1].fd = fd;
54 vpninfo->pfds[vpninfo->nfds - 1].events = events;
56 return vpninfo->nfds - 1;
61 static void handle_sigint(int sig)
66 int vpn_mainloop(struct anyconnect_info *vpninfo)
69 memset(&sa, 0, sizeof(sa));
70 sa.sa_handler = handle_sigint;
72 sigaction(SIGINT, &sa, NULL);
75 int timeout = INT_MAX;
77 if (vpninfo->dtls_fd != -1)
78 did_work += dtls_mainloop(vpninfo, &timeout);
80 did_work += ssl_mainloop(vpninfo, &timeout);
81 did_work += tun_mainloop(vpninfo, &timeout);
87 printf("Did no work; sleeping for %d ms...\n", timeout);
89 poll(vpninfo->pfds, vpninfo->nfds, timeout);
91 ssl_bye(vpninfo, "Client received SIGINT\n");