#include <errno.h>
#include <getopt.h>
#include <limits.h>
#include <regex.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
static bool
{
char error_message[PATH_MAX];
int status = regcomp(&
regex, text, REG_EXTENDED | REG_NEWLINE);
if (!status)
return true;
regerror(status, &
regex, error_message,
sizeof(error_message));
fprintf(stderr, "[ERROR] Regex error compiling '%s': %s\n", text, error_message);
return false;
}
static bool
{
const char *p = name;
regmatch_t m;
if (!name)
return false;
if (!regexec(&
regex, p, 1, &m, 0)) {
free(name);
return true;
}
free(name);
return false;
}
static void
{
char *name;
return;
if (!name) {
fprintf(stderr, "[ERROR] Could not get the link's name\n");
return;
}
switch (event) {
printf("Link %s was changed\n", name);
break;
printf("Link %s was added\n", name);
break;
printf("Link %s was removed\n", name);
free(name);
return;
break;
default:
break;
}
uint16_t i;
printf("\tUP ");
addr_str.used = 0;
}
printf("\n");
} else {
printf("\tDOWN\n");
}
free(name);
}
static void
{
char *regexp = NULL;
static const struct option opts[] = {
{ "interface", required_argument, NULL, 'i' },
{ "help", no_argument, NULL, 'h' },
{ 0, 0, 0, 0 }
};
while ((c = getopt_long(argc, argv, "i:h", opts, &opt_idx)) != -1) {
switch (c) {
case 'i':
regexp = optarg;
break;
case 'h':
default:
fprintf(stderr,
"Usage:\n\t%s [-i <interface to monitor>]\n"
"\tIf any interface is given all of them will be monitored\n", argv[0]);
return;
}
}
regexp = (regexp) ? : (char *)".*";
goto err;
return;
err_init:
err:
}
static void
{
}