_________ __ __ / _____// |_____________ _/ |______ ____ __ __ ______ \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/ / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ \ /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ > \/ \/ \//_____/ \/ ______________________ ______________________ T H E W A R B E G I N S Stratagus - A free fantasy real time strategy game engine
#include <stdint.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
Go to the source code of this file.
Classes | |
struct | mdns_string_t |
struct | mdns_string_pair_t |
struct | mdns_record_srv_t |
struct | mdns_record_txt_t |
struct | mdns_header_t |
Macros | |
#define | MDNS_INVALID_POS ((size_t)-1) |
#define | MDNS_STRING_CONST(s) (s), (sizeof((s)) - 1) |
#define | MDNS_STRING_FORMAT(s) (int)((s).length), s.str |
#define | MDNS_POINTER_OFFSET(p, ofs) ((void*)((char*)(p) + (ptrdiff_t)(ofs))) |
#define | MDNS_POINTER_OFFSET_CONST(p, ofs) ((const void*)((const char*)(p) + (ptrdiff_t)(ofs))) |
#define | MDNS_POINTER_DIFF(a, b) ((size_t)((const char*)(a) - (const char*)(b))) |
#define | MDNS_PORT 5353 |
#define | MDNS_UNICAST_RESPONSE 0x8000U |
#define | MDNS_CACHE_FLUSH 0x8000U |
Typedefs | |
typedef enum mdns_record_type | mdns_record_type_t |
typedef enum mdns_entry_type | mdns_entry_type_t |
typedef enum mdns_class | mdns_class_t |
typedef int(* | mdns_record_callback_fn) (int sock, const struct sockaddr *from, size_t addrlen, mdns_entry_type_t entry, uint16_t query_id, uint16_t rtype, uint16_t rclass, uint32_t ttl, const void *data, size_t size, size_t name_offset, size_t name_length, size_t record_offset, size_t record_length, void *user_data) |
typedef struct mdns_string_t | mdns_string_t |
typedef struct mdns_string_pair_t | mdns_string_pair_t |
typedef struct mdns_record_srv_t | mdns_record_srv_t |
typedef struct mdns_record_txt_t | mdns_record_txt_t |
typedef size_t | mdns_size_t |
Enumerations | |
enum | mdns_record_type { MDNS_RECORDTYPE_IGNORE = 0, MDNS_RECORDTYPE_A = 1, MDNS_RECORDTYPE_PTR = 12, MDNS_RECORDTYPE_TXT = 16, MDNS_RECORDTYPE_AAAA = 28, MDNS_RECORDTYPE_SRV = 33 } |
enum | mdns_entry_type { MDNS_ENTRYTYPE_QUESTION = 0, MDNS_ENTRYTYPE_ANSWER = 1, MDNS_ENTRYTYPE_AUTHORITY = 2, MDNS_ENTRYTYPE_ADDITIONAL = 3 } |
enum | mdns_class { MDNS_CLASS_IN = 1 } |
Functions | |
static int | mdns_socket_open_ipv4 (struct sockaddr_in *saddr) |
Open and setup a IPv4 socket for mDNS/DNS-SD. To bind the socket to a specific interface,. More... | |
static int | mdns_socket_setup_ipv4 (int sock, struct sockaddr_in *saddr) |
Setup an already opened IPv4 socket for mDNS/DNS-SD. To bind the socket to a specific interface,. More... | |
static int | mdns_socket_open_ipv6 (struct sockaddr_in6 *saddr) |
Open and setup a IPv6 socket for mDNS/DNS-SD. To bind the socket to a specific interface,. More... | |
static int | mdns_socket_setup_ipv6 (int sock, struct sockaddr_in6 *saddr) |
Setup an already opened IPv6 socket for mDNS/DNS-SD. To bind the socket to a specific interface,. More... | |
static void | mdns_socket_close (int sock) |
Close a socket opened with mdns_socket_open_ipv4 and mdns_socket_open_ipv6. More... | |
static size_t | mdns_socket_listen (int sock, void *buffer, size_t capacity, mdns_record_callback_fn callback, void *user_data) |
Listen for incoming multicast DNS-SD and mDNS query requests. The socket should have been. More... | |
static int | mdns_discovery_send (int sock) |
Send a multicast DNS-SD reqeuest on the given socket to discover available services. Returns. More... | |
static size_t | mdns_discovery_recv (int sock, void *buffer, size_t capacity, mdns_record_callback_fn callback, void *user_data) |
Recieve unicast responses to a DNS-SD sent with mdns_discovery_send. Any data will be piped to. More... | |
static int | mdns_discovery_answer (int sock, const void *address, size_t address_size, void *buffer, size_t capacity, const char *record, size_t length) |
Send a unicast DNS-SD answer with a single record to the given address. Returns 0 if success,. More... | |
static int | mdns_query_send (int sock, mdns_record_type_t type, const char *name, size_t length, void *buffer, size_t capacity, uint16_t query_id) |
Send a multicast mDNS query on the given socket for the given service name. The supplied buffer. More... | |
static size_t | mdns_query_recv (int sock, void *buffer, size_t capacity, mdns_record_callback_fn callback, void *user_data, int query_id) |
Receive unicast responses to a mDNS query sent with mdns_discovery_recv, optionally filtering. More... | |
static int | mdns_query_answer (int sock, const void *address, size_t address_size, void *buffer, size_t capacity, uint16_t query_id, const char *service, size_t service_length, const char *hostname, size_t hostname_length, uint32_t ipv4, const uint8_t *ipv6, uint16_t port, const char *txt, size_t txt_length) |
Send a unicast or multicast mDNS query answer with a single record to the given address. The. More... | |
static mdns_string_t | mdns_string_extract (const void *buffer, size_t size, size_t *offset, char *str, size_t capacity) |
static int | mdns_string_skip (const void *buffer, size_t size, size_t *offset) |
static int | mdns_string_equal (const void *buffer_lhs, size_t size_lhs, size_t *ofs_lhs, const void *buffer_rhs, size_t size_rhs, size_t *ofs_rhs) |
static void * | mdns_string_make (void *data, size_t capacity, const char *name, size_t length) |
static void * | mdns_string_make_ref (void *data, size_t capacity, size_t ref_offset) |
static void * | mdns_string_make_with_ref (void *data, size_t capacity, const char *name, size_t length, size_t ref_offset) |
static mdns_string_t | mdns_record_parse_ptr (const void *buffer, size_t size, size_t offset, size_t length, char *strbuffer, size_t capacity) |
static mdns_record_srv_t | mdns_record_parse_srv (const void *buffer, size_t size, size_t offset, size_t length, char *strbuffer, size_t capacity) |
static struct sockaddr_in * | mdns_record_parse_a (const void *buffer, size_t size, size_t offset, size_t length, struct sockaddr_in *addr) |
static struct sockaddr_in6 * | mdns_record_parse_aaaa (const void *buffer, size_t size, size_t offset, size_t length, struct sockaddr_in6 *addr) |
static size_t | mdns_record_parse_txt (const void *buffer, size_t size, size_t offset, size_t length, mdns_record_txt_t *records, size_t capacity) |
static int | mdns_is_string_ref (uint8_t val) |
static mdns_string_pair_t | mdns_get_next_substring (const void *rawdata, size_t size, size_t offset) |
static size_t | mdns_string_find (const char *str, size_t length, char c, size_t offset) |
static size_t | mdns_records_parse (int sock, const struct sockaddr *from, size_t addrlen, const void *buffer, size_t size, size_t *offset, mdns_entry_type_t type, uint16_t query_id, size_t records, mdns_record_callback_fn callback, void *user_data) |
static int | mdns_unicast_send (int sock, const void *address, size_t address_size, const void *buffer, size_t size) |
static int | mdns_multicast_send (int sock, const void *buffer, size_t size) |
Variables | |
static const uint8_t | mdns_services_query [] |
#define MDNS_CACHE_FLUSH 0x8000U |
#define MDNS_INVALID_POS ((size_t)-1) |
#define MDNS_POINTER_DIFF | ( | a, | |
b | |||
) | ((size_t)((const char*)(a) - (const char*)(b))) |
#define MDNS_POINTER_OFFSET | ( | p, | |
ofs | |||
) | ((void*)((char*)(p) + (ptrdiff_t)(ofs))) |
#define MDNS_POINTER_OFFSET_CONST | ( | p, | |
ofs | |||
) | ((const void*)((const char*)(p) + (ptrdiff_t)(ofs))) |
#define MDNS_PORT 5353 |
#define MDNS_STRING_CONST | ( | s | ) | (s), (sizeof((s)) - 1) |
#define MDNS_STRING_FORMAT | ( | s | ) | (int)((s).length), s.str |
#define MDNS_UNICAST_RESPONSE 0x8000U |
typedef enum mdns_class mdns_class_t |
typedef enum mdns_entry_type mdns_entry_type_t |
typedef int(* mdns_record_callback_fn) (int sock, const struct sockaddr *from, size_t addrlen, mdns_entry_type_t entry, uint16_t query_id, uint16_t rtype, uint16_t rclass, uint32_t ttl, const void *data, size_t size, size_t name_offset, size_t name_length, size_t record_offset, size_t record_length, void *user_data) |
typedef struct mdns_record_srv_t mdns_record_srv_t |
typedef struct mdns_record_txt_t mdns_record_txt_t |
typedef enum mdns_record_type mdns_record_type_t |
typedef size_t mdns_size_t |
typedef struct mdns_string_pair_t mdns_string_pair_t |
typedef struct mdns_string_t mdns_string_t |
enum mdns_class |
enum mdns_entry_type |
enum mdns_record_type |
|
static |
Send a unicast DNS-SD answer with a single record to the given address. Returns 0 if success,.
|
static |
Recieve unicast responses to a DNS-SD sent with mdns_discovery_send. Any data will be piped to.
|
static |
Send a multicast DNS-SD reqeuest on the given socket to discover available services. Returns.
|
static |
|
static |
|
static |
|
static |
Send a unicast or multicast mDNS query answer with a single record to the given address. The.
|
static |
Receive unicast responses to a mDNS query sent with mdns_discovery_recv, optionally filtering.
|
static |
Send a multicast mDNS query on the given socket for the given service name. The supplied buffer.
Optional unicast response based on local port, class IN
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
Close a socket opened with mdns_socket_open_ipv4 and mdns_socket_open_ipv6.
|
static |
Listen for incoming multicast DNS-SD and mDNS query requests. The socket should have been.
|
static |
Open and setup a IPv4 socket for mDNS/DNS-SD. To bind the socket to a specific interface,.
|
static |
Open and setup a IPv6 socket for mDNS/DNS-SD. To bind the socket to a specific interface,.
|
static |
Setup an already opened IPv4 socket for mDNS/DNS-SD. To bind the socket to a specific interface,.
|
static |
Setup an already opened IPv6 socket for mDNS/DNS-SD. To bind the socket to a specific interface,.
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |