add endpoint type
This commit is contained in:
@@ -41,6 +41,9 @@ bravais_result_t bravais_conn_create(const bravais_config_t* config, bravais_con
|
|||||||
|
|
||||||
newConn->config = *config;
|
newConn->config = *config;
|
||||||
newConn->state = BRAVAIS_CONN_STATE_IDLE;
|
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");
|
conn_log(newConn, BRAVAIS_LOG_LEVEL_DEBUG, "Connection created");
|
||||||
*outConn = newConn;
|
*outConn = newConn;
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#define BRAVAIS_CONN_H
|
#define BRAVAIS_CONN_H
|
||||||
|
|
||||||
#include "bravais.h"
|
#include "bravais.h"
|
||||||
|
#include "proto/endpoint.h"
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
BRAVAIS_CONN_STATE_IDLE,
|
BRAVAIS_CONN_STATE_IDLE,
|
||||||
@@ -18,6 +19,8 @@ typedef enum {
|
|||||||
struct bravais_conn {
|
struct bravais_conn {
|
||||||
bravais_config_t config;
|
bravais_config_t config;
|
||||||
bravais_conn_state_t state;
|
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
|
#endif // BRAVAIS_CONN_H
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
@@ -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
|
||||||
Reference in New Issue
Block a user