Skip to content

Comments

feat: support Windows#17

Open
nomyfan wants to merge 3 commits intojvns:mainfrom
nomyfan:feature/support_windows
Open

feat: support Windows#17
nomyfan wants to merge 3 commits intojvns:mainfrom
nomyfan:feature/support_windows

Conversation

@nomyfan
Copy link

@nomyfan nomyfan commented Apr 5, 2021

  • capture packets from an interface
  • conditional compilation
  • fix overflow in get_time function

There's one thing needs to pay attention to(in Cargo.toml). Since we only enable pcap's capture-stream feature on unix, we need to update the publish.yml file to pass down the --features arguments for cargo build.

I have not set up the CI for Windows build yet !!!

nomyfan added 2 commits April 5, 2021 10:03
* capture packets from an interface
* conditional compilation
* fix overflow in get_time function
@nomyfan nomyfan mentioned this pull request Apr 5, 2021
@jvns
Copy link
Owner

jvns commented Apr 5, 2021

Thanks so much for your work on this!

4 questions I have:

  1. Why does this add an interface flag? Is it because the any interface doesn't exist on Windows?
  2. Why does it say to not use the port flag on Windows? (does WinPcap not support using another port?)
  3. Do you know why capture-stream doesn't work on Windows? From some very brief Googling it looks like Tokio has some sort of Windows support, but I don't know a lot about this.
  4. Does the "" feature work on Windows? More specifically -- if you start dnspeep and then send a packet that doesn't get a DNS response (like with dig @127.0.0.1 example.com), do you see that packet printed out with <no response>?. My guess is that it won't because it's not using pcap's stream feature and so tokio's event loop will be blocked.

@nomyfan
Copy link
Author

nomyfan commented Apr 5, 2021

  1. Yes. You can see this example comment from pcap, which points out any is not support on Windows. Moreover, in some scenarios we may only care the packets from the specific interface. With interface flag, we can do this.
  2. I think I can do dome adjustments to combine interface with port working together(DONE with 4307ca2).
  3. capture-stream feature will enable PacketStream that has the dependency chain PacketStream -> SelectableFd -> RawFd while RawFd aka std::os::unix::io::RawFd isn't enabled on Windows. You can explorer it in stream.rs
  4. Yes. It does print out with <no response>, See the figure below.

snipaste_20210406_001218

both windows and unix are supported. on unix, default
interface is `any`. default port is 53.
@nomyfan
Copy link
Author

nomyfan commented Apr 23, 2021

Resolve #15

@sw5ciprl
Copy link

abandoned?

@brian6932
Copy link

webpcap.lib needs to be documented, as it's not straight forward to build at the moment.

