MCPcopy Create free account
hub / github.com/cloud-hypervisor/cloud-hypervisor / test_create_sockaddr

Function test_create_sockaddr

net_util/src/lib.rs:193–210  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

191
192 #[test]
193 fn test_create_sockaddr() {
194 let addr: net::Ipv4Addr = "10.0.0.1".parse().unwrap();
195 let sockaddr = create_sockaddr(addr);
196
197 assert_eq!(sockaddr.sa_family, libc::AF_INET as u16);
198
199 let data = &sockaddr.sa_data[..];
200
201 // The first two bytes should represent the port, which is 0.
202 assert_eq!(data[0], 0);
203 assert_eq!(data[1], 0);
204
205 // The next four bytes should represent the actual IPv4 address, in network order.
206 assert_eq!(data[2], 10);
207 assert_eq!(data[3], 0);
208 assert_eq!(data[4], 0);
209 assert_eq!(data[5], 1);
210 }
211}

Callers

nothing calls this directly

Calls 2

create_sockaddrFunction · 0.85
parseMethod · 0.45

Tested by

no test coverage detected