-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add SrvRdata struct for SRV resource record type
- Loading branch information
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use crate::domain_name::DomainName; | ||
|
||
|
||
/// RFC 2782: https://datatracker.ietf.org/doc/html/rfc2782 | ||
/// An struct that represents the `Rdata` for srv type. | ||
pub struct SrvRdata { | ||
/// The priority of this target host. A client MUST attempt to contact the target host with the lowest-numbered priority it can reach; target hosts with the same priority SHOULD be tried in an order defined by the weight field. | ||
priority: u16, | ||
/// A server selection mechanism. The weight field specifies a relative weight for entries with the same priority. Larger weights SHOULD be given a proportionately higher probability of being selected. | ||
weight: u16, | ||
/// The port on this target host of this service. | ||
port: u16, | ||
/// The domain name of the target host. | ||
target: DomainName, | ||
} | ||
|
||
impl SrvRdata { | ||
|
||
/// Creates a new `SrvRdata` with default values. | ||
/// | ||
/// # Example | ||
/// ``` | ||
/// let srv_rdata = SrvRdata::new(); | ||
/// ``` | ||
pub fn new() -> SrvRdata { | ||
SrvRdata { | ||
priority: 0, | ||
weight: 0, | ||
port: 0, | ||
target: DomainName::new(), | ||
} | ||
} | ||
|
||
/// Creates a new `SrvRdata` with the specified values. | ||
/// # Example | ||
/// ``` | ||
/// let srv_rdata = SrvRdata::new_with_values(1, 2, 3, DomainName::new_from_str("www.example.com")); | ||
/// ``` | ||
pub fn new_with_values(priority: u16, weight: u16, port: u16, target: DomainName) -> SrvRdata { | ||
SrvRdata { | ||
priority, | ||
weight, | ||
port, | ||
target, | ||
} | ||
} | ||
} |