-
Notifications
You must be signed in to change notification settings - Fork 16
/
main.rs
30 lines (24 loc) · 871 Bytes
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
extern crate nix;
extern crate tokio_core;
extern crate tun2tor;
use std::net::{SocketAddr, IpAddr, Ipv4Addr};
use tokio_core::reactor::Core;
use tun2tor::{Tun, DnsTcpStack, SocksBackend, DnsPortResolver};
use tun2tor::io::stream_transfer;
fn main() {
let mut core = Core::new().unwrap();
let handle = core.handle();
let utun = Tun::new(&handle).unwrap();
utun.set_addr(Ipv4Addr::new(172, 30, 20, 1)).unwrap();
utun.set_netmask(Ipv4Addr::new(255, 255, 255, 255)).unwrap();
let resolver = DnsPortResolver::new(&SocketAddr::new(
IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)),
12345,
));
let backend = SocksBackend::new(&SocketAddr::new(
IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)),
9050,
));
let stack = DnsTcpStack::new(backend, resolver, &handle);
core.run(stream_transfer(stack, utun)).unwrap();
}