MCPcopy
hub / github.com/urllib3/urllib3 / _address_from_socket

Function _address_from_socket

test/contrib/test_socks.py:78–94  ·  view source on GitHub ↗

Returns the address from the SOCKS socket

(sock: socket.socket)

Source from the content-addressed store, hash-verified

76
77
78def _address_from_socket(sock: socket.socket) -> bytes | str:
79 """
80 Returns the address from the SOCKS socket
81 """
82 addr_type = sock.recv(1)
83
84 if addr_type == b"\x01":
85 ipv4_addr = _read_exactly(sock, 4)
86 return socket.inet_ntoa(ipv4_addr)
87 elif addr_type == b"\x04":
88 ipv6_addr = _read_exactly(sock, 16)
89 return socket.inet_ntop(socket.AF_INET6, ipv6_addr)
90 elif addr_type == b"\x03":
91 addr_len = ord(sock.recv(1))
92 return _read_exactly(sock, addr_len)
93 else:
94 raise RuntimeError(f"Unexpected addr type: {addr_type!r}")
95
96
97def _set_up_fake_getaddrinfo(monkeypatch: pytest.MonkeyPatch) -> None:

Callers 1

Calls 2

_read_exactlyFunction · 0.85
recvMethod · 0.45

Tested by

no test coverage detected