}
#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;
}
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--)
// 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;
}