X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=main.cpp;fp=main.cpp;h=eff9b46a8f14ec4c43aebf23a167620004d51bb7;hb=487fcef7148730fec86f39738823689487ad24c3;hp=09802cee9c6984d44ffed2c68532f83d03f12052;hpb=e18c3c0b38c5be562f6a1e0f268fd743a058d330;p=tunudptotcp diff --git a/main.cpp b/main.cpp index 09802ce..eff9b46 100644 --- a/main.cpp +++ b/main.cpp @@ -29,11 +29,13 @@ int getrandom(void* buf, size_t len, unsigned int flags) { } #endif +#define PACKET_READ_SIZE 1500 -static int tun_alloc(char *dev, int queues, int *fds) +static int tun_alloc(char *dev, const char* local_ip, const char* remote_ip, int queues, int *fds) { struct ifreq ifr; int fd, err, i; + char buf[1024]; if (!dev) return -1; @@ -58,6 +60,23 @@ static int tun_alloc(char *dev, int queues, int *fds) } fds[i] = fd; } + + sprintf(buf, "ip link set %s mtu %d", dev, PACKET_READ_SIZE); + err = system(buf); + if (err) goto err; + + sprintf(buf, "ip addr add %s/32 dev %s", local_ip, dev); + err = system(buf); + if (err) goto err; + + sprintf(buf, "ip link set %s up", dev); + err = system(buf); + if (err) goto err; + + sprintf(buf, "ip route add %s/32 dev %s", remote_ip, dev); + err = system(buf); + if (err) goto err; + return 0; err: for (--i; i >= 0; i--) @@ -585,7 +604,7 @@ int main(int argc, char* argv[]) { // Create tun and bind to sockets... // - if (tun_alloc(tun_name, TUN_IF_COUNT, fd) != 0) { + if (tun_alloc(tun_name, argv[3], argv[2], TUN_IF_COUNT, fd) != 0) { fprintf(stderr, "Failed to alloc tun if\n"); return -1; }