MCPcopy Create free account
hub / github.com/Dstack-TEE/dstack / parses_v2_ipv4

Function parses_v2_ipv4

gateway/src/pp.rs:220–236  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

218
219 #[tokio::test]
220 async fn parses_v2_ipv4() {
221 // v2 magic + ver/cmd 0x21 + family/proto 0x11 (TCP/IPv4) + len 12
222 let mut header = Vec::new();
223 header.extend_from_slice(V2_PROTOCOL_PREFIX);
224 header.extend_from_slice(&[0x21, 0x11, 0x00, 0x0c]);
225 header.extend_from_slice(&[1, 2, 3, 4]); // src ip
226 header.extend_from_slice(&[5, 6, 7, 8]); // dst ip
227 header.extend_from_slice(&11111u16.to_be_bytes()); // src port
228 header.extend_from_slice(&22222u16.to_be_bytes()); // dst port
229
230 let (_stream, parsed) = read_proxy_header(&header[..]).await.expect("v2 parse");
231 let (src, dst) = extract_v4(parsed);
232 assert_eq!(src.ip().octets(), [1, 2, 3, 4]);
233 assert_eq!(src.port(), 11111);
234 assert_eq!(dst.ip().octets(), [5, 6, 7, 8]);
235 assert_eq!(dst.port(), 22222);
236 }
237
238 #[tokio::test]
239 async fn rejects_no_prefix() {

Callers

nothing calls this directly

Calls 2

read_proxy_headerFunction · 0.85
extract_v4Function · 0.85

Tested by

no test coverage detected