From 9a9f85b180b87126e11ce8a937fce1a8ea818dc3 Mon Sep 17 00:00:00 2001 From: DcruBro Date: Tue, 20 Oct 2026 15:53:50 +0200 Subject: [PATCH] add endpoint type --- src/proto/conn.c | 3 +++ src/proto/conn.h | 3 +++ src/proto/endpoint.c | 10 ++++++++++ src/proto/endpoint.h | 21 +++++++++++++++++++++ 4 files changed, 37 insertions(+) create mode 100644 src/proto/endpoint.c create mode 100644 src/proto/endpoint.h diff --git a/src/proto/conn.c b/src/proto/conn.c index b500127..1d6a8b0 100644 --- a/src/proto/conn.c +++ b/src/proto/conn.c @@ -41,6 +41,9 @@ bravais_result_t bravais_conn_create(const bravais_config_t* config, bravais_con newConn->config = *config; newConn->state = BRAVAIS_CONN_STATE_IDLE; + // calloc() already zeroes + //memset(&newConn->remoteEndpoint, 0, sizeof(newConn->remoteEndpoint)); + //memset(&newConn->localEndpoint, 0, sizeof(newConn->localEndpoint)); conn_log(newConn, BRAVAIS_LOG_LEVEL_DEBUG, "Connection created"); *outConn = newConn; diff --git a/src/proto/conn.h b/src/proto/conn.h index 46d076f..8b1eda6 100644 --- a/src/proto/conn.h +++ b/src/proto/conn.h @@ -7,6 +7,7 @@ #define BRAVAIS_CONN_H #include "bravais.h" +#include "proto/endpoint.h" typedef enum { BRAVAIS_CONN_STATE_IDLE, @@ -18,6 +19,8 @@ typedef enum { struct bravais_conn { bravais_config_t config; bravais_conn_state_t state; + bravais_endpoint_t remoteEndpoint; + bravais_endpoint_t localEndpoint; // This is here since the local endpoint, if we're initiating a connection, may not have a standard port number. }; #endif // BRAVAIS_CONN_H diff --git a/src/proto/endpoint.c b/src/proto/endpoint.c new file mode 100644 index 0000000..66fe629 --- /dev/null +++ b/src/proto/endpoint.c @@ -0,0 +1,10 @@ +// endpoint.c +// Endpoint internals for the lib + +#include "proto/endpoint.h" + +bool bravais_endpoint_is_ipv4(const bravais_endpoint_t* endpoint) { + if (!endpoint) { return false; } + + return memcmp(endpoint->address, bravaisEndpointMappedIPv4Prefix, sizeof(bravaisEndpointMappedIPv4Prefix)) == 0; +} \ No newline at end of file diff --git a/src/proto/endpoint.h b/src/proto/endpoint.h new file mode 100644 index 0000000..267c609 --- /dev/null +++ b/src/proto/endpoint.h @@ -0,0 +1,21 @@ +// endpoint.h +// Endpoint internals for the lib + +#ifndef BRAVAIS_ENDPOINT_H +#define BRAVAIS_ENDPOINT_H + +#include +#include +#include +#include + +static const uint8_t bravaisEndpointMappedIPv4Prefix[12] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff }; + +typedef struct bravais_endpoint { + uint8_t address[16]; // IPv6 address (or IPv4-mapped IPv6) - network byte order + uint16_t port; // Port number - host byte order +} bravais_endpoint_t; + +bool bravais_endpoint_is_ipv4(const bravais_endpoint_t* endpoint); + +#endif // BRAVAIS_ENDPOINT_H