Go for a multicall binary I guess
This commit is contained in:
parent
17a8d869ca
commit
76b11b80b6
13 changed files with 166 additions and 13 deletions
3
Makefile
3
Makefile
|
@ -1,11 +1,14 @@
|
|||
all:
|
||||
$(MAKE) -C src all
|
||||
$(MAKE) -C bin all
|
||||
$(MAKE) -C examples all
|
||||
|
||||
install:
|
||||
$(MAKE) -C src install
|
||||
$(MAKE) -C bin install
|
||||
$(MAKE) -C examples install
|
||||
|
||||
clean:
|
||||
$(MAKE) -C src clean
|
||||
$(MAKE) -C bin clean
|
||||
$(MAKE) -C examples clean
|
||||
|
|
28
bin/Makefile
Normal file
28
bin/Makefile
Normal file
|
@ -0,0 +1,28 @@
|
|||
include ../mk/build.mk
|
||||
|
||||
CC = $(CROSS)cc
|
||||
|
||||
INCLUDE_PATH = ../include
|
||||
|
||||
CFLAGS += -I$(INCLUDE_PATH)
|
||||
LDFLAGS = -L../src -lhexagram
|
||||
STATIC = ../src/libhexagram.a
|
||||
OBJS = capture.o convert.o replay.o replaypcap.o main.o
|
||||
NAME = hexagram
|
||||
|
||||
RM = /bin/rm
|
||||
|
||||
all: $(NAME)
|
||||
|
||||
install: $(NAME)
|
||||
$(INSTALL) -d 0755 $(PREFIX)/bin
|
||||
$(INSTALL) -c -m 0755 $(NAME) $(PREFIX)/bin
|
||||
|
||||
$(OBJS): %.o: %.c
|
||||
$(CC) $(CFLAGS) -c $<
|
||||
|
||||
$(NAME): $(OBJS) $(STATIC)
|
||||
$(CC) $(CFLAGS) -o $(NAME) $(OBJS) $(STATIC)
|
||||
|
||||
clean:
|
||||
$(RM) -f $(NAME) $(OBJS)
|
10
bin/app.h
Normal file
10
bin/app.h
Normal file
|
@ -0,0 +1,10 @@
|
|||
#ifndef _APP_H
|
||||
#define _APP_H
|
||||
|
||||
typedef struct {
|
||||
const char *name;
|
||||
const char *arglist;
|
||||
int (*main)(int argc, char **argv);
|
||||
} hexagram_app;
|
||||
|
||||
#endif /* _APP_H *?
|
|
@ -8,7 +8,13 @@
|
|||
#include <hexagram/can.h>
|
||||
#include <hexagram/capture.h>
|
||||
|
||||
static void usage(int argc, char **argv, const char *message, ...) {
|
||||
#include "capture.h"
|
||||
|
||||
char *hexagram_arglist_capture(void) {
|
||||
return "canif [file.can]";
|
||||
}
|
||||
|
||||
static int usage(int argc, char **argv, const char *message, ...) {
|
||||
if (message) {
|
||||
va_list args;
|
||||
|
||||
|
@ -17,14 +23,12 @@ static void usage(int argc, char **argv, const char *message, ...) {
|
|||
va_end(args);
|
||||
}
|
||||
|
||||
fprintf(stderr, "usage: %s canif [file.can]\n", argv[0]);
|
||||
fprintf(stderr, "usage: hexagram %s %s\n", argv[0], hexagram_arglist_capture());
|
||||
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int hexagram_main_capture(int argc, char **argv) {
|
||||
hexagram_can_if *can_if;
|
||||
hexagram_capture *capture;
|
||||
|
8
bin/capture.h
Normal file
8
bin/capture.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
#ifndef _CAPTURE_H
|
||||
#define _CAPTURE_H
|
||||
|
||||
char *hexagram_arglist_capture(void);
|
||||
|
||||
int hexagram_main_capture(int argc, char **argv);
|
||||
|
||||
#endif /* _CAPTURE_H */
|
|
@ -5,11 +5,15 @@
|
|||
#include <inttypes.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/endian.h>
|
||||
#include <endian.h>
|
||||
|
||||
#include <hexagram/capture.h>
|
||||
#include <hexagram/pcapng.h>
|
||||
|
||||
char *hexagram_arglist_convert(void) {
|
||||
return "[infile] [outfile]";
|
||||
}
|
||||
|
||||
static ssize_t handle_option(hexagram_pcapng_stream *stream,
|
||||
uint32_t type,
|
||||
uint16_t code,
|
||||
|
@ -182,7 +186,7 @@ error_io:
|
|||
return -1;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int hexagram_main_convert(int argc, char **argv) {
|
||||
int fd;
|
||||
|
||||
hexagram_pcapng_stream *stream;
|
8
bin/convert.h
Normal file
8
bin/convert.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
#ifndef _CONVERT_H
|
||||
#define _CONVERT_H
|
||||
|
||||
char *hexagram_arglist_convert(void);
|
||||
|
||||
int hexagram_main_convert(int argc, char **argv);
|
||||
|
||||
#endif /* _CONVERT_H */
|
59
bin/main.c
Normal file
59
bin/main.c
Normal file
|
@ -0,0 +1,59 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "capture.h"
|
||||
#include "convert.h"
|
||||
#include "replay.h"
|
||||
#include "replaypcap.h"
|
||||
|
||||
typedef struct {
|
||||
const char *name;
|
||||
char *(*arglist)(void);
|
||||
int (*main)(int argc, char **argv);
|
||||
} hexagram_app;
|
||||
|
||||
hexagram_app apps[] = {
|
||||
{ "capture", hexagram_arglist_capture, hexagram_main_capture },
|
||||
{ "convert", hexagram_arglist_convert, hexagram_main_convert },
|
||||
{ "replay", hexagram_arglist_replay, hexagram_main_replay },
|
||||
{ "replaypcap", hexagram_arglist_replaypcap, hexagram_main_replaypcap },
|
||||
{ NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
static int usage(int argc, char **argv, const char *message, ...) {
|
||||
hexagram_app *app;
|
||||
|
||||
if (message) {
|
||||
va_list args;
|
||||
|
||||
va_start(args, message);
|
||||
vfprintf(stderr, message, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
fprintf(stderr, "usage: %s [command args ...]\n", argv[0]);
|
||||
|
||||
for (app = apps; app->name != NULL; app++) {
|
||||
fprintf(stderr, " %s %s %s\n", argv[0], app->name, app->arglist());
|
||||
}
|
||||
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
hexagram_app *app;
|
||||
|
||||
if (argc < 2) {
|
||||
return usage(argc, argv, "No command provided\n");
|
||||
}
|
||||
|
||||
for (app = apps; app->name != NULL; app++) {
|
||||
if (strcmp(argv[1], app->name) == 0) {
|
||||
return app->main(--argc, ++argv);
|
||||
}
|
||||
}
|
||||
|
||||
return usage(argc, argv, NULL);
|
||||
}
|
|
@ -8,6 +8,12 @@
|
|||
#include <hexagram/can.h>
|
||||
#include <hexagram/capture.h>
|
||||
|
||||
#include "replay.h"
|
||||
|
||||
char *hexagram_arglist_replay(void) {
|
||||
return "canif [file.can]";
|
||||
}
|
||||
|
||||
static void usage(int argc, char **argv, const char *message, ...) {
|
||||
if (message) {
|
||||
va_list args;
|
||||
|
@ -17,12 +23,12 @@ static void usage(int argc, char **argv, const char *message, ...) {
|
|||
va_end(args);
|
||||
}
|
||||
|
||||
fprintf(stderr, "usage: %s canif [file.can]\n", argv[0]);
|
||||
fprintf(stderr, "usage: hexagram %s %s\n", argv[0], hexagram_arglist_replay());
|
||||
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int hexagram_main_replay(int argc, char **argv) {
|
||||
hexagram_can_if *can_if;
|
||||
hexagram_capture *capture;
|
||||
|
8
bin/replay.h
Normal file
8
bin/replay.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
#ifndef _REPLAY_H
|
||||
#define _REPLAY_H
|
||||
|
||||
char *hexagram_arglist_replay(void);
|
||||
|
||||
int hexagram_main_replay(int argc, char **argv);
|
||||
|
||||
#endif /* _REPLAY_H */
|
|
@ -5,8 +5,8 @@
|
|||
#include <inttypes.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <endian.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/endian.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
|
@ -16,11 +16,17 @@
|
|||
|
||||
#include <hexagram/pcapng.h>
|
||||
|
||||
#include "replaypcap.h"
|
||||
|
||||
struct pcapinfo {
|
||||
int sock;
|
||||
useconds_t last_time;
|
||||
};
|
||||
|
||||
char *hexagram_arglist_replaypcap(void) {
|
||||
return "canif [file.pcapng]";
|
||||
}
|
||||
|
||||
static void usage(int argc, char **argv, const char *message, ...) {
|
||||
if (message) {
|
||||
va_list args;
|
||||
|
@ -30,7 +36,8 @@ static void usage(int argc, char **argv, const char *message, ...) {
|
|||
va_end(args);
|
||||
}
|
||||
|
||||
fprintf(stderr, "usage: %s canif [file.pcapng]\n", argv[0]);
|
||||
fprintf(stderr, "usage: hexagram %s %s\n",
|
||||
argv[0], hexagram_arglist_replaypcap());
|
||||
|
||||
exit(1);
|
||||
}
|
||||
|
@ -220,7 +227,7 @@ error_io:
|
|||
return -1;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int hexagram_main_replaypcap(int argc, char **argv) {
|
||||
int fd;
|
||||
|
||||
struct sockaddr_can addr;
|
8
bin/replaypcap.h
Normal file
8
bin/replaypcap.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
#ifndef _REPLAYPCAP_H
|
||||
#define _REPLAYPCAP_H
|
||||
|
||||
char *hexagram_arglist_replaypcap(void);
|
||||
|
||||
int hexagram_main_replaypcap(int argc, char **argv);
|
||||
|
||||
#endif /* _REPLAYPCAP_H */
|
|
@ -8,7 +8,7 @@ CFLAGS += -I$(INCLUDE_PATH)
|
|||
LDFLAGS = -L../src -lhexagram
|
||||
STATIC = ../src/libhexagram.a
|
||||
|
||||
EXAMPLES = capture convert duration pcapread replay view
|
||||
EXAMPLES = duration view
|
||||
|
||||
RM = /bin/rm
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue