| 62 | }; |
| 63 | |
| 64 | static int |
| 65 | ListCmd(int ac, char **av) |
| 66 | { |
| 67 | struct ng_mesg *resp; |
| 68 | struct namelist *nlist; |
| 69 | struct nodeinfo *ninfo; |
| 70 | int list_hooks = 0; |
| 71 | int named_only = 0; |
| 72 | int ch, rtn = CMDRTN_OK; |
| 73 | |
| 74 | /* Get options */ |
| 75 | optind = 1; |
| 76 | while ((ch = getopt(ac, av, "ln")) != -1) { |
| 77 | switch (ch) { |
| 78 | case 'l': |
| 79 | list_hooks = 1; |
| 80 | break; |
| 81 | case 'n': |
| 82 | named_only = 1; |
| 83 | break; |
| 84 | case '?': |
| 85 | default: |
| 86 | return (CMDRTN_USAGE); |
| 87 | break; |
| 88 | } |
| 89 | } |
| 90 | ac -= optind; |
| 91 | av += optind; |
| 92 | |
| 93 | /* Get arguments */ |
| 94 | switch (ac) { |
| 95 | case 0: |
| 96 | break; |
| 97 | default: |
| 98 | return (CMDRTN_USAGE); |
| 99 | } |
| 100 | |
| 101 | /* Get list of nodes */ |
| 102 | if (NgSendMsg(csock, ".", NGM_GENERIC_COOKIE, |
| 103 | named_only ? NGM_LISTNAMES : NGM_LISTNODES, NULL, 0) < 0) { |
| 104 | warn("send msg"); |
| 105 | return (CMDRTN_ERROR); |
| 106 | } |
| 107 | if (NgAllocRecvMsg(csock, &resp, NULL) < 0) { |
| 108 | warn("recv msg"); |
| 109 | return (CMDRTN_ERROR); |
| 110 | } |
| 111 | |
| 112 | /* Show each node */ |
| 113 | nlist = (struct namelist *) resp->data; |
| 114 | printf("There are %d total %snodes:\n", |
| 115 | nlist->numnames, named_only ? "named " : ""); |
| 116 | ninfo = nlist->nodeinfo; |
| 117 | if (list_hooks) { |
| 118 | char path[NG_PATHSIZ]; |
| 119 | char *argv[2] = { "show", path }; |
| 120 | |
| 121 | while (nlist->numnames > 0) { |