# #
#############################################################################*/
+#include <limits.h>
+
#include <systemd/sd-bus.h>
+#include "../networkd/string.h"
#include "command.h"
#include "port.h"
return r;
}
+// Dump
+
+static int networkctl_port_dump(sd_bus* bus, int argc, char* argv[]) {
+ sd_bus_message* reply = NULL;
+ sd_bus_error error = SD_BUS_ERROR_NULL;
+ char path[PATH_MAX];
+ const char* text = NULL;
+ int r;
+
+ if (argc < 1) {
+ fprintf(stderr, "Port required\n");
+ return -EINVAL;
+ }
+
+ // Make port path
+ r = nw_string_format(path, "/org/ipfire/network1/port/%s", argv[0]);
+ if (r < 0)
+ goto ERROR;
+
+ // Call Describe
+ r = sd_bus_call_method(bus, "org.ipfire.network1", path,
+ "org.ipfire.network1.Port", "Describe", &error, &reply, "");
+ if (r < 0) {
+ fprintf(stderr, "Describe() call failed: %m\n");
+ goto ERROR;
+ }
+
+ // Read the text
+ r = sd_bus_message_read(reply, "s", &text);
+ if (r < 0) {
+ fprintf(stderr, "Could not parse bus message: %s\n", strerror(-r));
+ goto ERROR;
+ }
+
+ // Print the text
+ if (text)
+ printf("%s\n", text);
+
+ERROR:
+ if (reply)
+ sd_bus_message_unref(reply);
+
+ return r;
+}
+
+// List
+
static int __networkctl_port_list(sd_bus* bus, const char* path, const char* name, void* data) {
printf("%s\n", name);
int networkctl_port(sd_bus* bus, int argc, char* argv[]) {
static const struct command commands[] = {
+ { "dump", 0, networkctl_port_dump },
{ "list", 0, networkctl_port_list },
{ NULL },
};