Skip to content

xutianyi1999/SimpleWintun

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SimpleWintun

Wintun rust API library

Usage

wintun.dll (https://www.wintun.net) needs to be in the same directory as the executable file or in System32

Cargo.toml

[dependencies]
simple_wintun = { git = "https://github.com/xutianyi1999/SimpleWintun.git" }

main.rs

use std::net::Ipv4Addr;
use std::ops::Range;
use simple_wintun::adapter::WintunAdapter;

const SRC_ADDR: Range<usize> = 12..16;
const DST_ADDR: Range<usize> = 16..20;

fn main() {
    let adapter = WintunAdapter::create_adapter("example", "test", "{D4C24D32-A723-DB80-A493-4E32E7883F15}").unwrap();
    adapter.set_ipaddr("192.168.8.1", 24).unwrap();
    let session = adapter.start_session(0x20000).unwrap();

    let mut buff = vec![0u8; 65536];

    loop {
        let packet = match session.read_packet(&mut buff) {
            Ok(len) => &buff[..len],
            Err(e) => {
                eprintln!("error: {}", e);
                return
            }
        };

        let mut addr_buff = [0u8; 4];

        addr_buff.copy_from_slice(&packet[SRC_ADDR]);
        let src_addr = Ipv4Addr::from(addr_buff);

        addr_buff.copy_from_slice(&packet[DST_ADDR]);
        let dst_addr = Ipv4Addr::from(addr_buff);

        println!("packet {} -> {}", src_addr, dst_addr)
    }
}

About

Wintun rust API library

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published