 |
Flowgrind
Advanced TCP traffic generator
|
Utility to instruct the Flowgrind daemon to stop all flows.
More...
#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <xmlrpc-c/base.h>
#include <xmlrpc-c/client.h>
#include "common.h"
#include "fg_definitions.h"
#include "fg_error.h"
#include "fg_progname.h"
#include "fg_rpc_client.h"
#include "fg_argparser.h"
Go to the source code of this file.
|
int | main (int argc, char *argv[]) |
|
static void | stop_flows (const char *address) |
|
static void | usage (short status) |
| Print flowgrind-stop usage and exit. More...
|
|
Utility to instruct the Flowgrind daemon to stop all flows.
Definition in file flowgrind_stop.c.
◆ main()
int main |
( |
int |
argc, |
|
|
char * |
argv[] |
|
) |
| |
Definition at line 141 of file flowgrind_stop.c.
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();
◆ stop_flows()
static void stop_flows |
( |
const char * |
address | ) |
|
|
static |
Definition at line 87 of file flowgrind_stop.c.
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);
◆ usage()
static void usage |
( |
short |
status | ) |
|
|
static |
Print flowgrind-stop usage and exit.
Definition at line 65 of file flowgrind_stop.c.
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",
◆ parser
◆ progname
String containing name the program is called with.
Definition at line 35 of file fg_progname.c.
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.
static struct arg_parser parser
Command line option parser.
@ ap_no
Option without argument (flag).
#define warnx(...)
To report a warning w/ a system error message.
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).
static xmlrpc_env rpc_env
Defines a valid command line option.
#define FLOWGRIND_VERSION
Flowgrind version number.
#define free_all(...)
To free() an arbitrary number of variables.
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.