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__ */
38 #include <libdabba/macros.h>
39 #include <dabbad/dabbad.h>
40 #include <dabba/dabba.h>
41 #include <dabba/help.h>
42 #include <dabba/interface.h>
43 #include <dabba/capture.h>
45 int run_builtin(struct cmd_struct
*p
, int argc
, const char **argv
)
52 status
= p
->fn(argc
, argv
);
56 /* Somebody closed stdout? */
57 if (fstat(fileno(stdout
), &st
))
59 /* Ignore write errors for pipes and sockets.. */
60 if (S_ISFIFO(st
.st_mode
) || S_ISSOCK(st
.st_mode
))
63 /* Check for ENOSPC and EIO errors.. */
65 perror("write failure on standard output");
70 perror("unknown write failure on standard output");
75 perror("close failed on standard output");
82 static int handle_internal_command(int argc
, const char **argv
)
85 const char *cmd
= argv
[0];
86 static struct cmd_struct commands
[] = {
87 {"interface", cmd_interface
},
88 {"capture", cmd_capture
},
92 if (argc
== 0 || cmd
== NULL
|| !strcmp(cmd
, "--help"))
95 /* Turn "dabba cmd --help" into "dabba help cmd" */
96 if (argc
> 1 && !strcmp(argv
[1], "--help")) {
98 argv
[0] = cmd
= "help";
101 for (i
= 0; i
< ARRAY_SIZE(commands
); i
++) {
102 struct cmd_struct
*p
= commands
+ i
;
103 if (strcmp(p
->cmd
, cmd
))
109 return (run_builtin(p
, argc
, argv
));
112 help_unknown_cmd(cmd
);
117 int main(int argc
, const char **argv
)
125 return (handle_internal_command(argc
, argv
));