resolve: add formatted address string to DNSServer

Although the JSON output is mostly intended to be machine readable,
humans also consume the output through logs and scripts.

Add an addressString field to DNSServer to improve human-readability.
This commit is contained in:
Nick Rosbrook
2025-10-10 16:06:47 -04:00
parent f5d5ef9cb4
commit 0d9e5b39d3
2 changed files with 3 additions and 0 deletions

View File

@@ -1373,6 +1373,7 @@ int dns_server_dump_configuration_to_json(DnsServer *server, sd_json_variant **r
return sd_json_buildo(
ret,
JSON_BUILD_PAIR_STRING_NON_EMPTY("addressString", dns_server_string(server)),
JSON_BUILD_PAIR_IN_ADDR("address", &server->address, server->family),
SD_JSON_BUILD_PAIR_INTEGER("family", server->family),
SD_JSON_BUILD_PAIR_UNSIGNED("port", dns_server_port(server)),

View File

@@ -118,6 +118,8 @@ static SD_VARLINK_DEFINE_STRUCT_TYPE(
DNSServer,
SD_VARLINK_FIELD_COMMENT("IPv4 or IPv6 address of the server."),
SD_VARLINK_DEFINE_FIELD(address, SD_VARLINK_INT, SD_VARLINK_ARRAY),
SD_VARLINK_FIELD_COMMENT("IPv4 or IPv6 address of the server, formatted as a human-readable string."),
SD_VARLINK_DEFINE_FIELD(addressString, SD_VARLINK_STRING, SD_VARLINK_NULLABLE),
SD_VARLINK_FIELD_COMMENT("Address family of the server, one of AF_INET or AF_INET6."),
SD_VARLINK_DEFINE_FIELD(family, SD_VARLINK_INT, 0),
SD_VARLINK_FIELD_COMMENT("Port number of the server."),