Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/beacon.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void *beacon_loop(void *ptr)
}
chars_left = BEACON_LENGTH - n;

snprintf(buffer + (n * sizeof(char)), chars_left, "<Bus name=\"%s\"/>", interface_names[i]);
snprintf(buffer + (n * sizeof(char)), chars_left, "<Bus name=\"%s\"/>", bus_names[i]);
}

/* Find \0 in beacon buffer */
Expand Down
13 changes: 12 additions & 1 deletion src/socketcand.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ int receive_command(int socket, char *buf);
int sl, client_socket;
pthread_t beacon_thread, statistics_thread;
char **interface_names;
char **bus_names;
int interface_count = 0;
int port;
int verbose_flag = 0;
Expand Down Expand Up @@ -300,6 +301,16 @@ int main(int argc, char **argv)
interface_names[i] = strtok(NULL, ",");
}

/* check if any of the intefaces requires a different bus name */
bus_names = malloc(sizeof(char *) * interface_count);
for (i = 0; i < interface_count; i++) {
strtok(interface_names[i], "="); /* split at the = if it's there */
bus_names[i] = strtok(NULL, "=");
if (bus_names[i] == NULL) {
bus_names[i] = interface_names[i];
}
}

/* if daemon mode was activated the syslog must be opened */
if (daemon_flag) {
openlog("socketcand", 0, LOG_DAEMON);
Expand Down Expand Up @@ -645,7 +656,7 @@ void print_usage(void)
printf("Usage: socketcand [-v | --verbose] [-i interfaces | --interfaces interfaces]\n\t\t[-p port | --port port] [-q | --quick-ack]\n\t\t[-l interface | --listen interface] [-u name | --afuxname name]\n\t\t[-n | --no-beacon] [-d | --daemon] [-h | --help]\n\n");
printf("Options:\n");
printf("\t-v (activates verbose output to STDOUT)\n");
printf("\t-i <interfaces> (comma separated list of SocketCAN interfaces the daemon\n\t\tshall provide access to e.g. '-i can0,vcan1' - default: %s)\n", DEFAULT_BUSNAME);
printf("\t-i <interfaces>[=<bus>] (comma separated list of SocketCAN interfaces the daemon\n\t\tshall provide access to e.g. '-i can0,vcan1'\n\t\tmight include an optional bus name,\n\t\tif different from interface e.g. '-i vcan0=mybus' - default: %s)\n", DEFAULT_BUSNAME);
printf("\t-p <port> (changes the default port '%d' the daemon is listening at)\n", PORT);
printf("\t-q (enable TCP_QUICKACK socket option)\n");
printf("\t-l <interface> (changes the default network interface the daemon will\n\t\tbind to - default: %s)\n", DEFAULT_INTERFACE);
Expand Down
3 changes: 2 additions & 1 deletion src/socketcand.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ void state_nobus();

extern int client_socket;
extern char **interface_names;
extern char **bus_names;
extern int interface_count;
extern int port;
extern int verbose_flag;
Expand All @@ -74,4 +75,4 @@ int receive_command(int socket, char *buf);
int state_changed(char *buf, int current_state);
char *element_start(char *buf, int element);
int element_length(char *buf, int element);
int asc2nibble(char c);
int asc2nibble(char c);
6 changes: 4 additions & 2 deletions src/state_nobus.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
#include <string.h>
#include <sys/socket.h>

static int check_bus(const char *bus_name)
static int check_bus(char *bus_name)
{
int found = 0, i;

for (i = 0; i < interface_count; i++) {
if (!strcmp(interface_names[i], bus_name))
if (!strcmp(bus_names[i], bus_name)) {
strcpy(bus_name, interface_names[i]);
found = 1;
}
}
return found;
}
Expand Down