Returns the address from the SOCKS socket
(sock: socket.socket)
| 76 | |
| 77 | |
| 78 | def _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 | |
| 97 | def _set_up_fake_getaddrinfo(monkeypatch: pytest.MonkeyPatch) -> None: |
no test coverage detected