[systemd-devel] sd-bus example code for SetLinkDNS()

Tilman Baumann tilman at baumann.name
Fri Jul 21 12:44:59 UTC 2017


On 21.07.2017 14:35, Lennart Poettering wrote:
> On Wed, 19.07.17 11:20, Tilman Baumann (tilman at baumann.name) wrote:
> 
 >> My guess is that I can have it easier if I somehow use
>> sd_bus_message_append() to assemble the message. But I don't see a clear
>> path either.
> 
> You have to do something like this:
> 
> sd_bus_message_new_method(..., &m);
> sd_bus_message_append(m, "i", ifindex);
> sd_bus_message_open_container(m, 'a', '(iay)');
> for (i = 0; i < n_addresses; i++) {
>         sd_bus_message_open_container(m, '(', "iay"));
>         sd_bus_message_append(m, "i", addresses[i].sin_family);
>         sd_bus_message_append_array(m, 'y', &addresses[i].ip_addr, sizeof(addresses[i].ip_addr));
>         sd_bus_message_close_container(m);
> }
> sd_bus_message_close_container(m);
> sd_bus_message_send(..., m);
> sd_bus_message_unref(m);
> 
> (not tested, just written down from the top of my head, and of course,
> don't forget to add proper error checking)

Phantastic, thanks Lennart


More information about the systemd-devel mailing list