[cli] add srp server port command to retrieve SRP server port (#11373)

This commit adds the `srp server port` CLI command, which maps to the
`otSrpServerGetPort()` API. This new command is now used in
`thread-cert/node.py` to implement `get_srp_server_port()`, allowing
direct retrieval of the SRP server port instead of indirectly parsing
the network data entry.
This commit is contained in:
Abtin Keshavarzian
2025-03-31 14:07:37 -07:00
committed by GitHub
parent 793dd9896d
commit 8c30b93fee
3 changed files with 28 additions and 11 deletions
+2 -11
View File
@@ -1264,17 +1264,8 @@ class NodeImpl:
return service
def get_srp_server_port(self):
"""Returns the SRP server UDP port by parsing
the SRP Server Data in Network Data.
"""
for service in self.get_services():
# 0x5d is used to indicate SRP/DNS unicast entry
if int(service[1], 16) == 0x5d:
# The SRP server data contains IPv6 address (16 bytes)
# followed by UDP port number (two bytes) and then
# the version field (one byte)
return int(service[2][2 * 16:2 * 16 + 4], 16)
self.send_command('srp server port')
return int(self._expect_result(r'\d+'))
def srp_client_start(self, server_address, server_port):
self.send_command(f'srp client start {server_address} {server_port}')