mirror of
https://github.com/zaphar/durnitisp.git
synced 2025-07-22 18:19:48 -04:00
Initial commit with DNS resolution
This commit is contained in:
commit
b0de8b5a00
135
Cargo.lock
generated
Normal file
135
Cargo.lock
generated
Normal file
@ -0,0 +1,135 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "argv"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "87b48bbc752e97f1b6d7f237c0fd50056f19417e30b10121d4065d1459270e1d"
|
||||
|
||||
[[package]]
|
||||
name = "ctor"
|
||||
version = "0.1.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "39858aa5bac06462d4dd4b9164848eb81ffc4aa5c479746393598fd193afa227"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "damnitisp"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"gflags",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gflags"
|
||||
version = "0.3.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b85e4af201231c9fbcea144cc9ab6d37a0c7f9fce512a9af4edb4d4cd2aaf320"
|
||||
dependencies = [
|
||||
"argv",
|
||||
"gflags-impl",
|
||||
"inventory",
|
||||
"ref-cast",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gflags-impl"
|
||||
version = "0.3.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "29993a85290f4bbfa1888d19a9c2621188c10b893500a45e516446f88f404a73"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ghost"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1a5bcf1bbeab73aa4cf2fde60a846858dc036163c7c33bec309f8d17de785479"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "inventory"
|
||||
version = "0.1.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "621b50c176968fd3b0bd71f821a28a0ea98db2b5aea966b2fbb8bd1b7d310328"
|
||||
dependencies = [
|
||||
"ctor",
|
||||
"ghost",
|
||||
"inventory-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "inventory-impl"
|
||||
version = "0.1.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f99a4111304bade76468d05beab3487c226e4fe4c4de1c4e8f006e815762db73"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "beae6331a816b1f65d04c45b078fd8e6c93e8071771f41b8163255bbd8d7c8fa"
|
||||
dependencies = [
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ref-cast"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "745c1787167ddae5569661d5ffb8b25ae5fedbf46717eaa92d652221cec72623"
|
||||
dependencies = [
|
||||
"ref-cast-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ref-cast-impl"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7d21b475ab879ef0e315ad99067fa25778c3b0377f57f1b00207448dac1a3144"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.33"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e8d5d96e8cbb005d6959f119f773bfaebb5684296108fb32600c00cde305b2cd"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
|
10
Cargo.toml
Normal file
10
Cargo.toml
Normal file
@ -0,0 +1,10 @@
|
||||
[package]
|
||||
name = "damnitisp"
|
||||
version = "0.1.0"
|
||||
authors = ["Jeremy Wall <jeremy@marzhillstudios.com>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
gflags = "^0.3"
|
54
src/main.rs
Normal file
54
src/main.rs
Normal file
@ -0,0 +1,54 @@
|
||||
use gflags;
|
||||
|
||||
use std::io;
|
||||
use std::net::{SocketAddr, ToSocketAddrs};
|
||||
|
||||
gflags::define! {
|
||||
/// Print this help text.
|
||||
-h, --help = false
|
||||
}
|
||||
|
||||
gflags::define! {
|
||||
/// Delay between lookup attempts in seconds.
|
||||
--delaySec: i32 = 60
|
||||
}
|
||||
|
||||
gflags::define! {
|
||||
/// Port to listen on for exporting variables prometheus style.
|
||||
--listenPort: i32 = 0
|
||||
}
|
||||
|
||||
gflags::define! {
|
||||
/// Retry dns infinitenly until we resolve.
|
||||
--dnsRetryInfinite = false
|
||||
}
|
||||
|
||||
fn resolveAddrs(servers: Vec<&str>) -> io::Result<Vec<SocketAddr>> {
|
||||
let mut results = Vec::new();
|
||||
for name in servers {
|
||||
eprintln!("Resolving {}", name);
|
||||
results.extend(name.to_socket_addrs()?);
|
||||
}
|
||||
return Ok(results);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let default_stun_servers: Vec<&'static str> = vec![
|
||||
"stun.l.google.com:19302",
|
||||
"stun.ekiga.net:3478",
|
||||
"stunserver.org:3478",
|
||||
"stun.xten.com:3478",
|
||||
"stun.softjoys.com:3478",
|
||||
"stun1.noc.ams-ix.net:3478",
|
||||
];
|
||||
let mut stun_servers = gflags::parse();
|
||||
|
||||
if HELP.flag {
|
||||
// TODO print better help than this.
|
||||
gflags::print_help_and_exit(0);
|
||||
}
|
||||
if stun_servers.is_empty() {
|
||||
stun_servers = default_stun_servers;
|
||||
}
|
||||
let socketAddrs = resolveAddrs(stun_servers).unwrap();
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user