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)
LDFLAGS = -L../src -lhexagram
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
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 "capture.h"
#include "convert.h"
#include "replay.h"
#include "replaypcap.h"
#include "pcap2can.h"
#include "pcapreplay.h"
typedef struct {
const char *name;
@ -16,9 +16,9 @@ typedef struct {
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 },
{ "pcap2can", hexagram_arglist_pcap2can, hexagram_main_pcap2can },
{ "pcapreplay", hexagram_arglist_pcapreplay, hexagram_main_pcapreplay },
{ NULL, NULL, NULL }
};

View file

@ -10,7 +10,7 @@
#include <hexagram/capture.h>
#include <hexagram/pcapng.h>
char *hexagram_arglist_convert(void) {
char *hexagram_arglist_pcap2can(void) {
return "[infile.pcapng] [outfile.can]";
}
@ -190,7 +190,7 @@ error_io:
return -1;
}
int hexagram_main_convert(int argc, char **argv) {
int hexagram_main_pcap2can(int argc, char **argv) {
int fd;
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 "replaypcap.h"
#include "pcapreplay.h"
struct pcapinfo {
int sock;
useconds_t last_time;
};
char *hexagram_arglist_replaypcap(void) {
char *hexagram_arglist_pcapreplay(void) {
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",
argv[0], hexagram_arglist_replaypcap());
argv[0], hexagram_arglist_pcapreplay());
exit(1);
}
@ -161,11 +161,6 @@ static ssize_t handle_block_packet(hexagram_pcapng_stream *stream,
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) {
goto error_io;
}
@ -232,7 +227,7 @@ error_io:
return -1;
}
int hexagram_main_replaypcap(int argc, char **argv) {
int hexagram_main_pcapreplay(int argc, char **argv) {
int fd;
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);
int hexagram_module_win(hexagram_module *module);
int hexagram_module_run(hexagram_module *module,
hexagram_dict *buses);

View file

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

View file

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