• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * tipc.	TIPC utility frontend.
3  *
4  *		This program is free software; you can redistribute it and/or
5  *		modify it under the terms of the GNU General Public License
6  *		as published by the Free Software Foundation; either version
7  *		2 of the License, or (at your option) any later version.
8  *
9  * Authors:	Richard Alpe <richard.alpe@ericsson.com>
10  */
11 
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <getopt.h>
15 #include <unistd.h>
16 
17 #include "bearer.h"
18 #include "link.h"
19 #include "nametable.h"
20 #include "socket.h"
21 #include "media.h"
22 #include "node.h"
23 #include "peer.h"
24 #include "cmdl.h"
25 
26 int help_flag;
27 
about(struct cmdl * cmdl)28 static void about(struct cmdl *cmdl)
29 {
30 	fprintf(stderr,
31 		"Transparent Inter-Process Communication Protocol\n"
32 		"Usage: %s [OPTIONS] COMMAND [ARGS] ...\n"
33 		"\n"
34 		"Options:\n"
35 		" -h, --help \t\tPrint help for last given command\n"
36 		"\n"
37 		"Commands:\n"
38 		" bearer                - Show or modify bearers\n"
39 		" link                  - Show or modify links\n"
40 		" media                 - Show or modify media\n"
41 		" nametable             - Show nametable\n"
42 		" node                  - Show or modify node related parameters\n"
43 		" peer                  - Peer related operations\n"
44 		" socket                - Show sockets\n",
45 		cmdl->argv[0]);
46 }
47 
main(int argc,char * argv[])48 int main(int argc, char *argv[])
49 {
50 	int i;
51 	int res;
52 	struct cmdl cmdl;
53 	const struct cmd cmd = {"tipc", NULL, about};
54 	struct option long_options[] = {
55 		{"help", no_argument, 0, 'h'},
56 		{0, 0, 0, 0}
57 	};
58 	const struct cmd cmds[] = {
59 		{ "bearer",	cmd_bearer,	cmd_bearer_help},
60 		{ "link",	cmd_link,	cmd_link_help},
61 		{ "media",	cmd_media,	cmd_media_help},
62 		{ "nametable",	cmd_nametable,	cmd_nametable_help},
63 		{ "node",	cmd_node,	cmd_node_help},
64 		{ "peer",	cmd_peer,	cmd_peer_help},
65 		{ "socket",	cmd_socket,	cmd_socket_help},
66 		{ NULL }
67 	};
68 
69 	do {
70 		int option_index = 0;
71 
72 		i = getopt_long(argc, argv, "h", long_options, &option_index);
73 
74 		switch (i) {
75 		case 'h':
76 			/*
77 			 * We want the help for the last command, so we flag
78 			 * here in order to print later.
79 			 */
80 			help_flag = 1;
81 			break;
82 		case -1:
83 			/* End of options */
84 			break;
85 		default:
86 			/* Invalid option, error msg is printed by getopts */
87 			return 1;
88 		}
89 	} while (i != -1);
90 
91 	cmdl.optind = optind;
92 	cmdl.argc = argc;
93 	cmdl.argv = argv;
94 
95 	if ((res = run_cmd(NULL, &cmd, cmds, &cmdl, NULL)) != 0)
96 		return 1;
97 
98 	return 0;
99 }
100