.Op ports Ar ethX Op ,...
.Op Cd details | summary
.Op Cd hidden
+.Op Cd limit Ar X
.Bd -ragged -offset XXXXXX
Watch for any neighbor changes and report them as soon as they
happen. When specifying ports, the changes are only reported when
.Cd hidden , summary
and
.Cd details
-have the same meaning than previously described.
+have the same meaning than previously described. If
+.Cd limit
+is specificed,
+.Nm
+will exit after receiving the specified number of events.
.Ed
.Cd show configuration
#include "client.h"
#include <string.h>
+#include <limits.h>
/**
* Show neighbors.
struct watcharg {
struct cmd_env *env;
struct writer *w;
+ size_t nb;
};
/**
cmdenv_get(env, "detailed")?DISPLAY_DETAILS:
DISPLAY_NORMAL, protocol);
tag_end(w);
+ wa->nb++;
}
/**
int watch = 1;
struct watcharg wa = {
.env = env,
- .w = w
+ .w = w,
+ .nb = 0
};
+ const char *limit_str = cmdenv_get(env, "limit");
+ size_t limit = 0;
+
+ if (limit_str) {
+ const char *errstr;
+ limit = strtonum(limit_str, 1, LLONG_MAX, &errstr);
+ if (errstr != NULL) {
+ log_warnx("lldpctl", "specified limit (%s) is %s and ignored",
+ limit_str, errstr);
+ }
+ }
+
log_debug("lldpctl", "watch for neighbor changes");
if (lldpctl_watch_callback(conn, watchcb, &wa) < 0) {
log_warnx("lldpctl", "unable to watch for neighbors. %s",
lldpctl_last_strerror(conn));
watch = 0;
}
+ if (limit > 0 && wa.nb >= limit)
+ watch = 0;
}
return 0;
}
"Monitor neighbor changes",
NULL, NULL, NULL);
- /* Neighbors data */
commands_new(watch,
NEWLINE,
"Monitor neighbors change",
NULL, cmd_watch_neighbors, NULL);
+ commands_new(
+ commands_new(watch,
+ "limit",
+ "Don't show more than X events",
+ cmd_check_no_env, NULL, "limit"),
+ NULL,
+ "Stop after getting X events",
+ NULL, cmd_store_env_value_and_pop2, "limit");
+
register_common_commands(watch, 1);
}