]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
--getinterfaces should be more than sufficient for the control socket.
authorRoy Marples <roy@marples.name>
Thu, 15 Jan 2009 14:22:40 +0000 (14:22 +0000)
committerRoy Marples <roy@marples.name>
Thu, 15 Jan 2009 14:22:40 +0000 (14:22 +0000)
configure.c
configure.h
dhcpcd.c

index 60b1921ac1323b1141fc4fdda292832fd3cd19d2..8e69a1d36efaa913ed05b25f7dfd08be3a0efb74 100644 (file)
@@ -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;
index 52ed900085c880b816868c00f7469ea015c3ca9f..5ee4ab8a9e94977793e65a7c2b2e7ae0c167ad49 100644 (file)
@@ -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 *);
 
index 813adb2aff2231cf4cfb9431c66c31869cc3349a..3e84999450b37c48e271566dd49637b39e77b9eb 100644 (file)
--- 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;