1 /*#############################################################################
3 # IPFire.org - A linux based firewall #
4 # Copyright (C) 2023 IPFire Network Development Team #
6 # This program is free software: you can redistribute it and/or modify #
7 # it under the terms of the GNU General Public License as published by #
8 # the Free Software Foundation, either version 3 of the License, or #
9 # (at your option) any later version. #
11 # This program is distributed in the hope that it will be useful, #
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
14 # GNU General Public License for more details. #
16 # You should have received a copy of the GNU General Public License #
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
19 #############################################################################*/
26 #include <systemd/sd-bus.h>
32 static int networkctl_status(sd_bus
* bus
, int argc
, char* argv
[]) {
33 printf("%s called\n", __FUNCTION__
);
37 static int networkctl_main(sd_bus
* bus
, int argc
, char* argv
[]) {
38 static const struct command commands
[] = {
39 { "port", 0, networkctl_port
},
40 { "status", 0, networkctl_status
},
41 { "zone", 0, networkctl_zone
},
45 return command_dispatch(bus
, commands
, argc
, argv
);
48 static int version(void) {
49 printf("networkctl %s\n", PACKAGE_VERSION
);
54 static int help(void) {
56 "%s [OPTIONS...] COMMAND\n\n"
58 " -h --help Show help\n"
59 " --version Show version\n",
60 program_invocation_short_name
66 static int parse_argv(int argc
, char* argv
[]) {
71 static const struct option options
[] = {
72 { "help", no_argument
, NULL
, 'h' },
73 { "version", no_argument
, NULL
, ARG_VERSION
},
79 c
= getopt_long(argc
, argv
, "h", options
, NULL
);
101 int main(int argc
, char* argv
[]) {
105 // Parse command line arguments
106 r
= parse_argv(argc
, argv
);
110 // Connect to system bus
111 r
= sd_bus_open_system(&bus
);
113 fprintf(stderr
, "Could not connect to system bus: %m\n");
118 r
= networkctl_main(bus
, argc
- 1, argv
+ 1);
122 sd_bus_flush_close_unref(bus
);