meh / rust-tun

TUN device creation and handling.
344 stars 139 forks source link

when change ip addr to new ip addr, but subnet broadcast address no change, in macos m1 #68

Open flyzxt opened 1 year ago

flyzxt commented 1 year ago

os: macos m1

let mut tun_config = tun::Configuration::default();
tun_config.address((10, 0, 0, 1)).netmask((255, 255, 255, 0)).up();

when use default code to create tun device, system route table like blow:

# netstat -nr -f inet
Routing tables

Internet:
Destination        Gateway            Flags               Netif Expire
10.0.0.255         10.0.0.1           UH                 utun14

change address in code, and re run

let mut tun_config = tun::Configuration::default();
tun_config.address((10, 0, 1, 1)).netmask((255, 255, 255, 0)).up();
# netstat -nr -f inet
Routing tables

Internet:
Destination        Gateway            Flags               Netif Expire
10.0.0.255         10.0.1.1           UH                 utun14

I think corret route table is 10.0.1.255, but it's not change.

M0dEx commented 9 months ago

Hi @flyzxt!

For the destination to change, you must call the destination() setter with the desired address on the tun_config:

tun_config
    .address((10, 0, 1, 1))
    .destination((10, 0, 1, 255))
    .netmask((255, 255, 255, 0))
    .up();

Be wary of this on Windows, however, as it override the default gateway.