aboutsummaryrefslogtreecommitdiff
path: root/rustables/src/table.rs
diff options
context:
space:
mode:
authorSimon THOBY <git@nightmared.fr>2021-11-05 06:23:45 +0000
committerSimon THOBY <git@nightmared.fr>2021-11-05 06:23:45 +0000
commit46b22d88c36863851e4b27efa767d28c8aeecfe0 (patch)
treeab1a638de7587e7b73fe64093428218e1c545004 /rustables/src/table.rs
parent3f61ea42bd291c208d07006d8019c25d588f9183 (diff)
parent1bec5a5c30541e47e9c7cff839ac0e7dd3fb6215 (diff)
Merge branch 'manipulate-exprs' into 'master'
Add functions to iterate over the expressions of existing rules See merge request rustwall/rustables!3
Diffstat (limited to 'rustables/src/table.rs')
-rw-r--r--rustables/src/table.rs13
1 files changed, 9 insertions, 4 deletions
diff --git a/rustables/src/table.rs b/rustables/src/table.rs
index dc09b5e..7cc475f 100644
--- a/rustables/src/table.rs
+++ b/rustables/src/table.rs
@@ -38,7 +38,11 @@ impl Table {
pub fn get_name(&self) -> &CStr {
unsafe {
let ptr = sys::nftnl_table_get_str(self.table, sys::NFTNL_TABLE_NAME as u16);
- CStr::from_ptr(ptr)
+ if ptr.is_null() {
+ panic!("Impossible situation: retrieving the name of a chain failed")
+ } else {
+ CStr::from_ptr(ptr)
+ }
}
}
@@ -66,10 +70,11 @@ impl Table {
pub fn get_userdata(&self) -> Option<&CStr> {
unsafe {
let ptr = sys::nftnl_table_get_str(self.table, sys::NFTNL_TABLE_USERDATA as u16);
- if ptr == std::ptr::null() {
- return None;
+ if !ptr.is_null() {
+ Some(CStr::from_ptr(ptr))
+ } else {
+ None
}
- Some(CStr::from_ptr(ptr))
}
}