Real nice when your brain chooches well

This commit is contained in:
XANTRONIX Development 2019-05-22 22:02:58 -05:00
parent ab61c674a0
commit 73f8bec336
11 changed files with 53 additions and 49 deletions

View file

@ -7,7 +7,7 @@ INCLUDE_PATH = ../include
CFLAGS += -I$(INCLUDE_PATH) CFLAGS += -I$(INCLUDE_PATH)
LDFLAGS = -L../src -lhexagram LDFLAGS = -L../src -lhexagram
STATIC = ../src/libhexagram.a STATIC = ../src/libhexagram.a
OBJS = capture.o convert.o replay.o replaypcap.o main.o OBJS = capture.o pcap2can.o replay.o pcapreplay.o main.o
NAME = hexagram NAME = hexagram
RM = /bin/rm RM = /bin/rm

View file

@ -1,8 +0,0 @@
#ifndef _CONVERT_H
#define _CONVERT_H
char *hexagram_arglist_convert(void);
int hexagram_main_convert(int argc, char **argv);
#endif /* _CONVERT_H */

View file

@ -4,9 +4,9 @@
#include <stdarg.h> #include <stdarg.h>
#include "capture.h" #include "capture.h"
#include "convert.h"
#include "replay.h" #include "replay.h"
#include "replaypcap.h" #include "pcap2can.h"
#include "pcapreplay.h"
typedef struct { typedef struct {
const char *name; const char *name;
@ -16,9 +16,9 @@ typedef struct {
hexagram_app apps[] = { hexagram_app apps[] = {
{ "capture", hexagram_arglist_capture, hexagram_main_capture }, { "capture", hexagram_arglist_capture, hexagram_main_capture },
{ "convert", hexagram_arglist_convert, hexagram_main_convert },
{ "replay", hexagram_arglist_replay, hexagram_main_replay }, { "replay", hexagram_arglist_replay, hexagram_main_replay },
{ "replaypcap", hexagram_arglist_replaypcap, hexagram_main_replaypcap }, { "pcap2can", hexagram_arglist_pcap2can, hexagram_main_pcap2can },
{ "pcapreplay", hexagram_arglist_pcapreplay, hexagram_main_pcapreplay },
{ NULL, NULL, NULL } { NULL, NULL, NULL }
}; };

View file

@ -10,7 +10,7 @@
#include <hexagram/capture.h> #include <hexagram/capture.h>
#include <hexagram/pcapng.h> #include <hexagram/pcapng.h>
char *hexagram_arglist_convert(void) { char *hexagram_arglist_pcap2can(void) {
return "[infile.pcapng] [outfile.can]"; return "[infile.pcapng] [outfile.can]";
} }
@ -190,7 +190,7 @@ error_io:
return -1; return -1;
} }
int hexagram_main_convert(int argc, char **argv) { int hexagram_main_pcap2can(int argc, char **argv) {
int fd; int fd;
hexagram_pcapng_stream *stream; hexagram_pcapng_stream *stream;

8
bin/pcap2can.h Normal file
View file

@ -0,0 +1,8 @@
#ifndef _CONVERT_H
#define _CONVERT_H
char *hexagram_arglist_pcap2can(void);
int hexagram_main_pcap2can(int argc, char **argv);
#endif /* _CONVERT_H */

View file

@ -16,14 +16,14 @@
#include <hexagram/pcapng.h> #include <hexagram/pcapng.h>
#include "replaypcap.h" #include "pcapreplay.h"
struct pcapinfo { struct pcapinfo {
int sock; int sock;
useconds_t last_time; useconds_t last_time;
}; };
char *hexagram_arglist_replaypcap(void) { char *hexagram_arglist_pcapreplay(void) {
return "canif [file.pcapng]"; return "canif [file.pcapng]";
} }
@ -37,7 +37,7 @@ static void usage(int argc, char **argv, const char *message, ...) {
} }
fprintf(stderr, "usage: hexagram %s %s\n", fprintf(stderr, "usage: hexagram %s %s\n",
argv[0], hexagram_arglist_replaypcap()); argv[0], hexagram_arglist_pcapreplay());
exit(1); exit(1);
} }
@ -161,11 +161,6 @@ static ssize_t handle_block_packet(hexagram_pcapng_stream *stream,
frame.can_id = be32toh(frame.can_id); frame.can_id = be32toh(frame.can_id);
printf("Read packet %"PRIu32" bytes time hi %"PRIu32" lo %"PRIu32" id %8"PRIx32" payload %d\n",
header.caplen, header.timestamp[0], header.timestamp[1],
frame.can_id,
frame.can_dlc);
if (write(data->sock, &frame, sizeof(struct can_frame)) < 0) { if (write(data->sock, &frame, sizeof(struct can_frame)) < 0) {
goto error_io; goto error_io;
} }
@ -232,7 +227,7 @@ error_io:
return -1; return -1;
} }
int hexagram_main_replaypcap(int argc, char **argv) { int hexagram_main_pcapreplay(int argc, char **argv) {
int fd; int fd;
struct sockaddr_can addr; struct sockaddr_can addr;

8
bin/pcapreplay.h Normal file
View file

@ -0,0 +1,8 @@
#ifndef _REPLAYPCAP_H
#define _REPLAYPCAP_H
char *hexagram_arglist_pcapreplay(void);
int hexagram_main_pcapreplay(int argc, char **argv);
#endif /* _REPLAYPCAP_H */

View file

@ -1,8 +0,0 @@
#ifndef _REPLAYPCAP_H
#define _REPLAYPCAP_H
char *hexagram_arglist_replaypcap(void);
int hexagram_main_replaypcap(int argc, char **argv);
#endif /* _REPLAYPCAP_H */

View file

@ -14,6 +14,8 @@ int hexagram_module_close(hexagram_module *module);
const char *hexagram_module_name(hexagram_module *module); const char *hexagram_module_name(hexagram_module *module);
int hexagram_module_win(hexagram_module *module);
int hexagram_module_run(hexagram_module *module, int hexagram_module_run(hexagram_module *module,
hexagram_dict *buses); hexagram_dict *buses);

View file

@ -11,6 +11,7 @@ struct _hexagram_module {
const char *soname; const char *soname;
void *handle; void *handle;
char *(*name)(); char *(*name)();
int (*win)();
int (*run)(hexagram_dict *buses); int (*run)(hexagram_dict *buses);
pid_t pid; pid_t pid;
}; };
@ -57,6 +58,14 @@ const char *hexagram_module_name(hexagram_module *module) {
return module->name(); return module->name();
} }
int hexagram_module_win(hexagram_module *module) {
if (module->win == NULL) {
return -1;
}
return module->win();
}
int hexagram_module_run(hexagram_module *module, int hexagram_module_run(hexagram_module *module,
hexagram_dict *buses) { hexagram_dict *buses) {
if (module->run == NULL) { if (module->run == NULL) {

View file

@ -4,7 +4,7 @@
#include <hexagram/sim.h> #include <hexagram/sim.h>
struct _hexagram_sim { struct _hexagram_sim {
hexagram_dict *can_ifs; hexagram_dict *buses;
hexagram_dict *modules; hexagram_dict *modules;
}; };
@ -15,8 +15,8 @@ hexagram_sim *hexagram_sim_new() {
goto error_malloc; goto error_malloc;
} }
if ((sim->can_ifs = hexagram_dict_new()) == NULL) { if ((sim->buses = hexagram_dict_new()) == NULL) {
goto error_dict_new_can_ifs; goto error_dict_new_buses;
} }
if ((sim->modules = hexagram_dict_new()) == NULL) { if ((sim->modules = hexagram_dict_new()) == NULL) {
@ -26,9 +26,9 @@ hexagram_sim *hexagram_sim_new() {
return sim; return sim;
error_dict_new_modules: error_dict_new_modules:
hexagram_dict_destroy(sim->can_ifs); hexagram_dict_destroy(sim->buses);
error_dict_new_can_ifs: error_dict_new_buses:
free(sim); free(sim);
error_malloc: error_malloc:
@ -37,22 +37,21 @@ error_malloc:
void hexagram_sim_destroy(hexagram_sim *sim) { void hexagram_sim_destroy(hexagram_sim *sim) {
hexagram_dict_destroy(sim->modules); hexagram_dict_destroy(sim->modules);
hexagram_dict_destroy(sim->can_ifs); hexagram_dict_destroy(sim->buses);
free(sim); free(sim);
} }
int hexagram_sim_add_can_if(hexagram_sim *sim, int hexagram_sim_add_bus(hexagram_sim *sim,
const char *name, const char *name,
hexagram_can_if *can_if) { hexagram_can_if *bus) {
if (hexagram_dict_set(sim->can_ifs, if (hexagram_dict_set_s(sim->buses, name, bus) == NULL) {
(void *)name, strlen(name), can_if) == NULL) { goto error_dict_set_s;
goto error_dict_set;
} }
return 0; return 0;
error_dict_set: error_dict_set_s:
return -1; return -1;
} }
@ -64,14 +63,13 @@ int hexagram_sim_add_module(hexagram_sim *sim,
goto error_module_name; goto error_module_name;
} }
if (hexagram_dict_set(sim->modules, if (hexagram_dict_set_s(sim->modules, name, module) == NULL) {
(void *)name, strlen(name), module) == NULL) { goto error_dict_set_s;
goto error_dict_set;
} }
return 0; return 0;
error_dict_set: error_dict_set_s:
error_module_name: error_module_name:
return -1; return -1;
} }