From 0eb84dcca830dcee950a12a48f63062d950d03d0 Mon Sep 17 00:00:00 2001 From: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com> Date: Sat, 4 Apr 2026 22:35:42 -0400 Subject: [PATCH] Add NXDK (Xbox) support --- include/enet/enet.h | 2 +- unix.c | 34 ++++++++++++++++++++++++++++++++-- win32.c | 26 +++++++++++++------------- 3 files changed, 46 insertions(+), 16 deletions(-) diff --git a/include/enet/enet.h b/include/enet/enet.h index 985b883..1be3c47 100644 --- a/include/enet/enet.h +++ b/include/enet/enet.h @@ -12,7 +12,7 @@ extern "C" #include -#ifdef _WIN32 +#if defined(_WIN32) && !defined(NXDK) #include "enet/win32.h" #else #include "enet/unix.h" diff --git a/unix.c b/unix.c index 251e144..32c6f14 100644 --- a/unix.c +++ b/unix.c @@ -2,7 +2,7 @@ @file unix.c @brief ENet Unix system specific functions */ -#ifndef _WIN32 +#if !defined(_WIN32) || defined(NXDK) // Required for IPV6_PKTINFO with Darwin headers #ifndef __APPLE_USE_RFC_3542 @@ -104,6 +104,34 @@ #ifndef NO_MSGAPI #define NO_MSGAPI 1 #endif +#elif defined(NXDK) +#ifndef HAS_POLL +#define HAS_POLL 1 +#endif +#ifndef HAS_FCNTL +#define HAS_FCNTL 1 +#endif +#ifndef HAS_IOCTL +#define HAS_IOCTL 1 +#endif +#ifndef HAS_INET_PTON +#define HAS_INET_PTON 1 +#endif +#ifndef HAS_INET_NTOP +#define HAS_INET_NTOP 1 +#endif +#ifndef HAS_SOCKLEN_T +#define HAS_SOCKLEN_T 1 +#endif +#ifndef HAS_GETADDRINFO +#define HAS_GETADDRINFO 1 +#endif +#ifndef HAS_GETNAMEINFO +#define HAS_GETNAMEINFO 1 +#endif +#ifndef NO_MSGAPI +#define NO_MSGAPI 1 +#endif #elif defined(__3DS__) #ifdef AF_INET6 #undef AF_INET6 @@ -438,7 +466,7 @@ enet_socket_set_option (ENetSocket socket, ENetSocketOption option, int value) { case ENET_SOCKOPT_NONBLOCK: #ifdef HAS_FCNTL - result = fcntl (socket, F_SETFL, (value ? O_NONBLOCK : 0) | (fcntl (socket, F_GETFL) & ~O_NONBLOCK)); + result = fcntl (socket, F_SETFL, (value ? O_NONBLOCK : 0) | (fcntl (socket, F_GETFL, 0) & ~O_NONBLOCK)); #else #ifdef HAS_IOCTL result = ioctl (socket, FIONBIO, & value); @@ -715,7 +743,9 @@ enet_socket_send (ENetSocket socket, case EADDRNOTAVAIL: case ENETDOWN: case ENETUNREACH: +#if !defined(EHOSTDOWN) || (EHOSTDOWN != EHOSTUNREACH) case EHOSTDOWN: +#endif case EHOSTUNREACH: return 0; diff --git a/win32.c b/win32.c index 4f37819..f54e0c6 100644 --- a/win32.c +++ b/win32.c @@ -1,8 +1,8 @@ -/** +/** @file win32.c @brief ENet Win32 system specific functions */ -#ifdef _WIN32 +#if defined(_WIN32) && !defined(NXDK) #define ENET_BUILDING_LIB 1 #include "enet/enet.h" @@ -51,7 +51,7 @@ enet_initialize (void) { WORD versionRequested = MAKEWORD (2, 0); WSADATA wsaData; - + if (WSAStartup (versionRequested, & wsaData)) return -1; @@ -59,7 +59,7 @@ enet_initialize (void) HIBYTE (wsaData.wVersion) != 0) { WSACleanup (); - + return -1; } @@ -228,9 +228,9 @@ enet_address_set_host (ENetAddress * address, const char * name) { memcpy (& address -> address, result -> ai_addr, result -> ai_addrlen); address -> addressLength = result -> ai_addrlen; - + freeaddrinfo (resultList); - + return 0; } @@ -429,10 +429,10 @@ enet_socket_accept (ENetSocket socket, ENetAddress * address) if (address != NULL) address -> addressLength = sizeof (address -> address); - result = accept (socket, - address != NULL ? (struct sockaddr *) & address -> address : NULL, + result = accept (socket, + address != NULL ? (struct sockaddr *) & address -> address : NULL, address != NULL ? & address -> addressLength : NULL); - + if (result == -1) return ENET_SOCKET_NULL; @@ -697,10 +697,10 @@ enet_socket_wait (ENetSocket socket, enet_uint32 * condition, enet_uint32 timeou fd_set readSet, writeSet; struct timeval timeVal; int selectCount; - + timeVal.tv_sec = timeout / 1000; timeVal.tv_usec = (timeout % 1000) * 1000; - + FD_ZERO (& readSet); FD_ZERO (& writeSet); @@ -722,12 +722,12 @@ enet_socket_wait (ENetSocket socket, enet_uint32 * condition, enet_uint32 timeou if (FD_ISSET (socket, & writeSet)) * condition |= ENET_SOCKET_WAIT_SEND; - + if (FD_ISSET (socket, & readSet)) * condition |= ENET_SOCKET_WAIT_RECEIVE; return 0; -} +} #endif