2025-10-02 18:39:32 +02:00
|
|
|
/// Utilitaires pour la gestion des adresses IP réseau.
|
|
|
|
|
///
|
|
|
|
|
/// Ce module fournit des fonctions pour détecter et lister les adresses IP
|
|
|
|
|
/// des interfaces réseau locales de la machine.
|
|
|
|
|
///
|
|
|
|
|
/// # Fonctions principales
|
|
|
|
|
///
|
|
|
|
|
/// - [`guess_local_ip`] : Devine l'adresse IP locale utilisée pour les connexions sortantes
|
|
|
|
|
///
|
|
|
|
|
/// # Examples
|
|
|
|
|
///
|
|
|
|
|
/// ```
|
2025-10-09 22:36:33 +02:00
|
|
|
/// use pmoutils::guess_local_ip;
|
2025-10-02 18:39:32 +02:00
|
|
|
///
|
|
|
|
|
/// let ip = guess_local_ip();
|
|
|
|
|
/// println!("Adresse IP locale: {}", ip);
|
|
|
|
|
/// ```
|
2025-10-09 22:36:33 +02:00
|
|
|
pub mod ip_utils;
|
2025-09-23 20:54:50 +02:00
|
|
|
|
2025-10-06 20:24:04 +02:00
|
|
|
pub use ip_utils::guess_local_ip;
|
2025-10-19 12:45:59 +02:00
|
|
|
pub mod process;
|
2025-10-19 13:42:29 +02:00
|
|
|
pub use process::{ProcessPortInfo, TransportProtocol, find_process_using_port};
|
2025-11-28 18:33:03 +01:00
|
|
|
use xmltree::{Element, EmitterConfig};
|
2025-10-06 20:24:04 +02:00
|
|
|
|
|
|
|
|
/// Retourne une chaîne décrivant le système d'exploitation et sa version.
|
|
|
|
|
///
|
|
|
|
|
/// Utilise la crate `os_info` pour obtenir de manière portable et fiable
|
|
|
|
|
/// les informations sur le système d'exploitation courant.
|
|
|
|
|
///
|
|
|
|
|
/// # Format
|
|
|
|
|
/// - macOS: "macOS/15.1" ou "Mac OS/10.15.7"
|
|
|
|
|
/// - Linux: "Linux/6.5.0" ou "Ubuntu/22.04"
|
|
|
|
|
/// - Windows: "Windows/10.0.19045"
|
|
|
|
|
/// - Autre: "{OS}/Unknown"
|
|
|
|
|
///
|
|
|
|
|
/// # Exemples
|
|
|
|
|
///
|
|
|
|
|
/// ```
|
|
|
|
|
/// use pmoutils::get_os_string;
|
|
|
|
|
///
|
|
|
|
|
/// let os = get_os_string();
|
|
|
|
|
/// println!("OS: {}", os); // Ex: "Linux/6.5.0"
|
|
|
|
|
/// ```
|
|
|
|
|
pub fn get_os_string() -> String {
|
|
|
|
|
let info = os_info::get();
|
|
|
|
|
let os_type = format!("{:?}", info.os_type());
|
|
|
|
|
|
|
|
|
|
// Obtenir la version si disponible
|
|
|
|
|
let version = info.version();
|
|
|
|
|
if version != &os_info::Version::Unknown {
|
|
|
|
|
format!("{}/{}", os_type, version)
|
|
|
|
|
} else {
|
|
|
|
|
format!("{}/Unknown", os_type)
|
|
|
|
|
}
|
2025-10-19 12:45:59 +02:00
|
|
|
}
|
2025-11-28 18:33:03 +01:00
|
|
|
|
|
|
|
|
/// Trait générique pour obtenir un élément XML (xmltree::Element).
|
|
|
|
|
///
|
|
|
|
|
/// Aligné sur la signature utilisée dans pmoupnp (UpnpObject::to_xml_element),
|
|
|
|
|
/// afin de pouvoir factoriser la sérialisation XML entre crates.
|
|
|
|
|
pub trait ToXmlElement {
|
|
|
|
|
/// Convertit l'objet en élément XML.
|
|
|
|
|
fn to_xml_element(&self) -> Element;
|
|
|
|
|
|
|
|
|
|
/// Sérialise en chaîne XML formatée.
|
|
|
|
|
fn to_xml(&self) -> String {
|
|
|
|
|
let elem = self.to_xml_element();
|
|
|
|
|
let config = EmitterConfig::new()
|
|
|
|
|
.perform_indent(true)
|
|
|
|
|
.indent_string(" ");
|
|
|
|
|
let mut buf = Vec::new();
|
|
|
|
|
elem.write_with_config(&mut buf, config)
|
|
|
|
|
.expect("Failed to write XML");
|
|
|
|
|
String::from_utf8(buf).expect("Invalid UTF-8")
|
|
|
|
|
}
|
|
|
|
|
}
|