mirror of
https://github.com/CalcProgrammer1/OpenRGB.git
synced 2026-09-16 07:07:12 -04:00
SDK6 PROTOCOL CHANGE: Add client and server hostname set packets
This commit is contained in:
1 parent
bfaef77719
commit
2e09228568
8 files changed
+214
-11
No files matched your search
@@ -10,6 +10,16 @@
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#include <winsock2.h>
|
||||
#pragma comment(lib, "ws2_32.lib")
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#include <climits>
|
||||
#endif
|
||||
|
||||
#include "NetworkProtocol.h"
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
@@ -17,6 +27,46 @@
|
||||
\*-----------------------------------------------------*/
|
||||
const char openrgb_sdk_magic[OPENRGB_SDK_MAGIC_SIZE] = { 'O', 'R', 'G', 'B' };
|
||||
|
||||
std::string GetHostname()
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| Determine maximum hostname limit or fallback to |
|
||||
| defensive size |
|
||||
\*-----------------------------------------------------*/
|
||||
#if defined(HOST_NAME_MAX)
|
||||
const size_t buffer_size = HOST_NAME_MAX + 1;
|
||||
#else
|
||||
const size_t buffer_size = 256;
|
||||
#endif
|
||||
|
||||
char buffer[buffer_size];
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
/*-------------------------------------------------*\
|
||||
| Initialize Winsock data required on Windows |
|
||||
| before socket calls |
|
||||
\*-------------------------------------------------*/
|
||||
WSADATA wsa_data;
|
||||
if(WSAStartup(MAKEWORD(2, 2), &wsa_data) != 0)
|
||||
{
|
||||
return "unknown";
|
||||
}
|
||||
#endif
|
||||
|
||||
std::string hostname = "unknown";
|
||||
|
||||
if(gethostname(buffer, sizeof(buffer)) == 0)
|
||||
{
|
||||
hostname = buffer;
|
||||
}
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
WSACleanup();
|
||||
#endif
|
||||
|
||||
return(hostname);
|
||||
}
|
||||
|
||||
void InitNetPacketHeader
|
||||
(
|
||||
NetPacketHeader * pkt_hdr,
|
||||
|
||||
Reference in new issue
Block a user