Skip to content

Commit

Permalink
feat: Add SrvRdata struct for SRV resource record type
Browse files Browse the repository at this point in the history
  • Loading branch information
Litr0 committed Jul 17, 2024
1 parent bd583a1 commit 94ecc48
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/message/rdata/srv_rdata.rs
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,
}
}
}

0 comments on commit 94ecc48

Please sign in to comment.