add endpoint type

This commit is contained in:
2026-10-20 15:53:50 +02:00
parent b1a3baf147
commit 9a9f85b180
4 changed files with 37 additions and 0 deletions
+3
View File
@@ -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;
+3
View File
@@ -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
+10
View File
@@ -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;
}
+21
View File
@@ -0,0 +1,21 @@
// endpoint.h
// Endpoint internals for the lib
#ifndef BRAVAIS_ENDPOINT_H
#define BRAVAIS_ENDPOINT_H
#include <stdint.h>
#include <stddef.h>
#include <string.h>
#include <stdlib.h>
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