Skip to content

Commit 32ea422

Browse files
committed
Removes suffixes
1 parent 6787e82 commit 32ea422

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@ iprev 185.143.223.168
1414
Will produce
1515

1616
```
17-
168.223.143.185.in-addr.arpa
17+
168.223.143.185.
1818
```
19+
20+

src/main.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,26 @@ use std::process;
44

55
fn ip_reverse(ip: &IpAddr) -> String {
66
match ip {
7-
IpAddr::V4(ip4) => ip4_reverse(ip4, "in-addr.arpa"),
8-
IpAddr::V6(ip6) => ip6_reverse(ip6, "ip6.arpa"),
7+
IpAddr::V4(ip4) => ip4_reverse(ip4),
8+
IpAddr::V6(ip6) => ip6_reverse(ip6),
99
}
1010
}
1111

12-
fn ip4_reverse(ip: &Ipv4Addr, suffix: &str) -> String {
13-
let mut rev = String::with_capacity(16 + suffix.len());
12+
fn ip4_reverse(ip: &Ipv4Addr) -> String {
13+
let mut rev = String::with_capacity(16);
1414
for oct in ip.octets().iter().rev() {
1515
rev.push_str(format!("{}.", oct).as_str());
1616
}
17-
rev.push_str(suffix);
1817
rev
1918
}
2019

21-
fn ip6_reverse(ip: &Ipv6Addr, suffix: &str) -> String {
22-
let mut rev = String::with_capacity(64 + suffix.len());
20+
fn ip6_reverse(ip: &Ipv6Addr) -> String {
21+
let mut rev = String::with_capacity(64);
2322
for oct in ip.octets().iter().rev() {
2423
rev.push_str(format!("{:x}.", oct & 0x0fu8).as_str());
2524
// Rust gets mad about right-shifting set bits, so we need to mask + shift
2625
rev.push_str(format!("{:x}.", (oct & 0xf0u8) >> 4u8).as_str());
2726
}
28-
rev.push_str(suffix);
2927
rev
3028
}
3129

0 commit comments

Comments
 (0)