19int main(
int argc,
char* argv[]) {
37 bj_info(
"discover: listening for broadcasts on port %d",
PORT);
41 bj_info(
"discover: no broadcasts received in last 5 seconds...");
59 if (len >=
sizeof(message)) {
60 len =
sizeof(message) - 1;
65 bj_info(
"discover: found service at %s:%d - \"%s\"",
struct bj_datagram bj_datagram
const char * bj_error_message(const struct bj_error *error)
Gets the error message from an error object.
void bj_clear_error(struct bj_error **error)
Frees an error and sets the pointer to NULL.
#define bj_info(...)
Log a message using the BJ_LOG_INFO level.
#define bj_err(...)
Log a message using the BJ_LOG_ERROR level.
struct bj_datagram * bj_receive_udp(struct bj_udp *udp, struct bj_error **error)
Receives a datagram from the UDP socket.
bj_bool bj_wait_udp(struct bj_udp *udp, uint32_t ms_timeout)
Waits for data to become available on a UDP socket.
size_t bj_datagram_length(const struct bj_datagram *dgram)
Gets the data length from a datagram.
uint16_t bj_datagram_port(const struct bj_datagram *dgram)
Gets the sender's port from a datagram.
void bj_destroy_datagram(struct bj_datagram *dgram)
Closes a datagram and frees resources.
void bj_destroy_udp(struct bj_udp *udp)
Closes a UDP socket.
struct bj_udp * bj_create_udp(const char *host, uint16_t port, uint16_t hints, struct bj_error **error)
Opens a UDP socket bound to the specified port.
#define BJ_ADDR_STRLEN
Maximum length of an address string (including null terminator).
size_t bj_datagram_address(const struct bj_datagram *dgram, char *buf, size_t size)
Gets the sender's address from a datagram.
const void * bj_datagram_data(const struct bj_datagram *dgram)
Gets the data pointer from a datagram.
@ BJ_NET_HINT_IPV4
Restrict address resolution to IPv4.
bj_bool bj_begin(int systems, struct bj_error **error)
Initialises the system.
void bj_end(void)
De-initialises the system.
Logging utility functions.
Portable main() replacement with platform-aware entry shim.
Header file for network API.
UTF-8 string views and owning strings.
Header file for system interactions.