#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
parent 8e5d75e426
commit a4f41b7db3
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;
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);

View file

@ -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;
}
@ -2432,8 +2434,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",
created_users, netmask);

View file

@ -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);

View file

@ -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_ */

View file

@ -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()
{

View file

@ -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();