Skip to content

Commit

Permalink
Merge pull request #1207 from stlankes/peer
Browse files Browse the repository at this point in the history
fix conversion from IpAddress::Ipv4 to in_addr
  • Loading branch information
mkroening authored May 19, 2024
2 parents bc20e42 + 1a71b8f commit 716ee54
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
1 change: 0 additions & 1 deletion src/fd/socket/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,6 @@ impl ObjectInterface for Socket {
}
}

#[allow(dead_code)]
fn getpeername(&self) -> Option<IpEndpoint> {
self.with(|socket| socket.remote_endpoint())
}
Expand Down
8 changes: 4 additions & 4 deletions src/syscalls/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl From<sockaddr_in> for IpListenEndpoint {
if addr.sin_addr.s_addr == 0 {
IpListenEndpoint { addr: None, port }
} else {
let s_addr = addr.sin_addr.s_addr.to_be_bytes();
let s_addr = addr.sin_addr.s_addr.to_ne_bytes();

let address = IpAddress::v4(s_addr[0], s_addr[1], s_addr[2], s_addr[3]);

Expand All @@ -116,7 +116,7 @@ impl From<sockaddr_in> for IpListenEndpoint {
impl From<sockaddr_in> for IpEndpoint {
fn from(addr: sockaddr_in) -> IpEndpoint {
let port = u16::from_be(addr.sin_port);
let s_addr = addr.sin_addr.s_addr.to_be_bytes();
let s_addr = addr.sin_addr.s_addr.to_ne_bytes();
let address = IpAddress::v4(s_addr[0], s_addr[1], s_addr[2], s_addr[3]);

IpEndpoint::from((address, port))
Expand All @@ -129,7 +129,7 @@ impl From<IpEndpoint> for sockaddr_in {
match endpoint.addr {
IpAddress::Ipv4(ip) => {
let sin_addr = in_addr {
s_addr: u32::from_be_bytes(ip.as_bytes().try_into().unwrap()),
s_addr: u32::from_ne_bytes(ip.as_bytes().try_into().unwrap()),
};

Self {
Expand Down Expand Up @@ -532,7 +532,7 @@ pub unsafe extern "C" fn sys_getpeername(
obj.map_or_else(
|e| -num::ToPrimitive::to_i32(&e).unwrap(),
|v| {
if let Some(endpoint) = (*v).getsockname() {
if let Some(endpoint) = (*v).getpeername() {
if !addr.is_null() && !addrlen.is_null() {
let addrlen = unsafe { &mut *addrlen };

Expand Down

0 comments on commit 716ee54

Please sign in to comment.