summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs3
-rw-r--r--src/net.rs40
2 files changed, 43 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
index fec2e1da5e..c65c221aec 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -5,6 +5,9 @@
/// Working with processes.
pub mod process;
+/// Network primitives.
+pub mod net;
+
#[cfg(test)]
mod tests {
#[test]
diff --git a/src/net.rs b/src/net.rs
new file mode 100644
index 0000000000..0906426f7b
--- /dev/null
+++ b/src/net.rs
@@ -0,0 +1,40 @@
+/// Representation of a TCP or UDP endpoint. The host is represented as a String since it can be
+/// both a hostname/domain as well as an IP.
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
+pub struct RemoteAddr {
+ address: String,
+ port: u16,
+}
+
+impl RemoteAddr {
+ /// Constructs a new `RemoteAddr` from the given address and port.
+ pub fn new(address: &str, port: u16) -> Self {
+ RemoteAddr {
+ address: address.to_owned(),
+ port: port,
+ }
+ }
+
+ /// Returns the address associated with this `RemoteAddr`.
+ pub fn address(&self) -> &str {
+ &self.address
+ }
+
+ /// Returns the port associated with this `RemoteAddr`.
+ pub fn port(&self) -> u16 {
+ self.port
+ }
+}
+
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn remote_addr_new_and_getters() {
+ let remote_addr = RemoteAddr::new("a_domain", 543);
+ assert_eq!("a_domain", remote_addr.address());
+ assert_eq!(543, remote_addr.port());
+ }
+}