#89, use remote ip as second ip in ifconfig on FreeBSD

This commit is contained in:
Erik Ekman 2010-02-08 16:50:45 +00:00 committed by Erik Ekman
parent 465cfe54a3
commit b22e3da5a0
6 changed files with 19 additions and 6 deletions

View File

@ -1492,7 +1492,7 @@ handshake_login(int dns_fd, int seed)
server[64] = 0; server[64] = 0;
client[64] = 0; client[64] = 0;
if (tun_setip(client, netmask) == 0 && if (tun_setip(client, server, netmask) == 0 &&
tun_setmtu(mtu) == 0) { tun_setmtu(mtu) == 0) {
fprintf(stderr, "Server tunnel IP is %s\n", server); fprintf(stderr, "Server tunnel IP is %s\n", server);

View File

@ -2409,12 +2409,14 @@ main(int argc, char **argv)
read_password(password, sizeof(password)); read_password(password, sizeof(password));
} }
created_users = init_users(my_ip, netmask);
if ((tun_fd = open_tun(device)) == -1) { if ((tun_fd = open_tun(device)) == -1) {
retval = 1; retval = 1;
goto cleanup0; goto cleanup0;
} }
if (!skipipconfig) { 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; retval = 1;
goto cleanup1; goto cleanup1;
} }
@ -2431,8 +2433,6 @@ main(int argc, char **argv)
} }
my_mtu = mtu; my_mtu = mtu;
created_users = init_users(my_ip, netmask);
if (created_users < USERS) { if (created_users < USERS) {
fprintf(stderr, "Limiting to %d simultaneous users because of netmask /%d\n", fprintf(stderr, "Limiting to %d simultaneous users because of netmask /%d\n",

View File

@ -426,7 +426,7 @@ read_tun(int tun_fd, char *buf, size_t len)
} }
int int
tun_setip(const char *ip, int netbits) tun_setip(const char *ip, const char *remoteip, int netbits)
{ {
char cmdline[512]; char cmdline[512];
int netmask; int netmask;
@ -458,7 +458,11 @@ tun_setip(const char *ip, int netbits)
"/sbin/ifconfig %s %s %s netmask %s", "/sbin/ifconfig %s %s %s netmask %s",
if_name, if_name,
ip, ip,
#ifdef FREEBSD
remoteip, /* FreeBSD wants other IP as second IP */
#else
ip, ip,
#endif
inet_ntoa(net)); inet_ntoa(net));
fprintf(stderr, "Setting IP of %s to %s\n", if_name, ip); fprintf(stderr, "Setting IP of %s to %s\n", if_name, ip);

View File

@ -21,7 +21,7 @@ int open_tun(const char *);
void close_tun(int); void close_tun(int);
int write_tun(int, char *, size_t); int write_tun(int, char *, size_t);
ssize_t read_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); int tun_setmtu(const unsigned);
#endif /* _TUN_H_ */ #endif /* _TUN_H_ */

View File

@ -85,6 +85,14 @@ init_users(in_addr_t my_ip, int netbits)
return created_users; 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 int
users_waiting_on_reply() users_waiting_on_reply()
{ {

View File

@ -76,6 +76,7 @@ struct user {
extern struct user users[USERS]; extern struct user users[USERS];
int init_users(in_addr_t, int); int init_users(in_addr_t, int);
const char* users_get_first_ip();
int users_waiting_on_reply(); int users_waiting_on_reply();
int find_user_by_ip(uint32_t); int find_user_by_ip(uint32_t);
int all_users_waiting_to_send(); int all_users_waiting_to_send();