mssql_browser/
lib.rs

1//! # mssql-browser
2//!
3//! mssql-browser is a Rust implementation of the SQL Server Resolution Protocol.
4//!
5//! >The SQL Server Resolution Protocol enables finding endpoint information of MSSQL servers running in the current network.
6//! >
7//! > The SQL Server Resolution Protocol (SSRP) [MC-SQLR] is a simple application-level protocol for the transfer of requests and responses between clients and database server discovery services. To determine the communication endpoint information of a particular database instance, the client sends a single request to a specific machine and waits for a single response. To enumerate database instances in the network and obtain the endpoint information of each instance, the client broadcasts or multicasts a request to the network and waits for responses from different discovery services on the network.
8//! >
9//! > The SQL Server Resolution Protocol is appropriate for retrieving database endpoint information or for database instance enumeration in scenarios where network or local connectivity is available.
10//!
11//! ## Examples
12//! Below are a few different ways to get endpoint information of MSSQL server instances.
13//!
14//! ### Discover endpoint information of instances within network
15//! ```rust
16//! use std::net::{ IpAddr, Ipv4Addr };
17//! use std::error::Error;
18//! use mssql_browser::{ browse, BrowserError };
19//!
20//! async fn run() -> Result<(), Box<dyn Error>> {
21//!   let broadcast_addr = IpAddr::V4(Ipv4Addr::BROADCAST);
22//!   let mut iterator = browse(broadcast_addr).await?;
23//!   
24//!   while let instance = iterator.next().await? {
25//!     println!("Found instance {} on host {}.", instance.instance_name, instance.addr);
26//!   }
27//!   
28//!   Ok(())
29//! }
30//! ```
31//!
32//! ### Discover endpoint information of instances on host
33//! ```rust
34//! use std::net::{ IpAddr, Ipv4Addr };
35//! use std::error::Error;
36//! use mssql_browser::{ browse_host, BrowserError };
37//! 
38//! async fn run() -> Result<(), Box<dyn Error>> {
39//!   let host_addr = IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1));
40//!   let mut iterator = browse_host(host_addr).await?;
41//!   
42//!   while let Some(instance) = iterator.next()? {
43//!     println!("Found instance {}", instance.instance_name);
44//!   }
45//!   
46//!   Ok(())
47//! }
48//! ```
49//!
50//! ### Discover endpoint information of specific instance
51//! ```rust
52//! use std::net::{ IpAddr, Ipv4Addr };
53//! use std::error::Error;
54//! use mssql_browser::{ browse_instance, BrowserError };
55//!
56//! async fn run() -> Result<(), Box<dyn Error>> {
57//!   let host_addr = IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1));
58//!   let instance = browse_instance(host_addr, "MSSQLSERVER").await?;
59//!   
60//!   if let Some(tcp) = instance.tcp_info {
61//!     println!("Instance is available via TCP on port {}", tcp.port);
62//!   }
63//!  
64//!   if let Some(np) = instance.np_info {
65//!     println!("Instance is available via named pipe {}", np.name);
66//!   }
67//!  
68//!   Ok(())
69//! }
70//! ```
71//!
72//! ### Discover DAC endpoint information
73//! ```rust
74//! use std::net::{ IpAddr, Ipv4Addr };
75//! use std::error::Error;
76//! use mssql_browser::{ browse_instance_dac, BrowserError };
77//!
78//! async fn run() -> Result<(), Box<dyn Error>> {
79//!   let host_addr = IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1));
80//!   let dac_info = browse_instance_dac(host_addr, "MSSQLSERVER").await?;
81//!   
82//!   println!("DAC is exposed on port {}", dac_info.port);
83//!  
84//!   Ok(())
85//! }
86//! ```
87
88mod error;
89mod info;
90mod socket;
91
92mod browse;
93mod browse_host;
94mod browse_instance;
95mod browse_instance_dac;
96
97/// Maximum length of an instance name
98pub const MAX_INSTANCE_NAME_LEN: usize = 32;
99
100pub use error::*;
101pub use info::*;
102
103#[cfg(any(feature = "tokio", feature = "async-std"))]
104pub use browse::browse;
105pub use browse::AsyncInstanceIterator;
106#[cfg(any(feature = "tokio", feature = "async-std"))]
107pub use browse_host::browse_host;
108pub use browse_host::InstanceIterator;
109#[cfg(any(feature = "tokio", feature = "async-std"))]
110pub use browse_instance::browse_instance;
111#[cfg(any(feature = "tokio", feature = "async-std"))]
112pub use browse_instance_dac::browse_instance_dac;
113
114/// Types and functions related to using a custom socket implementation
115pub mod custom_socket {
116    pub use super::browse::browse_inner as browse;
117    pub use super::browse_host::browse_host_inner as browse_host;
118    pub use super::browse_instance::browse_instance_inner as browse_instance;
119    pub use super::browse_instance_dac::browse_instance_dac_inner as browse_instance_dac;
120    pub use super::socket::*;
121}