build logs
❯ cargo install --git https://github.com/nomyfan/dnspeep --branch feature/support_windows
    Updating git repository `https://github.com/nomyfan/dnspeep`
  Installing dnspeep v0.1.3 (https://github.com/nomyfan/dnspeep?branch=feature%2Fsupport_windows#4307ca2f)
    Updating crates.io index
    Updating git repository `https://github.com/jvns/pcap`
     Locking 91 packages to latest compatible versions
      Adding bytes v1.0.1 (available: v1.10.1)
      Adding dns-message-parser v0.5.0 (available: v0.8.0)
      Adding etherparse v0.9.0 (available: v0.18.0)
      Adding tokio v0.2.25 (available: v1.45.0)
   Compiling winapi v0.3.9
   Compiling proc-macro2 v1.0.95
   Compiling unicode-ident v1.0.18
   Compiling autocfg v1.4.0
   Compiling winapi-build v0.1.1
   Compiling winapi v0.2.8
   Compiling memchr v2.7.4
   Compiling futures-core v0.3.31
   Compiling regex-syntax v0.8.5
   Compiling cfg-if v0.1.10
   Compiling futures-sink v0.3.31
   Compiling syn v1.0.109
   Compiling pin-project-lite v0.2.16
   Compiling libc v0.2.172
   Compiling iovec v0.1.4
   Compiling futures-io v0.3.31
   Compiling ws2_32-sys v0.2.1
   Compiling kernel32-sys v0.2.2
   Compiling futures-task v0.3.31
   Compiling log v0.4.27
   Compiling pin-utils v0.1.0
   Compiling slab v0.4.9
   Compiling num-traits v0.2.19
   Compiling aho-corasick v1.1.3
   Compiling futures-channel v0.3.31
   Compiling thiserror v1.0.69
   Compiling eyre v0.6.12
   Compiling widestring v0.2.2
   Compiling pin-project-lite v0.1.12
   Compiling bytes v1.0.1
   Compiling once_cell v1.21.3
   Compiling bytes v0.5.6
   Compiling indenter v0.3.3
   Compiling num_cpus v1.16.0
   Compiling byteorder v1.5.0
   Compiling windows-link v0.1.1
   Compiling unicode-width v0.1.14
   Compiling fnv v1.0.7
   Compiling hex v0.4.3
   Compiling regex-automata v0.4.9
   Compiling lazy_static v1.5.0
   Compiling etherparse v0.9.0
   Compiling quote v1.0.40
   Compiling getopts v0.2.21
   Compiling syn v2.0.101
   Compiling chrono v0.4.41
   Compiling regex v1.11.1
   Compiling net2 v0.2.39
   Compiling miow v0.3.7
   Compiling libloading v0.6.7
   Compiling pcap v0.8.1 (https://github.com/jvns/pcap#ae2aa7f5)
   Compiling tokio-macros v0.2.6
   Compiling futures-macro v0.3.31
   Compiling thiserror-impl v1.0.69
   Compiling futures-util v0.3.31
   Compiling miow v0.2.2
   Compiling dns-message-parser v0.5.0
   Compiling mio v0.6.23
   Compiling mio-named-pipes v0.1.7
   Compiling tokio v0.2.25
   Compiling futures-executor v0.3.31
   Compiling futures v0.3.31
   Compiling dnspeep v0.1.3 (~\scoop\persist\rustup-msvc\.cargo\git\checkouts\dnspeep-682aa6d8acb6b0c3\4307ca2)
warning: panic message is not a string literal
   --> src\main.rs:193:20
    |
193 |             panic!(f.to_string())
    |                    ^^^^^^^^^^^^^
    |
    = note: this usage of `panic!()` is deprecated; it will be a hard error in Rust 2021
    = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html>
    = note: `#[warn(non_fmt_panics)]` on by default
help: add a "{}" format string to `Display` the message
    |
193 |             panic!("{}", f.to_string())
    |                    +++++

warning: field `server_port` is never read
  --> src\main.rs:32:5
   |
28 | struct OrigPacket {
   |        ---------- field in this struct
...
32 |     server_port: u16,
   |     ^^^^^^^^^^^
   |
   = note: `OrigPacket` has a derived impl for the trait `Clone`, but this is intentionally ignored during dead code analysis
   = note: `#[warn(dead_code)]` on by default

error: linking with `link.exe` failed: exit code: 1181
  |
  = note: "C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\VC\\Tools\\MSVC\\14.43.34808\\bin\\HostX64\\x64\\link.exe" "/NOLOGO" "/IGNORE:4286" "~\\AppData\\Local\\Temp\\rustcZLRFVx\\symbols.o" "<1 object files omitted>" "~\\AppData\\Local\\Temp\\rustcZLRFVx/{libchrono-8bba49938331960e.rlib,libstd-3c0cd0d9d82a5dea.rlib}.rlib" "<sysroot>\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib/{libcompiler_builtins-*}.rlib" "ws2_32.lib" "kernel32.lib" "advapi32.lib" "cfgmgr32.lib" "fwpuclnt.lib" "gdi32.lib" "kernel32.lib" "msimg32.lib" "ntdll.lib" "opengl32.lib" "synchronization.lib" "user32.lib" "winspool.lib" "ws2_32.lib" "wpcap.lib" "legacy_stdio_definitions.lib" "kernel32.lib" "kernel32.lib" "ntdll.lib" "userenv.lib" "ws2_32.lib" "dbghelp.lib" "/defaultlib:msvcrt" "/NXCOMPAT" "/OUT:~\\AppData\\Local\\Temp\\cargo-installrAffUx\\release\\deps\\dnspeep.exe" "/OPT:REF,ICF" "/DEBUG" "/PDBALTPATH:%_PDB%" "/NATVIS:<sysroot>\\lib\\rustlib\\etc\\intrinsic.natvis" "/NATVIS:<sysroot>\\lib\\rustlib\\etc\\liballoc.natvis" "/NATVIS:<sysroot>\\lib\\rustlib\\etc\\libcore.natvis" "/NATVIS:<sysroot>\\lib\\rustlib\\etc\\libstd.natvis"
  = note: some arguments are omitted. use `--verbose` to show all linker arguments
  = note: LINK : fatal error LNK1181: cannot open input file 'wpcap.lib'␍


warning: `dnspeep` (bin "dnspeep") generated 2 warnings
error: could not compile `dnspeep` (bin "dnspeep") due to 1 previous error; 2 warnings emitted
error: failed to compile `dnspeep v0.1.3 (https://github.com/nomyfan/dnspeep?branch=feature%2Fsupport_windows#4307ca2f)`, intermediate artifacts can be found at `~\AppData\Local\Temp\cargo-installrAffUx`.
To reuse those artifacts with a future compilation, set the environment variable `CARGO_TARGET_DIR` to that path.

@jvns
Copy link
Owner

jvns commented May 22, 2025

I'd be happy to merge this if the build errors can be fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants