fbd3c71ba7
Splits the platform-agnostic network core out of dusk into a top-level dusknetwork module, mirroring the duskgl/dusksdl2 pattern. Adds a DUSK_NETWORK cmake option (default ON) so builds can exclude all networking code, including the per-platform implementations. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
51 lines
1.2 KiB
C
51 lines
1.2 KiB
C
/**
|
|
* Copyright (c) 2026 Dominic Masters
|
|
*
|
|
* This software is released under the MIT License.
|
|
* https://opensource.org/licenses/MIT
|
|
*/
|
|
|
|
#pragma once
|
|
#include "dusk.h"
|
|
|
|
#define NETWORK_INFO_IPV4_DNS_COUNT_MAX 2
|
|
#define NETWORK_INFO_IPV4_OCTET_COUNT 4
|
|
#define NETWORK_INFO_IPV6_OCTET_COUNT 16
|
|
#define NETWORK_INFO_IPV6_DNS_COUNT_MAX 2
|
|
#define NETWORK_INFO_FORMAT_IPV4 "%u.%u.%u.%u"
|
|
#define NETWORK_INFO_FORMAT_IPV6 \
|
|
"%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x"
|
|
|
|
typedef enum {
|
|
NETWORK_TYPE_IPV4,
|
|
#ifdef DUSK_NETWORK_IPV6
|
|
NETWORK_TYPE_IPV6,
|
|
#endif
|
|
} networktype_t;
|
|
|
|
typedef struct {
|
|
uint8_t ip[NETWORK_INFO_IPV4_OCTET_COUNT];
|
|
} networkinfoipv4_t;
|
|
|
|
#ifdef DUSK_NETWORK_IPV6
|
|
typedef struct {
|
|
uint8_t ip[NETWORK_INFO_IPV6_OCTET_COUNT];
|
|
} networkinfoipv6_t;
|
|
#endif
|
|
|
|
typedef struct {
|
|
networktype_t type;
|
|
union {
|
|
networkinfoipv4_t ipv4;
|
|
#ifdef DUSK_NETWORK_IPV6
|
|
networkinfoipv6_t ipv6;
|
|
#endif
|
|
};
|
|
} networkinfo_t;
|
|
|
|
/**
|
|
* Returns the network information for the currently active network connection.
|
|
*
|
|
* @return Network information for the currently active network connection.
|
|
*/
|
|
networkinfo_t networkGetInfo(); |