{"record":{"id":"596e11c194a990a8","repo":"NationalSecurityAgency/ghidra","slug":"address-must-be-in-the-form-host-port-596e11","errorCode":null,"errorMessage":"address must be in the form 'host:port'","messagePattern":"address must be in the form 'host:port'","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"Ghidra/Debug/Debugger-agent-drgn/src/main/py/src/ghidradrgn/commands.py","lineNumber":161,"sourceCode":"\nSTATE = State()\n\n\ndef ghidra_trace_connect(address: Optional[str] = None) -> None:\n    \"\"\"\n    Connect Python to Ghidra for tracing\n\n    Address must be of the form 'host:port'\n    \"\"\"\n\n    STATE.require_no_client()\n    if address is None:\n        raise RuntimeError(\n            \"'ghidra_trace_connect': missing required argument 'address'\")\n\n    parts = address.split(':')\n    if len(parts) != 2:\n        raise RuntimeError(\"address must be in the form 'host:port'\")\n    host, port = parts\n    try:\n        c = socket.socket()\n        c.connect((host, int(port)))\n        # TODO: Can we get version info from the DLL?\n        STATE.client = Client(c, \"drgn\", methods.REGISTRY)\n        print(f\"Connected to {STATE.client.description} at {address}\")\n    except ValueError:\n        raise RuntimeError(\"port must be numeric\")\n\n\ndef ghidra_trace_listen(address: str = '127.0.0.1:0') -> None:\n    \"\"\"\n    Listen for Ghidra to connect for tracing\n\n    Takes an optional address for the host and port on which to listen.\n    Either the form 'host:port' or just 'port'. If omitted, it will bind\n    to an ephemeral port on localhost. If only the port is given, it will","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Debug/Debugger-agent-drgn/src/main/py/src/ghidradrgn/commands.py#L143-L179","documentation":"Raised as RuntimeError by ghidra_trace_connect() when address.split(':') does not yield exactly two parts. The connect command only accepts the strict 'host:port' form (single colon) — bare ports, IPv6, or extra colons are rejected.","triggerScenarios":"Passing a port-only string ('12345'), an IPv6 literal ('::1:12345'), an empty string, or a value with multiple/no colons to ghidra_trace_connect().","commonSituations":"User enters just a port (should use ghidra_trace_listen or supply host); copy-pasting an IPv6 address; trailing whitespace/colons in the address.","solutions":["Provide the address strictly as 'host:port' (single colon), e.g. '127.0.0.1:12345'.","For port-only input, prepend '127.0.0.1:' or use ghidra_trace_listen instead.","Normalize/strip the address and validate it has exactly one colon before calling."],"exampleFix":"// before\nghidra_trace_connect('12345')       # one part -> RuntimeError\nghidra_trace_connect('host:p:1')    # three parts -> RuntimeError\n// after\nghidra_trace_connect('127.0.0.1:12345')","handlingStrategy":"validation","validationCode":"parts = address.split(':')\nif len(parts) != 2 or not parts[0] or not parts[1]:\n    raise RuntimeError(\"address must be 'host:port' (single colon)\")\nghidra_trace_connect(address)","typeGuard":"import re\n_HOST_PORT = re.compile(r'^[^:]+:[0-9]+$')\ndef is_host_port(address) -> bool:\n    return isinstance(address, str) and bool(_HOST_PORT.match(address))","tryCatchPattern":"try:\n    ghidra_trace_connect(address)\nexcept RuntimeError as e:\n    if 'host:port' in str(e):\n        ghidra_trace_connect('127.0.0.1:' + str(address))  # port-only fixup\n    else:\n        raise","preventionTips":["Supply the address strictly as 'host:port' with a single colon (e.g. '127.0.0.1:12345').","For port-only input, prepend '127.0.0.1:' or use ghidra_trace_listen instead.","Strip whitespace and validate the single-colon shape before calling."],"tags":["drgn","connection","validation","address-format"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}