I want to read the data available in Link 2; mainly DNS Servers and DNS Domains. I am not able to figure out how to read those data using c sd bus api.
test@ubuntu:~/Desktop/$systemd-resolve --status
Global
DNSSEC NTA: 10.in-addr.arpa
16.172.in-addr.arpa
....bla bla.
Link 2 (ens33)
Current Scopes: DNS
LLMNR setting: yes
MulticastDNS setting: no
DNSSEC setting: no
DNSSEC supported: no
DNS Servers: 49.205.72.130
183.82.243.66
DNS Domain: ~.
If I had to use GetLink method, how could I get the DNS Servers and Domain information?
Needed something similar as below
#define DESTINATION "org.freedesktop.resolve1"
#define PATH "/org/freedesktop/resolve1"
#define INTERFACE "org.freedesktop.resolve1.Manager"
#define MEMBER "GetLink"
static int log_error(int error, const char *message) {
errno = -error;
fprintf(stderr, "%s: %m\n", message);
return error;
}
static int print_unit_path(sd_bus *bus) {
sd_bus_message *m = NULL;
sd_bus_error error = SD_BUS_ERROR_NULL;
sd_bus_message *reply = NULL;
int r;
r = sd_bus_message_new_method_call(bus, &m,
DESTINATION, PATH, INTERFACE, MEMBER);
if (r < 0)
return log_error(r, "Failed to create bus message");
r = sd_bus_message_append(m, "i", 2);
if (r < 0)
return log_error(r, "Failed to append to bus message");
r = sd_bus_call(bus, m, -1, &error, &reply);
if (r < 0)
return log_error(r, "Call failed");
const char *ans;
r = sd_bus_message_read(reply, "o", &ans);
if (r < 0)
return log_error(r, "Failed to read reply");
printf("Link is \"%s\".\n", ans);
}
int main(int argc, char **argv) {
sd_bus *bus = NULL;
int r;
r = sd_bus_open_system(&bus);
if (r < 0)
return log_error(r, "Failed to acquire bus");
print_unit_path(bus);
}
Output: "/org/freedesktop/resolve1/link/_32"
How do I read the DNS using this link?
Thanks