diff options
author | Carl Lerche <me@carllerche.com> | 2015-02-25 12:24:43 -0800 |
---|---|---|
committer | Carl Lerche <me@carllerche.com> | 2015-02-25 12:24:43 -0800 |
commit | 8a7cd5675d38365d96e322693f455b2cd7fea6e5 (patch) | |
tree | 860341241eddeda0168c06bfbdb2d6d1df1ec702 /test/sys/test_socket.rs | |
parent | fcc952a18c054821480964bc1b0f7b32e7728e62 (diff) | |
download | nix-8a7cd5675d38365d96e322693f455b2cd7fea6e5.zip |
Large cleanup, mostly of socket functions
Diffstat (limited to 'test/sys/test_socket.rs')
-rw-r--r-- | test/sys/test_socket.rs | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/test/sys/test_socket.rs b/test/sys/test_socket.rs index 1c80fad9..588ba815 100644 --- a/test/sys/test_socket.rs +++ b/test/sys/test_socket.rs @@ -1,8 +1,10 @@ -use nix::sys::socket::{SockAddr, ToSockAddr, FromSockAddr}; +use nix::sys::socket::{SockAddr, ToSockAddr, FromSockAddr, getsockname}; use std::{mem, net}; use std::num::Int; use std::path::{Path, PathBuf}; use std::str::FromStr; +use std::os::unix::AsRawFd; +use ports::localhost; #[test] pub fn test_inetv4_addr_to_sock_addr() { @@ -11,12 +13,14 @@ pub fn test_inetv4_addr_to_sock_addr() { match addr { SockAddr::IpV4(addr) => { - assert_eq!(addr.sin_addr.s_addr, Int::from_be(2130706433)); - assert_eq!(addr.sin_port, 3000); + assert_eq!(addr.sin_addr.s_addr, 0x7f000001.to_be()); + assert_eq!(addr.sin_port, 3000.to_be()); } _ => panic!("nope"), } + assert_eq!(addr.to_str(), "127.0.0.1:3000"); + let inet = FromSockAddr::from_sock_addr(&addr).unwrap(); assert_eq!(actual, inet); } @@ -37,3 +41,14 @@ pub fn test_path_to_sock_addr() { let path: PathBuf = FromSockAddr::from_sock_addr(&addr).unwrap(); assert_eq!(actual, &*path); } + +#[test] +pub fn test_getsockname() { + use std::net::TcpListener; + + let addr = localhost(); + let sock = TcpListener::bind(&*addr).unwrap(); + let res = getsockname(sock.as_raw_fd()).unwrap(); + + assert_eq!(addr, res.to_str()); +} |