ascii-chat
Binary v0.16.114-28-gf5913657f
Library lib/v0.3.2-3302-gf5913657f
Video chat in your terminal
Loading...
Searching...
No Matches
mdns.c File Reference

Go to the source code of this file.

Functions

ui_mdns_server_t * ui_mdns_query (const ui_mdns_config_t *, int *out_count)
 Discover ascii-chat servers on the local network via mDNS.
const char * ui_mdns_get_best_address (const ui_mdns_server_t *)
 Get best address representation for a discovered server.
int ui_mdns_select (const ui_mdns_server_t *, int)
void ui_mdns_free_results (ui_mdns_server_t *)
 Free results from TUI discovery query.

Function Documentation

◆ ui_mdns_free_results()

void ui_mdns_free_results ( ui_mdns_server_t * servers)

Free results from TUI discovery query.

Releases memory allocated by ui_mdns_query().

Parameters
serversPointer to server array (safe to pass NULL)
Note
Safe to call multiple times or with NULL pointer

Free results from TUI discovery query.

Definition at line 20 of file wasm/stubs/mdns.c.

20{}

◆ ui_mdns_get_best_address()

const char * ui_mdns_get_best_address ( const ui_mdns_server_t * server)

Get best address representation for a discovered server.

Returns the most suitable address representation (IPv4 > IPv6 > hostname) for connecting to a discovered server.

Selection Priority:

  1. IPv4 address (most universal)
  2. IPv6 address
  3. Advertised hostname (service labels are never connection destinations)
Parameters
serverDiscovered server
Returns
Pointer to best address string (points to field in server struct)

Get best address representation for a discovered server.

Get best address for a server

Definition at line 12 of file wasm/stubs/mdns.c.

12 {
13 return NULL;
14}

◆ ui_mdns_query()

ui_mdns_server_t * ui_mdns_query ( const ui_mdns_config_t * config,
int * out_count )

Discover ascii-chat servers on the local network via mDNS.

Performs an mDNS query for _ascii-chat._tcp services on the local network. Collects responses and returns discovered servers to the caller.

Behavior:

  • Sends multicast mDNS query for _ascii-chat._tcp.local services
  • Waits for responses for the specified timeout period
  • Collects all discovered servers with their addresses and ports
  • Returns array of discovered servers

Memory Management:

Error Handling:

  • Returns NULL and sets errno on initialization failure
  • Partial results returned if mDNS init fails but discovery was attempted
  • Network errors logged but don't prevent continuation

Threading:

  • Blocking operation - waits for full timeout period
  • Safe to call from main thread
  • Does not spawn background threads
Parameters
configDiscovery configuration (NULL uses defaults)
out_countOutput parameter: number of discovered servers
Returns
Array of discovered servers, or NULL on error Must be freed with ui_mdns_free_results()
Note
Timeout includes network round-trip time, so 2000ms allows ~1.5s of actual waiting
Returns empty array (non-NULL with count=0) if no servers found, not NULL

Example:

ui_mdns_config_t config = {.timeout_ms = 2000, .max_servers = 20};
int count = 0;
ui_mdns_server_t *servers = ui_mdns_query(&config, &count);
if (servers && count > 0) {
for (int i = 0; i < count; i++) {
printf("%d: %s (%s:%d)\n", i+1, servers[i].name, servers[i].address,
servers[i].port);
}
// User selects server...
}
Configuration for TUI discovery.
Definition tui/mdns.h:86
Discovered server information from mDNS.
Definition tui/mdns.h:68
ui_mdns_server_t * ui_mdns_query(const ui_mdns_config_t *config, int *out_count)
TUI-based server selection with formatted display.
Definition tui/mdns.c:79
void ui_mdns_free_results(ui_mdns_server_t *servers)
Free results from mDNS discovery.
Definition tui/mdns.c:102

Discover ascii-chat servers on the local network via mDNS.

TUI wrapper around core mDNS discovery

Calls discovery_mdns_query() from discovery.c with TUI-friendly configuration.

Definition at line 4 of file wasm/stubs/mdns.c.

4 {
5 if (out_count) {
6 *out_count = 0;
7 }
8 SET_ERRNO(ERROR_NOT_SUPPORTED, "Native mDNS discovery unavailable in the browser");
9 return NULL;
10}
#define SET_ERRNO(code,...)
@ ERROR_NOT_SUPPORTED
Definition error_codes.h:74

References ERROR_NOT_SUPPORTED, and SET_ERRNO.

◆ ui_mdns_select()

int ui_mdns_select ( const ui_mdns_server_t * servers,
int count )

Shared controller list: arrows/j/k move, Enter selects, digits choose by number, Esc/q cancels. Resizes retain the selection and scroll it into view. Returns -1 without waiting when no interactive terminal is available.

Definition at line 16 of file wasm/stubs/mdns.c.

16 {
17 return -1;
18}