diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f5e8132..afe1306 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,11 +5,11 @@ repos: hooks: - id: isort args: [ '-m', 'HANGING_INDENT', '-l', '120','--check-only' ] - files: src/client + files: src/rpcclient - repo: https://github.com/pycqa/flake8 rev: "7.0.0" hooks: - id: flake8 args: [ '--max-line-length=127' ] - files: src/client \ No newline at end of file + files: src/rpcclient diff --git a/src/rpcclient/rpcclient/network.py b/src/rpcclient/rpcclient/network.py index 560fef8..df8ec33 100644 --- a/src/rpcclient/rpcclient/network.py +++ b/src/rpcclient/rpcclient/network.py @@ -1,6 +1,7 @@ import socket as pysock import typing from collections import namedtuple +from typing import Optional from rpcclient.allocated import Allocated from rpcclient.darwin.structs import timeval @@ -165,11 +166,14 @@ def unix_connect(self, filename: str) -> Socket: self._client.raise_errno_exception(f'failed connecting to: {filename}') return Socket(self._client, sockfd) - def gethostbyname(self, name: str) -> Hostentry: + def gethostbyname(self, name: str) -> Optional[Hostentry]: + """ Query DNS record. Returns None if not found. """ aliases = [] addresses = [] - - result = hostent(self._client).parse_stream(self._client.symbols.gethostbyname(name)) + result = self._client.symbols.gethostbyname(name) + if result == 0: + return None + result = hostent(self._client).parse_stream(result) p_aliases = result.h_aliases i = 0 diff --git a/src/rpcclient/tests/test_network.py b/src/rpcclient/tests/test_network.py new file mode 100644 index 0000000..de7c43e --- /dev/null +++ b/src/rpcclient/tests/test_network.py @@ -0,0 +1,12 @@ +def test_valid_gethostbyname(client): + """ + :param rpcclient.client.Client client: + """ + assert client.network.gethostbyname('google.com') is not None + + +def test_invalid_gethostbyname(client): + """ + :param rpcclient.client.Client client: + """ + assert client.network.gethostbyname('google.com1') is None