| 1 | /* |
|---|
| 2 | * Copyright (C) 2009 B.A.T.M.A.N. contributors: |
|---|
| 3 | * |
|---|
| 4 | * Marek Lindner <lindner_marek@yahoo.de> |
|---|
| 5 | * |
|---|
| 6 | * This program is free software; you can redistribute it and/or |
|---|
| 7 | * modify it under the terms of version 2 of the GNU General Public |
|---|
| 8 | * License as published by the Free Software Foundation. |
|---|
| 9 | * |
|---|
| 10 | * This program is distributed in the hope that it will be useful, but |
|---|
| 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|---|
| 13 | * General Public License for more details. |
|---|
| 14 | * |
|---|
| 15 | * You should have received a copy of the GNU General Public License |
|---|
| 16 | * along with this program; if not, write to the Free Software |
|---|
| 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|---|
| 18 | * 02110-1301, USA |
|---|
| 19 | * |
|---|
| 20 | */ |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | #include <sys/time.h> |
|---|
| 24 | #include <stdio.h> |
|---|
| 25 | #include <stdlib.h> |
|---|
| 26 | #include <string.h> |
|---|
| 27 | #include <unistd.h> |
|---|
| 28 | |
|---|
| 29 | #include "main.h" |
|---|
| 30 | #include "proc.h" |
|---|
| 31 | #include "functions.h" |
|---|
| 32 | |
|---|
| 33 | static void interface_usage(void) |
|---|
| 34 | { |
|---|
| 35 | printf("Usage: batctl interface [options] [none|interface] \n"); |
|---|
| 36 | printf("options:\n"); |
|---|
| 37 | printf(" \t -h print this help\n"); |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | int interface(int argc, char **argv) |
|---|
| 41 | { |
|---|
| 42 | int i, res, optchar; |
|---|
| 43 | |
|---|
| 44 | while ((optchar = getopt(argc, argv, "h")) != -1) { |
|---|
| 45 | switch (optchar) { |
|---|
| 46 | case 'h': |
|---|
| 47 | interface_usage(); |
|---|
| 48 | return EXIT_SUCCESS; |
|---|
| 49 | default: |
|---|
| 50 | interface_usage(); |
|---|
| 51 | return EXIT_FAILURE; |
|---|
| 52 | } |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | if (argc == 1) |
|---|
| 56 | return read_file(PROC_ROOT_PATH, PROC_INTERFACES, SINGLE_READ); |
|---|
| 57 | |
|---|
| 58 | for (i = 1; i < argc; i++) { |
|---|
| 59 | if (strcmp(argv[i], "none") == 0) |
|---|
| 60 | res = write_file(PROC_ROOT_PATH, PROC_INTERFACES, ""); |
|---|
| 61 | else |
|---|
| 62 | res = write_file(PROC_ROOT_PATH, PROC_INTERFACES, argv[i]); |
|---|
| 63 | |
|---|
| 64 | if (res != EXIT_SUCCESS) |
|---|
| 65 | return res; |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | return EXIT_SUCCESS; |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | void originators_usage(void) |
|---|
| 72 | { |
|---|
| 73 | printf("Usage: batctl [options] originators \n"); |
|---|
| 74 | printf("options:\n"); |
|---|
| 75 | printf(" \t -h print this help\n"); |
|---|
| 76 | printf(" \t -n don't replace mac addresses with bat-host names\n"); |
|---|
| 77 | printf(" \t -w watch mode - refresh the originator table continuously\n"); |
|---|
| 78 | } |
|---|
| 79 | |
|---|
| 80 | void trans_local_usage(void) |
|---|
| 81 | { |
|---|
| 82 | printf("Usage: batctl [options] translocal \n"); |
|---|
| 83 | printf("options:\n"); |
|---|
| 84 | printf(" \t -h print this help\n"); |
|---|
| 85 | printf(" \t -n don't replace mac addresses with bat-host names\n"); |
|---|
| 86 | printf(" \t -w watch mode - refresh the local translation table continuously\n"); |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | void trans_global_usage(void) |
|---|
| 90 | { |
|---|
| 91 | printf("Usage: batctl [options] transglobal \n"); |
|---|
| 92 | printf("options:\n"); |
|---|
| 93 | printf(" \t -h print this help\n"); |
|---|
| 94 | printf(" \t -n don't replace mac addresses with bat-host names\n"); |
|---|
| 95 | printf(" \t -w watch mode - refresh the global translation table continuously\n"); |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | void orig_interval_usage(void) |
|---|
| 99 | { |
|---|
| 100 | printf("Usage: batctl [options] interval \n"); |
|---|
| 101 | printf("options:\n"); |
|---|
| 102 | printf(" \t -h print this help\n"); |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | void vis_server_usage(void) |
|---|
| 106 | { |
|---|
| 107 | printf("Usage: batctl [options] vis_server \n"); |
|---|
| 108 | printf("options:\n"); |
|---|
| 109 | printf(" \t -h print this help\n"); |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | void aggregation_usage(void) |
|---|
| 113 | { |
|---|
| 114 | printf("Usage: batctl [options] aggregation \n"); |
|---|
| 115 | printf("options:\n"); |
|---|
| 116 | printf(" \t -h print this help\n"); |
|---|
| 117 | } |
|---|
| 118 | |
|---|
| 119 | int handle_table(int argc, char **argv, char *file_path, void table_usage(void)) |
|---|
| 120 | { |
|---|
| 121 | int optchar, read_opt = USE_BAT_HOSTS; |
|---|
| 122 | |
|---|
| 123 | while ((optchar = getopt(argc, argv, "hnw")) != -1) { |
|---|
| 124 | switch (optchar) { |
|---|
| 125 | case 'h': |
|---|
| 126 | table_usage(); |
|---|
| 127 | return EXIT_SUCCESS; |
|---|
| 128 | case 'n': |
|---|
| 129 | read_opt &= ~USE_BAT_HOSTS; |
|---|
| 130 | break; |
|---|
| 131 | case 'w': |
|---|
| 132 | read_opt |= CLR_CONT_READ; |
|---|
| 133 | break; |
|---|
| 134 | default: |
|---|
| 135 | table_usage(); |
|---|
| 136 | return EXIT_FAILURE; |
|---|
| 137 | } |
|---|
| 138 | } |
|---|
| 139 | |
|---|
| 140 | return read_file(PROC_ROOT_PATH, file_path, read_opt); |
|---|
| 141 | } |
|---|
| 142 | |
|---|
| 143 | int handle_proc_setting(int argc, char **argv, char *file_path, void setting_usage(void)) |
|---|
| 144 | { |
|---|
| 145 | int optchar; |
|---|
| 146 | |
|---|
| 147 | while ((optchar = getopt(argc, argv, "h")) != -1) { |
|---|
| 148 | switch (optchar) { |
|---|
| 149 | case 'h': |
|---|
| 150 | setting_usage(); |
|---|
| 151 | return EXIT_SUCCESS; |
|---|
| 152 | default: |
|---|
| 153 | setting_usage(); |
|---|
| 154 | return EXIT_FAILURE; |
|---|
| 155 | } |
|---|
| 156 | } |
|---|
| 157 | |
|---|
| 158 | if (argc == 1) |
|---|
| 159 | return read_file(PROC_ROOT_PATH, file_path, SINGLE_READ); |
|---|
| 160 | |
|---|
| 161 | return write_file(PROC_ROOT_PATH, file_path, argv[1]); |
|---|
| 162 | } |
|---|