1use std::net::{Ipv4Addr, Ipv6Addr};
2
3#[macro_export]
4macro_rules! cfor {
5 ($init: stmt; $cond: expr; $step: expr; $body: block) => {
6 {
7 let mut first = true;
8 $init;
9 while {
10 if first {
11 first = false
12 } else {
13 $step
14 }
15
16 $cond
17 } $body
18 }
19 }
20}
21
22#[inline]
23pub const
24fn IN6_IS_ADDR_V4COMPAT(ipv6: &Ipv6Addr) -> bool
25{
26 if let [0, 0, 0, 0, 0, 0 | 0xffff, ab, cd] = ipv6.segments()
27 {
28 return true;
29 }
30
31 return false;
32}
33
34#[inline]
35pub const
36fn ipv4_u32(ip4: Ipv4Addr) -> u32
37{
38 return u32::from_ne_bytes(ip4.octets());
39}
40
41#[inline]
42pub
43fn strarr2str(arr_slice: &[u8]) -> &str
44{
45 return std::str::from_utf8(arr_slice).unwrap();
46}