It no longer works with a filename.
uint8_t type;
size_t auth_len;
- fd = open(state->leasefile, O_RDONLY);
+ if (state->leasefile[0] == '\0')
+ fd = fileno(stdin);
+ else
+ fd = open(state->leasefile, O_RDONLY);
if (fd == -1) {
if (errno != ENOENT)
logger(ifp->ctx, LOG_ERR, "%s: open `%s': %m",
ifp->name, state->leasefile);
return NULL;
}
- logger(ifp->ctx, LOG_DEBUG, "%s: reading lease `%s'",
- ifp->name, state->leasefile);
+ if (state->leasefile[0] == '\0')
+ logger(ifp->ctx, LOG_DEBUG, "reading standard input");
+ else
+ logger(ifp->ctx, LOG_DEBUG, "%s: reading lease `%s'",
+ ifp->name, state->leasefile);
dhcp = calloc(1, sizeof(*dhcp));
if (dhcp == NULL) {
close(fd);
int retval;
state = D6_STATE(ifp);
- if (stat(state->leasefile, &st) == -1)
- return -1;
- logger(ifp->ctx, LOG_DEBUG, "%s: reading lease `%s'",
- ifp->name, state->leasefile);
+ if (state->leasefile[0] == '\0')
+ logger(ifp->ctx, LOG_DEBUG, "reading standard input");
+ else {
+ if (stat(state->leasefile, &st) == -1)
+ return -1;
+ logger(ifp->ctx, LOG_DEBUG, "%s: reading lease `%s'",
+ ifp->name, state->leasefile);
+ }
if (st.st_size > UINT32_MAX) {
errno = E2BIG;
return -1;
}
- if ((fd = open(state->leasefile, O_RDONLY)) == -1)
+ if (state->leasefile[0] == '\0')
+ fd = fileno(stdin);
+ else
+ fd = open(state->leasefile, O_RDONLY);
+ if (fd == -1)
return -1;
if ((state->new = malloc((size_t)st.st_size)) == NULL)
return -1;
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd November 13, 2015
+.Dd November 18, 2015
.Dt DHCPCD 8
.Os
.Sh NAME
Dumps the last lease for the
.Ar interface
to stdout.
-.Ar interface
-could also be a path to a DHCP wire formatted file.
+If omitted, standard input is used to read a DHCP wire formatted message.
Use the
.Fl 4
or
}
if (ctx.options & DHCPCD_DUMPLEASE) {
- if (optind != argc - 1) {
- logger(&ctx, LOG_ERR,
- "dumplease requires an interface");
- goto exit_failure;
+ if (optind != argc) {
+ /* We need to try and find the interface so we can load
+ * the hardware address to compare automated IAID */
+ ctx.ifaces = if_discover(&ctx,
+ argc - optind, argv + optind);
+ } else {
+ if ((ctx.ifaces = malloc(sizeof(ctx.ifaces))) != NULL)
+ TAILQ_INIT(ctx.ifaces);
}
- i = 0;
- /* We need to try and find the interface so we can
- * load the hardware address to compare automated IAID */
- ctx.ifaces = if_discover(&ctx, 1, argv + optind);
if (ctx.ifaces == NULL) {
logger(&ctx, LOG_ERR, "if_discover: %m");
goto exit_failure;
logger(&ctx, LOG_ERR, "%s: %m", __func__);
goto exit_failure;
}
- strlcpy(ctx.pidfile, argv[optind], sizeof(ctx.pidfile));
+ if (optind != argc)
+ strlcpy(ctx.pidfile, argv[optind],
+ sizeof(ctx.pidfile));
ifp->ctx = &ctx;
TAILQ_INSERT_HEAD(ctx.ifaces, ifp, next);
if (family == 0) {
}
}
configure_interface(ifp, ctx.argc, ctx.argv, 0);
+ i = 0;
if (family == 0 || family == AF_INET) {
if (dhcp_dump(ifp) == -1)
i = 1;