#include #include #include #include "TunDevice.hpp" static const size_t BUFFER_SIZE = 1500; static volatile bool stopped = false; void stop_sig_handler(int signal) { printf("Received signal %d. Stopping.\n", signal); stopped = true; } int main(void) { char read_buffer[BUFFER_SIZE]; signal(SIGINT, stop_sig_handler); try { TunDevice tun_dev("cvpn%d"); printf("Tunnel device opened: <%s>, fd <%d>.\n", tun_dev.get_dev_name().c_str(), tun_dev.get_fd()); while(!stopped) { size_t packet_size = tun_dev.read_packet(read_buffer, BUFFER_SIZE); if(packet_size > 0) { printf("Received packet of size %lu.\n", packet_size); tun_dev.write_packet(read_buffer, packet_size); } } printf("Shutting down.\n"); } catch(const TunDevice::InitializationError& exn) { fprintf(stderr, "ERROR: %s\n", exn.what()); } return 0; }