 |
Flowgrind
Advanced TCP traffic generator
|
Go to the documentation of this file.
37 #include <arpa/inet.h>
39 #include <sys/socket.h>
41 #include <netinet/in.h>
43 #include <xmlrpc-c/base.h>
44 #include <xmlrpc-c/client.h>
60 static void usage(
short status) __attribute__((noreturn));
68 if (status != EXIT_SUCCESS) {
69 fprintf(stderr,
"Try '%s -h' for more information\n",
progname);
74 "Usage: %1$s [OPTION]... [ADDRESS]...\n"
75 "Stop all flows on the daemons running at the given addresses.\n\n"
77 "Mandatory arguments to long options are mandatory for short options too.\n"
78 " -h, --help display this help and exit\n"
79 " -v, --version print version information and exit\n\n"
82 " %1$s localhost 127.2.3.4:5999 example.com\n",
90 xmlrpc_client *client = 0;
91 xmlrpc_value * resultP = 0;
95 char *rpc_address = arg = strdup(address);
96 struct sockaddr_in6 source_in6;
97 source_in6.sin6_family = AF_INET6;
101 if (is_ipv6 && (inet_pton(AF_INET6, rpc_address,
102 (
char*)&source_in6.sin6_addr) <= 0))
103 errx(
"invalid IPv6 address '%s' for RPC", rpc_address);
105 if (port < 1 || port > 65535)
106 errx(
"invalid port for RPC");
110 rc = asprintf(&url,
"http://[%s]:%d/RPC2", rpc_address,
port);
112 rc = asprintf(&url,
"http://%s:%d/RPC2", rpc_address,
port);
115 critx(
"could not allocate memory for RPC URL");
117 printf(
"Stopping all flows on %s\n", url);
120 xmlrpc_env_init(&env);
121 xmlrpc_client_create(&env, XMLRPC_CLIENT_NO_FLAGS,
"Flowgrind",
FLOWGRIND_VERSION, NULL, 0, &client);
122 if (env.fault_occurred)
125 xmlrpc_client_call2f(&env, client, url,
"stop_flow", &resultP,
126 "({s:i})",
"flow_id", -1);
128 xmlrpc_DECREF(resultP);
131 if (env.fault_occurred) {
132 warnx(
"could not stop flows on %s: %s (%d)",
133 url, env.fault_string, env.fault_code);
136 xmlrpc_client_destroy(client);
137 xmlrpc_env_clean(&env);
141 int main(
int argc,
char *argv[])
147 {
'h',
"help",
ap_no, 0, 0},
148 {
'v',
"version",
ap_no, 0, 0},
152 if (!
ap_init(&
parser, argc, (
const char*
const*) argv, options, 0))
153 critx(
"could not allocate memory for option parser");
170 fprintf(stdout,
"%s %s\n%s\n%s\n\n%s\n",
progname,
183 errx(
"no address given");
189 xmlrpc_client_setup_global_const(&
rpc_env);
197 xmlrpc_client_teardown_global_const();
int ap_code(const struct arg_parser *const ap, const int i)
Returns the code of a parsed option with given index.
const char * ap_argument(const struct arg_parser *const ap, const int i)
Returns the argument of a parsed option.
const char * ap_error(const struct arg_parser *const ap)
Get the string containing errors encountered during parsing.
#define FLOWGRIND_COPYRIGHT
Flowgrind's copyright year.
Internal state of the argument parser.
static struct arg_parser parser
Command line option parser.
Error-reporting routines used by Flowgrind.
@ ap_no
Option without argument (flag).
#define warnx(...)
To report a warning w/ a system error message.
int main(int argc, char *argv[])
RPC related functions used by the Flowgrind controller flowgrind-stop.
int code
Short option letter or code (code != 0).
#define errx(...)
To report an error w/o a system error message.
void ap_free(struct arg_parser *const ap)
Free internal state of arg-parser.
#define FLOWGRIND_COPYING
Standard GPL3 no warranty message.
#define critx(...)
To report an critical error w/o a system error message.
const char * progname
String containing name the program is called with.
#define FLOWGRIND_AUTHORS
Flowgrind's authors in a printable string.
int ap_arguments(const struct arg_parser *const ap)
Number of arguments parsed (may be different from argc).
Command line argument parser.
static xmlrpc_env rpc_env
Defines a valid command line option.
Common definitions used by the Flowgrind daemon, controller, and libs.
#define FLOWGRIND_VERSION
Flowgrind version number.
#define free_all(...)
To free() an arbitrary number of variables.
Data structures used by the Flowgrind daemon and controller.
void set_progname(const char *argv0)
Set global variable 'progname', based on argv[0].
#define DEFAULT_LISTEN_PORT
Daemon's default listen port.
bool ap_init(struct arg_parser *const ap, const int argc, const char *const argv[], const struct ap_Option options[], const char in_order)
Initialize the arg-parser given command line and user-defined options.
static void stop_flows(const char *address)
void parse_rpc_address(char **rpc_address, int *port, bool *is_ipv6)
Parse RPC address for the xmlrpc control connection.
static void usage(short status) __attribute__((noreturn))
Print flowgrind-stop usage and exit.