mirror of
https://git.sr.ht/~thestr4ng3r/chiaki
synced 2025-08-21 14:03:11 -07:00
Display Server Info
This commit is contained in:
parent
446ddd0071
commit
696cf7823f
6 changed files with 58 additions and 24 deletions
|
@ -53,24 +53,11 @@ typedef enum chiaki_discovery_host_state_t
|
|||
|
||||
const char *chiaki_discovery_host_state_string(ChiakiDiscoveryHostState state);
|
||||
|
||||
typedef struct chiaki_discovery_host_t
|
||||
{
|
||||
// All string members here must be in sync with CHIAKI_DISCOVERY_HOST_STRING_FOREACH
|
||||
ChiakiDiscoveryHostState state;
|
||||
const char *system_version;
|
||||
const char *device_discovery_protocol_version;
|
||||
uint16_t host_request_port;
|
||||
const char *host_name;
|
||||
const char *host_type;
|
||||
const char *host_id;
|
||||
const char *running_app_titleid;
|
||||
const char *running_app_name;
|
||||
} ChiakiDiscoveryHost;
|
||||
|
||||
/**
|
||||
* Apply A on all names of string members in ChiakiDiscoveryHost
|
||||
*/
|
||||
#define CHIAKI_DISCOVERY_HOST_STRING_FOREACH(A) \
|
||||
A(host_addr); \
|
||||
A(system_version); \
|
||||
A(device_discovery_protocol_version); \
|
||||
A(host_name); \
|
||||
|
@ -79,6 +66,17 @@ typedef struct chiaki_discovery_host_t
|
|||
A(running_app_titleid); \
|
||||
A(running_app_name);
|
||||
|
||||
typedef struct chiaki_discovery_host_t
|
||||
{
|
||||
// All string members here must be in sync with CHIAKI_DISCOVERY_HOST_STRING_FOREACH
|
||||
ChiakiDiscoveryHostState state;
|
||||
uint16_t host_request_port;
|
||||
#define STRING_MEMBER(name) const char *name;
|
||||
CHIAKI_DISCOVERY_HOST_STRING_FOREACH(STRING_MEMBER)
|
||||
#undef STRING_MEMBER
|
||||
} ChiakiDiscoveryHost;
|
||||
|
||||
|
||||
CHIAKI_EXPORT int chiaki_discovery_packet_fmt(char *buf, size_t buf_size, ChiakiDiscoveryPacket *packet);
|
||||
|
||||
typedef struct chiaki_discovery_t
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include <netdb.h>
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
const char *chiaki_discovery_host_state_string(ChiakiDiscoveryHostState state)
|
||||
{
|
||||
|
@ -51,7 +52,7 @@ CHIAKI_EXPORT int chiaki_discovery_packet_fmt(char *buf, size_t buf_size, Chiaki
|
|||
}
|
||||
}
|
||||
|
||||
CHIAKI_EXPORT ChiakiErrorCode chiaki_discovery_srch_response_parse(ChiakiDiscoveryHost *response, char *buf, size_t buf_size)
|
||||
CHIAKI_EXPORT ChiakiErrorCode chiaki_discovery_srch_response_parse(ChiakiDiscoveryHost *response, struct sockaddr *addr, char *buf, size_t buf_size)
|
||||
{
|
||||
ChiakiHttpResponse http_response;
|
||||
ChiakiErrorCode err = chiaki_http_response_parse(&http_response, buf, buf_size);
|
||||
|
@ -60,6 +61,28 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_discovery_srch_response_parse(ChiakiDiscove
|
|||
|
||||
memset(response, 0, sizeof(*response));
|
||||
|
||||
size_t host_addr_str_size = 40;
|
||||
char *host_addr_str = malloc(host_addr_str_size);
|
||||
if(!host_addr_str)
|
||||
return CHIAKI_ERR_MEMORY;
|
||||
void *addr_src;
|
||||
switch(addr->sa_family)
|
||||
{
|
||||
case AF_INET:
|
||||
addr_src = &((struct sockaddr_in *)addr)->sin_addr;
|
||||
break;
|
||||
case AF_INET6:
|
||||
addr_src = &((struct sockaddr_in6 *)addr)->sin6_addr;
|
||||
break;
|
||||
default:
|
||||
addr_src = NULL;
|
||||
break;
|
||||
}
|
||||
if(addr_src)
|
||||
response->host_addr = inet_ntop(addr->sa_family, addr_src, host_addr_str, host_addr_str_size);
|
||||
if(!response->host_addr)
|
||||
free(host_addr_str);
|
||||
|
||||
switch(http_response.code)
|
||||
{
|
||||
case 200:
|
||||
|
@ -245,7 +268,7 @@ static void *discovery_thread_func(void *user)
|
|||
//chiaki_log_hexdump_raw(discovery->log, CHIAKI_LOG_VERBOSE, (const uint8_t *)buf, n);
|
||||
|
||||
ChiakiDiscoveryHost response;
|
||||
err = chiaki_discovery_srch_response_parse(&response, buf, n);
|
||||
err = chiaki_discovery_srch_response_parse(&response, &client_addr, buf, n);
|
||||
if(err != CHIAKI_ERR_SUCCESS)
|
||||
{
|
||||
CHIAKI_LOGI(discovery->log, "Discovery Response invalid");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue