#############################################################################*/
#include <errno.h>
+#include <stdlib.h>
+#include "address.h"
#include "bus.h"
#include "daemon.h"
#include "logging.h"
return 1;
}
+static int nw_port_bus_get_address(sd_bus* bus, const char* path, const char* interface,
+ const char* property, sd_bus_message* reply, void* data, sd_bus_error* error) {
+ struct nw_port* port = (struct nw_port*)data;
+ int r;
+
+ // Fetch the address
+ const nw_address_t* address = nw_port_get_address(port);
+
+ // Format the address as a string
+ char* s = nw_address_to_string(address);
+ if (!s) {
+ // XXX How to handle any errors?
+ return 0;
+ }
+
+ // Append the address to the return value
+ r = sd_bus_message_append(reply, "s", s);
+ if (r)
+ goto ERROR;
+
+ERROR:
+ if (s)
+ free(s);
+
+ return r;
+}
+
static const sd_bus_vtable port_vtable[] = {
SD_BUS_VTABLE_START(0),
+
+ // Address
+ SD_BUS_PROPERTY("Address", "s", nw_port_bus_get_address,
+ 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
+
SD_BUS_VTABLE_END
};
struct nw_port;
+#include "address.h"
+
int nw_port_create(struct nw_port** port, const char* name);
struct nw_port* nw_port_ref(struct nw_port* port);
char* nw_port_bus_path(struct nw_port* port);
+const nw_address_t* nw_port_get_address(struct nw_port* port);
+
#endif /* NETWORKD_PORT_H */