Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ pub struct IPTables {
pub is_numeric: bool,
}

/// Returns `None` because iptables only works on linux
#[cfg(not(target_os = "linux"))]
pub fn new(is_ipv6: bool) -> Result<IPTables, Box<dyn Error>> {
Err(error_from_str("iptables only works on Linux"))
/// Returns an error because iptables only works on Linux-based systems
#[cfg(not(any(target_os = "linux", target_os = "android")))]
pub fn new(_is_ipv6: bool) -> Result<IPTables, Box<dyn Error>> {
Err(error_from_str("iptables only works on Linux-based systems"))
}

/// Creates a new `IPTables` Result with the command of 'iptables' if `is_ipv6` is `false`, otherwise the command is 'ip6tables'.
#[cfg(target_os = "linux")]
#[cfg(any(target_os = "linux", target_os = "android"))]
pub fn new(is_ipv6: bool) -> Result<IPTables, Box<dyn Error>> {
let cmd = if is_ipv6 { "ip6tables" } else { "iptables" };

Expand Down Expand Up @@ -184,7 +184,7 @@ impl IPTables {

/// Checks for the existence of the `rule` in the table/chain.
/// Returns true if the rule exists.
#[cfg(target_os = "linux")]
#[cfg(any(target_os = "linux", target_os = "android"))]
pub fn exists(&self, table: &str, chain: &str, rule: &str) -> Result<bool, Box<dyn Error>> {
if !self.has_check {
return self.exists_old_version(table, chain, rule);
Expand All @@ -196,7 +196,7 @@ impl IPTables {

/// Checks for the existence of the `chain` in the table.
/// Returns true if the chain exists.
#[cfg(target_os = "linux")]
#[cfg(any(target_os = "linux", target_os = "android"))]
pub fn chain_exists(&self, table: &str, chain: &str) -> Result<bool, Box<dyn Error>> {
match self.is_numeric {
false => self
Expand Down