Added webserver and port number specification

This commit is contained in:
Random936
2024-09-22 20:08:41 -07:00
parent 1f7f636219
commit 7ec442c93b
5 changed files with 96 additions and 7 deletions

View File

@@ -3,7 +3,7 @@ use std::net::IpAddr;
use std::path::Path;
use if_addrs::{Interface, get_if_addrs};
fn print_single_interface<P: AsRef<Path>>(iface: Interface, path: P) -> io::Result<()> {
fn print_single_interface<P: AsRef<Path>>(iface: Interface, port: &u16, path: P) -> io::Result<()> {
for entry in fs::read_dir(path)? {
let entry = entry?;
let entry_path = entry.path();
@@ -11,7 +11,7 @@ fn print_single_interface<P: AsRef<Path>>(iface: Interface, path: P) -> io::Resu
let filename = entry_path.file_name().unwrap();
println!("http://{}/{}", iface.ip(), filename.to_str().unwrap());
println!("http://{}:{}/{}", iface.ip(), port, filename.to_str().unwrap());
}
Ok(())
@@ -24,7 +24,7 @@ fn is_last_octet_one(ip: IpAddr) -> bool {
}
}
pub fn print_interface<P: AsRef<Path>>(iface_str: &str, path: P) {
pub fn print_interface<P: AsRef<Path>>(iface_str: &str, port: &u16, path: P) {
for iface in get_if_addrs().unwrap() {
if iface_str == "all" {
if iface.is_loopback() || is_last_octet_one(iface.ip()) {
@@ -34,6 +34,6 @@ pub fn print_interface<P: AsRef<Path>>(iface_str: &str, path: P) {
if iface_str != iface.name { continue }
}
print_single_interface(iface, &path).unwrap();
print_single_interface(iface, port, &path).unwrap();
}
}