diff --git a/src/client.c b/src/client.c index 6845e0f..0036b0e 100644 --- a/src/client.c +++ b/src/client.c @@ -1492,7 +1492,7 @@ handshake_login(int dns_fd, int seed) server[64] = 0; client[64] = 0; - if (tun_setip(client, netmask) == 0 && + if (tun_setip(client, server, netmask) == 0 && tun_setmtu(mtu) == 0) { fprintf(stderr, "Server tunnel IP is %s\n", server); diff --git a/src/iodined.c b/src/iodined.c index 34cd240..84b2281 100644 --- a/src/iodined.c +++ b/src/iodined.c @@ -2409,12 +2409,14 @@ main(int argc, char **argv) read_password(password, sizeof(password)); } + created_users = init_users(my_ip, netmask); + if ((tun_fd = open_tun(device)) == -1) { retval = 1; goto cleanup0; } if (!skipipconfig) { - if (tun_setip(argv[0], netmask) != 0 || tun_setmtu(mtu) != 0) { + if (tun_setip(argv[0], users_get_first_ip(), netmask) != 0 || tun_setmtu(mtu) != 0) { retval = 1; goto cleanup1; } @@ -2431,8 +2433,6 @@ main(int argc, char **argv) } my_mtu = mtu; - - created_users = init_users(my_ip, netmask); if (created_users < USERS) { fprintf(stderr, "Limiting to %d simultaneous users because of netmask /%d\n", diff --git a/src/tun.c b/src/tun.c index df2297e..6802850 100644 --- a/src/tun.c +++ b/src/tun.c @@ -426,7 +426,7 @@ read_tun(int tun_fd, char *buf, size_t len) } int -tun_setip(const char *ip, int netbits) +tun_setip(const char *ip, const char *remoteip, int netbits) { char cmdline[512]; int netmask; @@ -458,7 +458,11 @@ tun_setip(const char *ip, int netbits) "/sbin/ifconfig %s %s %s netmask %s", if_name, ip, +#ifdef FREEBSD + remoteip, /* FreeBSD wants other IP as second IP */ +#else ip, +#endif inet_ntoa(net)); fprintf(stderr, "Setting IP of %s to %s\n", if_name, ip); diff --git a/src/tun.h b/src/tun.h index 3f99dc0..89ffcfa 100644 --- a/src/tun.h +++ b/src/tun.h @@ -21,7 +21,7 @@ int open_tun(const char *); void close_tun(int); int write_tun(int, char *, size_t); ssize_t read_tun(int, char *, size_t); -int tun_setip(const char *, int); +int tun_setip(const char *, const char *, int); int tun_setmtu(const unsigned); #endif /* _TUN_H_ */ diff --git a/src/user.c b/src/user.c index b2e8f04..dfe9c36 100644 --- a/src/user.c +++ b/src/user.c @@ -85,6 +85,14 @@ init_users(in_addr_t my_ip, int netbits) return created_users; } +const char* +users_get_first_ip() +{ + struct in_addr ip; + ip.s_addr = users[0].tun_ip; + return inet_ntoa(ip); +} + int users_waiting_on_reply() { diff --git a/src/user.h b/src/user.h index e32e090..51a6092 100644 --- a/src/user.h +++ b/src/user.h @@ -76,6 +76,7 @@ struct user { extern struct user users[USERS]; int init_users(in_addr_t, int); +const char* users_get_first_ip(); int users_waiting_on_reply(); int find_user_by_ip(uint32_t); int all_users_waiting_to_send();