From: Roy Marples Date: Thu, 15 Jan 2009 14:22:40 +0000 (+0000) Subject: --getinterfaces should be more than sufficient for the control socket. X-Git-Tag: v5.0.0~121 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5313b78124f566b486748ca071189aba2717d3d4;p=thirdparty%2Fdhcpcd.git --getinterfaces should be more than sufficient for the control socket. --- diff --git a/configure.c b/configure.c index 60b1921a..8e69a1d3 100644 --- a/configure.c +++ b/configure.c @@ -236,7 +236,7 @@ make_env(const struct interface *iface, char ***argv) } int -send_state(int fd, const struct interface *iface) +send_interface(int fd, const struct interface *iface) { char **env, **ep, *s; ssize_t elen; diff --git a/configure.h b/configure.h index 52ed9000..5ee4ab8a 100644 --- a/configure.h +++ b/configure.h @@ -30,7 +30,7 @@ #include "net.h" -int send_state(int, const struct interface *); +int send_interface(int, const struct interface *); int run_script(const struct interface *); int configure(struct interface *); diff --git a/dhcpcd.c b/dhcpcd.c index 813adb2a..3e849994 100644 --- a/dhcpcd.c +++ b/dhcpcd.c @@ -1111,46 +1111,42 @@ handle_args(struct fd_list *fd, int argc, char **argv) { struct interface *ifs, *ifp, *ifl, *ifn, *ift; int do_exit = 0, do_release = 0, do_reboot = 0, opt, oi = 0; - char *s, *p; - ssize_t l, len; + ssize_t len; struct iovec iov[2]; if (fd != NULL) { /* Special commands for our control socket */ if (strcmp(*argv, "--version") == 0) { - l = strlen(VERSION) + 1; - iov[0].iov_base = &l; + len = strlen(VERSION) + 1; + iov[0].iov_base = &len; iov[0].iov_len = sizeof(ssize_t); iov[1].iov_base = UNCONST(VERSION); - iov[1].iov_len = l; + iov[1].iov_len = len; writev(fd->fd, iov, 2); return 0; } else if (strcmp(*argv, "--getinterfaces") == 0) { - l = 0; - for (ifp = ifaces; ifp; ifp = ifp->next) - l += strlen(ifp->name) + 1; - s = p = xmalloc(l); - for (ifp = ifaces; ifp; ifp = ifp->next) { - len = strlen(ifp->name); - memcpy(p, ifp->name, len); - p += len; - *p++ = ' '; + len = 0; + if (argv[1] == NULL ) { + for (ifp = ifaces; ifp; ifp = ifp->next) + len++; + write(fd->fd, &len, sizeof(len)); + for (ifp = ifaces; ifp; ifp = ifp->next) + send_interface(fd->fd, ifp); + return 0; + } + opt = 0; + while (argv[++opt] != NULL) { + for (ifp = ifaces; ifp; ifp = ifp->next) + if (strcmp(argv[opt], ifp->name) == 0) + len++; + } + write(fd->fd, &len, sizeof(len)); + opt = 0; + while (argv[++opt] != NULL) { + for (ifp = ifaces; ifp; ifp = ifp->next) + if (strcmp(argv[opt], ifp->name) == 0) + send_interface(fd->fd, ifp); } - *--p = '\0'; - iov[0].iov_base = &l; - iov[0].iov_len = sizeof(ssize_t); - iov[1].iov_base = s; - iov[1].iov_len = l; - writev(fd->fd, iov, 2); - free(s); - return 0; - } else if (strcmp(*argv, "--getstates") == 0) { - l = 0; - for (ifp = ifaces; ifp; ifp = ifp->next) - l++; - write(fd->fd, &l, sizeof(l)); - for (ifp = ifaces; ifp; ifp = ifp->next) - send_state(fd->fd, ifp); return 0; } else if (strcmp(*argv, "--listen") == 0) { fd->listener = 1;