From 0c2923956afe5659488ca1fc7d079e567e0d9fac Mon Sep 17 00:00:00 2001 From: Laurent MAZET Date: Wed, 19 Mar 2025 18:46:52 +0100 Subject: [PATCH] wip --- debug.c | 5 ----- makefile | 2 +- more.c => morep.c | 54 +++++++++++++++++++++++++++++++++-------------- 3 files changed, 39 insertions(+), 22 deletions(-) delete mode 100644 debug.c rename more.c => morep.c (91%) diff --git a/debug.c b/debug.c deleted file mode 100644 index b9eba44..0000000 --- a/debug.c +++ /dev/null @@ -1,5 +0,0 @@ -#include "debug.h" - -int verbose = 0; - -/* vim: set ts=4 sw=4 et: */ diff --git a/makefile b/makefile index 921318b..8b09d1d 100644 --- a/makefile +++ b/makefile @@ -1,4 +1,4 @@ -# Messaging over raw Ethernet +# Messaging over raw Ethernet Packets communication library MDIR = $(shell pwd) diff --git a/more.c b/morep.c similarity index 91% rename from more.c rename to morep.c index f3dc053..a8a8644 100644 --- a/more.c +++ b/morep.c @@ -1,5 +1,5 @@ /* - Messaging Over Raw Ethernet communication library + Messaging Over Raw Ethernet Packets communication library Copyrigth Thales 20250319 */ @@ -30,23 +30,23 @@ #include "debug.h" -#include "more.h" +#include "morep.h" /** - MORE address structure + MOREP address structure */ typedef struct { - enum { MORE_error, MORE_tx, MORE_rx } mode; + enum { MOREP_error, MOREP_tx, MOREP_rx } mode; char mac_address[17]; -} MORE_addr_t; + uint8_t mac[6]; +} MOREP_addr_t; -#define MAX_SAP_NUMBER 256 +#define MAX_MOREP_NUMBER 256 /** Type of private descriptor associated to each connected SAP. */ typedef struct { - uint8_t mac[6]; int sock; struct sockaddr_ll sock_addr; uint16_t short tx_seqnum; @@ -54,32 +54,54 @@ typedef struct { unsigned char tx_buffer[9014]; // jumbo frame (1514 standard frame) unsigned char rx_buffer[9014]; // jumbo frame (1514 standard frame) int is_blocking; -} MORE_descriptor_t ; +} MOREP_descriptor_t ; /** List of private descriptor associated to each connected MORE. */ -MORE_descriptor_t *MORE_list[MAX_MORE_NUMBER] = { 0 }; +MOREP_descriptor_t *MOREP_list[MAX_MOREP_NUMBER] = { 0 }; /** Init flag */ static int __init = 1; -void free_all_mores (void) +void free_all_moreps (void) { - VERBOSE (more, 2, FPRINTF (stdout, "free_all_mores\n")); + VERBOSE (morep, 2, FPRINTF (stdout, "free_all_moreps\n")); int i; - for (i = 0; i < MAX_SAP_NUMBER; i++) { - free (MORE_list[i]); - MORE_list[i] = NULL; + for (i = 0; i < MAX_MOREP_NUMBER; i++) { + free (MOREP_list[i]); + MOREP_list[i] = NULL; } } -static inline int parse_url (const char *ascii_url, SAP_addr_t *addr) +static int _parse_mac (const char *hexa_str, MOREP_addr_t *addr) { + /* MAC address format: XX:XX:XX:XX:XX:XX */ + if (strlen (hexa_str) != 17) { + return -1; + } + + int i; + for (int i = 0; i < 6; i++) { + char one_byte[3] = "xx"; + char ptr = NULL; + memcpy (one_byte, hexa + 3 * i, 2); + mac[i] = strtoul(one_byte, NULL, 16, &ptr); + if (ptr != NULL) { + return -1; + } + if (i < 5) { + if (hexa[3 * i + 2] != ':') { + return -1; + } + } + } + return 0; +} struct in_addr **addr_list; char url_to_parse[256] = { 0 }; @@ -90,7 +112,7 @@ static inline int parse_url (const char *ascii_url, SAP_addr_t *addr) addr->type = SAP_tcp; else return -1; - + char *hostname = strtok (url_to_parse + 6, ":"); char *port = strtok (NULL, ":"); if ((hostname == NULL) || (port == NULL)) { -- 2.30.2