Compare commits
2 commits
8c8ca6cd60
...
738fa8accf
Author | SHA1 | Date | |
---|---|---|---|
738fa8accf | |||
172076eaad |
2 changed files with 38 additions and 7 deletions
6
flake.lock
generated
6
flake.lock
generated
|
@ -37,11 +37,11 @@
|
|||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1738546358,
|
||||
"narHash": "sha256-nLivjIygCiqLp5QcL7l56Tca/elVqM9FG1hGd9ZSsrg=",
|
||||
"lastModified": 1738680400,
|
||||
"narHash": "sha256-ooLh+XW8jfa+91F1nhf9OF7qhuA/y1ChLx6lXDNeY5U=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "c6e957d81b96751a3d5967a0fd73694f303cc914",
|
||||
"rev": "799ba5bffed04ced7067a91798353d360788b30d",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
|
39
src/main.rs
39
src/main.rs
|
@ -285,6 +285,37 @@ fn load_ip(path: &Path) -> Result<Option<SavedIPs>> {
|
|||
.map(Some)
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
struct Ipv6Prefix {
|
||||
prefix: Ipv6Addr,
|
||||
length: u32,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for Ipv6Prefix {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let Self { prefix, length } = self;
|
||||
write!(f, "{prefix}/{length}")
|
||||
}
|
||||
}
|
||||
|
||||
impl std::str::FromStr for Ipv6Prefix {
|
||||
type Err = miette::Error;
|
||||
|
||||
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
|
||||
let (addr, len) = s.split_once('/').wrap_err("missing `/` in ipv6 prefix")?;
|
||||
Ok(Self {
|
||||
prefix: addr
|
||||
.parse()
|
||||
.into_diagnostic()
|
||||
.wrap_err("invalid ipv6 address for ipv6 prefix")?,
|
||||
length: len
|
||||
.parse()
|
||||
.into_diagnostic()
|
||||
.wrap_err("invalid length for ipv6 prefix")?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[tracing::instrument(err)]
|
||||
fn main() -> Result<()> {
|
||||
// set panic hook to pretty print with miette's formatter
|
||||
|
@ -437,7 +468,7 @@ where
|
|||
struct FritzBoxUpdateParams {
|
||||
/// The domain that should be updated
|
||||
#[allow(unused)]
|
||||
#[serde(default)]
|
||||
#[serde(default, deserialize_with = "empty_string_as_none")]
|
||||
domain: Option<String>,
|
||||
/// IPv4 address for the domain
|
||||
#[serde(default, deserialize_with = "empty_string_as_none")]
|
||||
|
@ -447,11 +478,11 @@ struct FritzBoxUpdateParams {
|
|||
ipv6: Option<Ipv6Addr>,
|
||||
/// IPv6 prefix for the home network
|
||||
#[allow(unused)]
|
||||
#[serde(default)]
|
||||
ipv6prefix: Option<String>,
|
||||
#[serde(default, deserialize_with = "empty_string_as_none")]
|
||||
ipv6prefix: Option<Ipv6Prefix>,
|
||||
/// Whether the networks uses both IPv4 and IPv6
|
||||
#[allow(unused)]
|
||||
#[serde(default)]
|
||||
#[serde(default, deserialize_with = "empty_string_as_none")]
|
||||
dualstack: Option<String>,
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue