3 * \author written by Emmanuel Roullit emmanuel.roullit@gmail.com (c) 2012
7 /* __LICENSE_HEADER_BEGIN__ */
10 * Copyright (C) 2012 Emmanuel Roullit <emmanuel.roullit@gmail.com>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or (at
15 * your option) any later version.
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
28 /* __LICENSE_HEADER_END__ */
34 dabba interface - Manage network interface
38 dabba interface <command> [<arguments>...] [--help]
42 Give the user the possibility to manage the available network interfaces.
50 Fetch and print information about currenty supported interfaces.
51 The output is formatted in YAML.
59 =item dabba interface list
61 Output the list of network interface which can be used by dabba.
67 Written by Emmanuel Roullit <emmanuel.roullit@gmail.com>
73 =item Please report bugs to <https://github.com/eroullit/dabba/issues>
75 =item dabba project project page: <https://github.com/eroullit/dabba>
83 =item Copyright © 2012 Emmanuel Roullit.
85 =item License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl.html>.
87 =item This is free software: you are free to change and redistribute it.
89 =item There is NO WARRANTY, to the extent permitted by law.
101 #include <libdabba/macros.h>
102 #include <dabba/dabba.h>
103 #include <dabba/ipc.h>
105 static void display_interface_list_header(void)
108 printf(" interfaces:\n");
111 static void display_interface_list(const struct dabba_ipc_msg
const *msg
)
116 assert(msg
->msg_body
.elem_nr
<= ARRAY_SIZE(msg
->msg_body
.msg
.ifconf
));
118 for (a
= 0; a
< msg
->msg_body
.elem_nr
; a
++) {
119 printf(" - %s\n", msg
->msg_body
.msg
.ifconf
[a
].name
);
123 static void prepare_interface_list_query(struct dabba_ipc_msg
*msg
)
127 msg
->msg_body
.type
= DABBA_IFCONF
;
130 static void display_interface_list_msg_header(const struct dabba_ipc_msg
const
135 switch (msg
->msg_body
.type
) {
137 display_interface_list_header();
144 static void display_interface_list_msg(const struct dabba_ipc_msg
const *msg
)
148 switch (msg
->msg_body
.type
) {
150 display_interface_list(msg
);
158 * \brief Request the current supported interface list
159 * \param[in] argc Argument counter
160 * \param[in] argv Argument vector
161 * \return 0 on success, else on failure.
163 * This function prepares an IPC message to query the supported network
164 * interfaces present on the system. Once the message is sent, it waits for the
165 * dabba daemon to reply.
168 int cmd_interface_list(int argc
, const char **argv
)
171 struct dabba_ipc_msg msg
;
176 memset(&msg
, 0, sizeof(msg
));
177 prepare_interface_list_query(&msg
);
178 display_interface_list_msg_header(&msg
);
181 msg
.msg_body
.offset
+= msg
.msg_body
.elem_nr
;
182 msg
.msg_body
.elem_nr
= 0;
184 rc
= dabba_ipc_msg(&msg
);
189 display_interface_list_msg(&msg
);
190 } while (msg
.msg_body
.elem_nr
);
196 * \brief Parse which interface sub-command.
197 * \param[in] argc Argument counter
198 * \param[in] argv Argument vector
199 * \return 0 on success, ENOSYS if the sub-command does not exist,
202 * This function parses the interface sub-command string and the rest of the
203 * argument vector to the proper sub-command handler.
206 int cmd_interface(int argc
, const char **argv
)
208 const char *cmd
= argv
[0];
210 static struct cmd_struct interface_commands
[] = {
211 {"list", cmd_interface_list
}
214 if (argc
== 0 || cmd
== NULL
|| !strcmp(cmd
, "--help"))
217 for (i
= 0; i
< ARRAY_SIZE(interface_commands
); i
++) {
218 struct cmd_struct
*p
= interface_commands
+ i
;
219 if (strcmp(p
->cmd
, cmd
))
221 return (run_builtin(p
, argc
, argv
));