From 730b81a9d9f231e5fb75175aba98e759900ab955 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Sat, 25 Jun 2016 21:23:53 -0400 Subject: [PATCH] get system hostname --- Cargo.lock | 11 +++++++++++ Cargo.toml | 1 + src/main.rs | 16 ++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 2882237825..f55f57988c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7,6 +7,7 @@ dependencies = [ "hyper 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "iron 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "resolve 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "router 0.0.16 (registry+https://github.com/rust-lang/crates.io-index)", "rust-crypto 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", @@ -315,6 +316,16 @@ dependencies = [ "winapi 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "resolve" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.3.12 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "route-recognizer" version = "0.1.11" diff --git a/Cargo.toml b/Cargo.toml index 51244c76d9..fc4bacd409 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,7 @@ hyper = "0.7.*" iron = "0.2.*" log = "0.3.*" + resolve = "0.1.1" router = "0.0.16" rust-crypto = "0.2.*" rustc-serialize = "0.3.15" diff --git a/src/main.rs b/src/main.rs index 383f7ba5dd..34d3797381 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,6 +6,7 @@ extern crate hound; extern crate iron; #[macro_use] extern crate log; +extern crate resolve; extern crate router; extern crate rustc_serialize; extern crate time; @@ -23,6 +24,7 @@ use std::path::{Path, PathBuf}; use clap::{App, Arg, ArgMatches}; use iron::prelude::*; use router::Router; +use resolve::hostname; use config::Config; use handlers::audio_synth_handler::AudioSynthHandler; @@ -52,6 +54,8 @@ fn main() { VocabularyLibrary::read_from_directory( Path::new(&config.sound_path_development)); + get_hostname(); + start_server(&config, port); } @@ -89,3 +93,15 @@ fn start_server(config: &Config, port: u16) { Iron::new(router).http(("0.0.0.0", port)).unwrap(); } +fn get_hostname() { + match hostname::get_hostname() { + Ok(s) => { println!("Hostname: {}", s); }, + Err(_) => {}, + }; + + /*let len = 34u; + let mut buf = std::vec::from_elem(len, 0u8); + + let err = unsafe {gethostname (vec::raw::to_mut_ptr(buf) as *mut i8, len as u64)}; + if err != 0 { println("oops, gethostname failed"); return; }*/ +}