diff --git a/src/interface.cpp b/src/interface.cpp index e106d64..6a8fa70 100644 --- src/interface.cpp +++ src/interface.cpp @@ -1,6 +1,13 @@ #include #include +#ifdef __APPLE__ +struct tun_pi { + unsigned short flags; + unsigned short proto; +}; +#else #include +#endif #include #include #include @@ -94,9 +101,7 @@ void* NetworkInterface::loop() { } return nullptr; } -#ifndef __APPLE__ static const uint8_t required[] = {0x00, 0x00, 0x08, 0x00, 0x45}; -#endif void dump_packet(uint8_t* buffer, ssize_t size) { for(int i = 0; i < size; i++) { printf("%02x ", buffer[i]); diff --git a/src/interface_mac.cpp b/src/interface_mac.cpp index a12c92c..4f8c3be 100644 --- src/interface_mac.cpp +++ src/interface_mac.cpp @@ -10,7 +10,8 @@ static void* start_routine(void* x) { } NetworkInterface::NetworkInterface() : fd(0), my_tox(0) { if((fd = open("/dev/tun0", O_RDWR)) < 0) { - cerr << "unable to open /dev/tun0" << endl; + cerr << "unable to open /dev/tun0: " << strerror(errno) << endl; + exit(-1); } } void NetworkInterface::configure(string myip, Tox* my_tox) { diff --git a/src/main.cpp b/src/main.cpp index eae9170..9a84553 100644 --- src/main.cpp +++ src/main.cpp @@ -62,7 +62,11 @@ bool saveState(Tox* tox) { close(fd); return false; } +#ifdef __APPLE__ + int ret = fcntl(fd, F_FULLFSYNC); +#else int ret = fdatasync(fd); +#endif if (ret == -1) { perror("cant fdatasync to savedata.new"); close(fd); @@ -634,12 +638,6 @@ int main(int argc, char** argv) { maxfd = std::max(maxfd, control->populate_fdset(&readset)); if(toxvpn.listener) maxfd = std::max(maxfd, toxvpn.listener->populate_fdset(&readset)); - { - int udp_sock = tox_get_udp_socket(my_tox); - FD_SET(udp_sock, &readset); - maxfd = std::max(maxfd, udp_sock); - interval = 1000; - } #endif #endif diff --git a/src/route_mac.cpp b/src/route_mac.cpp index a5dca25..55942cf 100644 --- src/route_mac.cpp +++ src/route_mac.cpp @@ -11,3 +11,11 @@ void systemRouteSingle(int ifindex, struct in_addr dest, const char* gateway) { network, netmask); system(buffer); } +void systemRouteDirect(int ifindex, struct in_addr dest) { + char buffer[512]; + char network[16]; + strncpy(network, inet_ntoa(dest), 16); + printf("adding direct route for %s\n", network); + snprintf(buffer, 500, "route add -host %s -interface tun0", network); + system(buffer); +}