mdns.c File Reference

Standard compliant, minimal implementation of Multiast DNS. More...

#include "nip_init.h"
#include "app/mdns.h"
#include "dispatcher.h"
#include "net/udp.h"
#include "app/ports.h"
#include "inet.h"

Include dependency graph for mdns.c:

Go to the source code of this file.

Functions

void nip_mdns_register_hostname (struct nip_dns_string *name)
 set new host name.
void nip_mdns_disp_check_queries (void)
 Check list of mDNS queries.
nip_error_t nip_mdns_parse_packet (nip_udp_buf_type_t udp_buffer, nip_mdns_packet_task_t task, nip_mem_ptr_t *p, nip_mdns_qa_offset_t section)
 Perform several tasks on DNS packets.
nip_error_t nip_mdns_init (void)
 initialize mdns memory
nip_error_t nip_mdns_name_cmp (struct nip_dns_string *n1, struct nip_dns_string *n2)
 Perform dns name parsing-operation, depending on task parameter.
nip_mdns_namestring_id_t nip_mdns_register_name (nip_mdns_namestring_id_t *id, uint8_t cnt, nip_mem_ptr_t *name_ptr, nip_mdns_namestring_usg_t usg)
 Registers new MDNS namestring or retrieves already registered entry for that name.
nip_mdns_query_id_t nip_mdns_query (nip_mdns_query_type_t type, struct nip_mdns_name *rr_name, nip_mdns_type_t rr_type)
 Execute MDNS lookup query.
nip_mdns_record_size_t nip_mdns_record_size (struct nip_mdns_record *r)
 Return size of cache record.
struct nip_mdns_cachenip_mdns_cache_ptr (nip_mdns_cache_id_t id)
 Get pointer to specific cache entry.
nip_error_t nip_mdns_cache_task (nip_mdns_task_t task, nip_mdns_cache_id_t *id, struct nip_mdns_record *record)
 Perform mDNS cache operation.
nip_error_t nip_mdns_notify (nip_mdns_nfy_task_t task, nip_mdns_cache_id_t c_id, nip_mdns_query_id_t q_id, uint8_t nfy)
 Edit query notification list.
nip_error_t nip_mdns_close (nip_mdns_query_id_t r_id)
 Close query.
nip_mdns_cache_id_t nip_mdns_fetch_results (nip_mdns_query_id_t r_id)
 Fetch next result for lookup query.
nip_error_t nip_mdns_unregister (nip_mdns_cache_id_t id)
 Unregister previosly registered DNS record.
void nip_mdns_interface_up (nip_net_if_id_t if_id)
 Register host name and refresh cache.
void nip_mdns_interface_down (void)
void nip_mdns_disp_check_cache (void)
nip_error_t nip_mdns_tx_init (nip_mdns_packet_type_t ptype)
 Initialize Sending of packet.
nip_error_t nip_mdns_tx_name (nip_mem_ptr_t *dst, struct nip_mdns_name *rr_name, nip_mdns_type_t rr_type, uint8_t uclass_byte)
 Add DNS Name/Type/Class to Buffer.
void nip_mdns_transmit (void)
void nip_mdns_disp_check (void)
 Dispatcher function to be called upon receiving mDNS events.

Variables

struct nip_mdns_check nip_mdns
nip_net_if_id_t nip_mdns_if_id = NIP_NET_NO_IF
nip_udp_sock_id_t nip_mdns_sock = NIP_UDP_NO_SOCKET
nip_mdns_cache_id_t nip_mdns_hostname = NIP_MDNS_NO_CACHE_ID
nip_mdns_cache_id_t nip_mdns_host_ptr = NIP_MDNS_NO_CACHE_ID
nip_mdns_namestring_id_t nip_mdns_domain = NIP_MDNS_NO_NAMESTRING
nip_mem_handle_t nip_mdns_cs = NIP_MEM_NULL
 cache subscriptions
nip_mem_ptr_t nip_mdns_cache = {NIP_MEM_NULL,NULL}
 MDNS cache.
nip_mem_handle_t nip_mdns_names = NIP_MEM_NULL
 MDNS name strings.
nip_mem_ptr_t nip_mdns_queries = {NIP_MEM_NULL,NULL}
 MDNS queries.


Detailed Description

Standard compliant, minimal implementation of Multiast DNS.

Todo:
Make it standard compliant. ;) (timing, conflicts, local queries...)

Definition in file mdns.c.


Function Documentation

struct nip_mdns_cache* nip_mdns_cache_ptr ( nip_mdns_cache_id_t  id  )  [read]

Get pointer to specific cache entry.

Note:
You have to call nip_mem_release_block( nip_mdns_cache.id ) to release the retrieved pointer and unlock the cache.
Returns:
Pointer to cache entry. On error NULL will be returned and nip_error be set to one of the following values:
  • NIP_E_NOT_FOUND no record found for given ID
  • NIP_E_LOCKED cache locked, try again later

Definition at line 563 of file mdns.c.

References nip_mdns_cache::id, nip_mem_ptr_t::id, NIP_E_LOCKED, NIP_E_NOT_FOUND, nip_error, NIP_MDNS_BASE_CACHE_SIZE, nip_mdns_record_size(), nip_mem_buf_used(), nip_mem_obtain_ptr(), nip_mem_release_block(), NULL, and nip_mdns_cache::record.

Here is the call graph for this function:

nip_error_t nip_mdns_cache_task ( nip_mdns_task_t  task,
nip_mdns_cache_id_t id,
struct nip_mdns_record record 
)

Perform mDNS cache operation.

Type of operation depends on task parameter.

  • The register operation will add a new authorative record.
  • The learn operation will add or update a remote DNS record.
  • The get operation will retrieve the record data for a given ID.
  • The search operation will return the Id of the existing cache record that matches certain attributes from the given record. The set of attributes chosen for the match depends on the record type.
  • The reset operation removes all learned entries from cache, clears the subscription array and resets all registered entries into PROBING state.

Note:
This function will not trigger any dispatcher events or update the subscription list as it's just an internal function to be called by other mDNS functions.
Parameters:
record Pointer to DNS record to be added or searched
task register, learn or search record or reset cache
Returns:
Id of registered, updated or found cache entry. Will be set to NIP_MDNS_NO_CACHE_ID on error, nip_error will be set to one of the following then:
  • NIP_E_LOCKED cache locked, try again later
  • NIP_E_OUT_OF_MEMORY unable to allocate memory for new record
  • NIP_E_OUT_OF_RESSOURECES cache full
  • NIP_E_NOT_FOUND search operation was unsuccessfull
  • NIP_E_EXISTS register failed because record exists already
  • NIP_E_INTERNAL_ERROR something went wrong where it shouldn't have

Todo:
support multiple entries for the same name?

Todo:
nip_mdns_register_record_names( record, 1 )

Todo:
on error goto release

Todo:
nip_mdns_register_record_names( l->record, -1 )

Todo:
on error, try to unregister new record names, set INTERNAL_ERROR because name-count may now be inconsistant and goto release.

Todo:
set notification bit

Definition at line 627 of file mdns.c.

References nip_mdns_cache::age, nip_mdns_record::data, nip_mdns_cache::id, nip_mem_ptr_t::id, nip_mdns_record::name, NIP_DISP_CHECK_MDNS, nip_disp_notify, NIP_E_EXISTS, NIP_E_INTERNAL_ERROR, NIP_E_LOCKED, NIP_E_NOT_FOUND, NIP_E_OK, NIP_E_OUT_OF_MEMORY, NIP_E_OUT_OF_RESSOURCES, nip_error, NIP_MDNS_BASE_CACHE_SIZE, NIP_MDNS_CSTAT_ANNOUNCING, NIP_MDNS_CSTAT_AUTH_MASK, NIP_MDNS_CSTAT_DELETE, NIP_MDNS_CSTAT_LEARNED, NIP_MDNS_CSTAT_PROBING, NIP_MDNS_MAX_CACHE_SIZE, NIP_MDNS_MAX_NAME_DEPTH, NIP_MDNS_NAME_USE, NIP_MDNS_NO_CACHE_ID, nip_mdns_record_size(), NIP_MDNS_TASK_GET, NIP_MDNS_TASK_GET_LEARNED, NIP_MDNS_TASK_LEARN, NIP_MDNS_TASK_REGISTER, NIP_MDNS_TASK_REGUNIQUE, NIP_MDNS_TASK_RESET, NIP_MDNS_TASK_SEARCH, NIP_MDNS_TYPE_PTR, NIP_MDNS_UNREG_NAME, nip_mem_buf_used(), nip_mem_obtain_ptr(), nip_mem_ptr(), nip_mem_release_block(), nip_mem_set_used(), nip_mem_write(), nip_memcmp, nip_memcpy(), NULL, nip_mdns_name::part, nip_mem_ptr_t::ptr, nip_mdns_cache::record, nip_mdns_cache::stat, nip_mdns_record::ttl, and nip_mdns_record::type.

Referenced by nip_mdns_disp_check_queries().

Here is the call graph for this function:

Here is the caller graph for this function:

nip_error_t nip_mdns_close ( nip_mdns_query_id_t  r_id  ) 

Close query.

Todo:
implement

Definition at line 889 of file mdns.c.

References NIP_E_OK.

void nip_mdns_disp_check ( void   ) 

Dispatcher function to be called upon receiving mDNS events.

Todo:
check that the packet originated on the local link

Todo:
loop through queries

Todo:
-> loop through answers in packet

Todo:
answer matches local query? -> update cache -> update subscriptions
Todo:
answer matches remote query? -> update subscriptions for matching cache entries

Todo:
loop through queries

Todo:
remote query? -> loop through subscription list -> retrieve answers from cache and fill packet
Todo:
local query? -> check timer
Todo:
remove query marked for deletion and all notifications done? -> remove from list -> remove subscriptions

Todo:
loop through namestrings to remove unused names

Definition at line 1838 of file mdns.c.

References nip_udp_sock_addr::ip, NIP_CURR_CMD, NIP_DNS_OP_MASK, NIP_DNS_QR_MASK, NIP_DNS_RC_MASK, NIP_E_OK, NIP_IP_ADDR, nip_mdns, nip_mdns_disp_check_cache(), nip_mdns_disp_check_queries(), nip_mdns_if_id, nip_mdns_init(), NIP_MDNS_NSCOUNT_OFFSET, NIP_MDNS_PTYPE_NONE, NIP_MDNS_PTYPE_PROBE, NIP_MDNS_PTYPE_QUERY, NIP_MDNS_PTYPE_RESPONSE, NIP_MDNS_QDCOUNT_OFFSET, nip_mdns_sock, NIP_MDNS_STAT_CACHE_CHECK, NIP_MDNS_STAT_DOWN, NIP_MDNS_STAT_INIT, NIP_MDNS_STAT_QUERY_CHECK, nip_memcmp, nip_udp_cancel_recv(), nip_udp_data_ptr(), NIP_UDP_NO_SOCKET, nip_udp_ptr_release(), nip_udp_recvfrom(), NIP_UDP_RX_BUF, NULL, nip_dns_header::qa_count, nip_dns_header::qr_opcode_aa_tc_rd, nip_dns_header::ra_z_ad_cd_rcode, nip_mdns_check::recv, nip_mdns_check::recv_size, and nip_mdns_check::stat.

Here is the call graph for this function:

void nip_mdns_disp_check_cache ( void   ) 

Todo:
remove items that are scheduled for deletion where all subscribers have been notified

Todo:
else check known answers

Todo:
received Probe that we have Probe for?

Todo:
-> handle probe conflict

Todo:
out-of-memory? -> goto release

Todo:
check if there are unnotified remote queries to this

Todo:
check if there's still a query interested in this item
Todo:
update age and possibly trigger delete or refresh

Todo:
check probe and announcement states of registered cache records

Todo:
allow announcement of non-unique records

Todo:
check if local hostname record changed and update all registered records if necessary

Definition at line 1066 of file mdns.c.

References nip_mdns_cache::id, nip_mem_ptr_t::id, nip_mdns_record::name, NIP_DNS_CLASS_IN, NIP_E_EOF, NIP_E_NO_MATCH, NIP_E_OK, nip_mdns, NIP_MDNS_BASE_CACHE_SIZE, NIP_MDNS_CHECK_NAME, NIP_MDNS_CSTAT_AUTH_BIT, NIP_MDNS_MAX_NAME_DEPTH, NIP_MDNS_NO_NAMESTRING, NIP_MDNS_NO_QUERY, nip_mdns_parse_packet(), NIP_MDNS_PTASK_NEXT_ITEM, NIP_MDNS_PTYPE_QUERY, NIP_MDNS_QDCOUNT_OFFSET, NIP_MDNS_QTYPE_REMOTE, nip_mdns_query(), nip_mdns_record_size(), nip_mdns_sock, NIP_MDNS_SUBSCRIBE_REMOTE, NIP_MDNS_TYPE_ANY, nip_mem_buf_used(), NIP_MEM_NULL, nip_mem_ptr(), nip_mem_release_ptr(), nip_memcpy(), nip_udp_data_mem_ptr(), nip_udp_data_ptr(), nip_udp_ptr_release(), NIP_UDP_RX_BUF, ntohs, NULL, nip_mdns_name::part, nip_mem_ptr_t::ptr, nip_mdns_cache::record, nip_mdns_check::recv, nip_mdns_check::recv_size, nip_mdns_cache::stat, and nip_mdns_record::type.

Referenced by nip_mdns_disp_check().

Here is the call graph for this function:

Here is the caller graph for this function:

void nip_mdns_disp_check_queries ( void   ) 

Check list of mDNS queries.

Todo:
remove items that have no more subscribers

Todo:
loop answers a in Packet
Todo:
a saisfies q ? q=local? -> add a to cache, subscribe/notify q,a q=probe? -> CONFLICT -> select new name, update cache items q=remote & a=probe? -> schedule immediate response (timeout=0)

Todo:
update query timer

if timeout==0 q=local? ->

Todo:
configure query
Todo:
loop notifications, q=remote? ->
Todo:
configure query response
Todo:
add answers

Todo:
remove REMOTE or PROBE Query und remove subscriptions

Definition at line 1497 of file mdns.c.

References nip_mdns_cache_subscription::c_id, nip_mdns_record::data, htons, nip_mdns_query::id, nip_mem_ptr_t::id, nip_mdns_rdata_ptr::name, nip_mdns_record::name, NIP_CURR_CMD, NIP_DISP_CHECK_MDNS, nip_disp_notify, NIP_DNS_CF_FLAG, NIP_E_LOCKED, NIP_E_OK, NIP_E_OUT_OF_MEMORY, nip_error, nip_mdns, NIP_MDNS_ANCOUNT_OFFSET, nip_mdns_cache_task(), nip_mdns_cs, NIP_MDNS_MAX_NAME_DEPTH, NIP_MDNS_NFY_REMOTE, NIP_MDNS_NO_CACHE_ID, NIP_MDNS_NSCOUNT_OFFSET, nip_mdns_parse_packet(), NIP_MDNS_PTASK_INC_COUNTER, NIP_MDNS_PTASK_SECTION_PTR, NIP_MDNS_PTASK_SET_TC, NIP_MDNS_PTYPE_ANSWCONTINUED, NIP_MDNS_PTYPE_NONE, NIP_MDNS_PTYPE_PROBE, NIP_MDNS_PTYPE_QUERY, NIP_MDNS_PTYPE_RESPONSE, NIP_MDNS_QDCOUNT_OFFSET, NIP_MDNS_QTYPE_ANNOUNCE, NIP_MDNS_QTYPE_LOCAL_BIT, NIP_MDNS_QTYPE_PROBE, NIP_MDNS_QTYPE_REMOTE, NIP_MDNS_QTYPE_TX_BIT, NIP_MDNS_QUERY_ID_MASK, NIP_MDNS_QUERY_NOTIFIED, nip_mdns_sock, NIP_MDNS_STAT_UP, NIP_MDNS_TASK_GET, NIP_MDNS_TASK_GET_LEARNED, nip_mdns_transmit(), nip_mdns_tx_init(), nip_mdns_tx_name(), NIP_MDNS_TYPE_A, NIP_MDNS_TYPE_PTR, NIP_MDNS_TYPE_SRV, NIP_MDNS_UNSUBSCRIBE_QUERY, NIP_MDNS_WRITE_NAME, nip_mem_buf_used(), nip_mem_cut(), nip_mem_insert(), NIP_MEM_NULL, nip_mem_ptr(), nip_mem_release_block(), nip_mem_release_ptr(), nip_memcpy(), nip_udp_cancel_recv(), nip_udp_cancel_send(), NIP_UDP_TX_BUF, NULL, nip_mdns_rdata_t::oth, nip_mdns_name::part, nip_mdns_rdata_srv::port, nip_mdns_rdata_srv::priority, nip_mdns_rdata_t::ptr, nip_mem_ptr_t::ptr, nip_mdns_cache_subscription::q_id, nip_mdns_check::recv, nip_mdns_query::rr_name, nip_mdns_query::rr_type, nip_mdns_check::send, nip_mdns_rdata_t::srv, nip_mdns_check::stat, nip_mdns_rdata_oth::string, nip_mdns_rdata_srv::target, nip_mdns_query::timer, nip_mdns_record::ttl, nip_mdns_record::type, nip_mdns_query::type, and nip_mdns_rdata_srv::weight.

Referenced by nip_mdns_disp_check().

Here is the call graph for this function:

Here is the caller graph for this function:

nip_mdns_cache_id_t nip_mdns_fetch_results ( nip_mdns_query_id_t  r_id  ) 

Fetch next result for lookup query.

This function has to be called repeatedly, to fetch all results until nip_mdns_close() is called.

Parameters:
r_id ID of query to fetch result from
Returns:
ID of cache entry to result. If no result was available NIP_MDNS_NO_CACHE_ID will be returned and nip_error be set to NIP_E_AGAIN.

Todo:
implement

Definition at line 901 of file mdns.c.

References NIP_MDNS_NO_CACHE_ID.

nip_error_t nip_mdns_init ( void   ) 

void nip_mdns_interface_down ( void   ) 

Todo:
send notifications to network

Todo:
reset cache, clean up remote queries

Definition at line 1052 of file mdns.c.

References nip_mdns, nip_mdns_if_id, nip_mdns_sock, NIP_MDNS_STAT_DOWN, NIP_NET_NO_IF, nip_udp_close(), and nip_mdns_check::stat.

Here is the call graph for this function:

void nip_mdns_interface_up ( nip_net_if_id_t  if_id  ) 

Register host name and refresh cache.

Definition at line 1039 of file mdns.c.

References NIP_DISP_CHECK_MDNS, nip_disp_notify, nip_mdns, nip_mdns_if_id, NIP_MDNS_RESET_CACHE, NIP_MDNS_STAT_INIT, and nip_mdns_check::stat.

nip_error_t nip_mdns_name_cmp ( struct nip_dns_string n1,
struct nip_dns_string n2 
)

Perform dns name parsing-operation, depending on task parameter.

Parameters:
task 
  • NIP_MDNS_NTASK_FIND check the local name list and fill the given name pointer (if not NULL) if the search was sucessfull.
  • NIP_MDNS_NTASK_WRITE write
name pointer to dns name structure
buf pointer to name buffer
size size of buffer. May be 0 for ..WRITE-task, if memory block is being used. operation will parse the name from Compare UTF-8 namestrings, case insensitively, according to mDNS draft chapter "18. Multicast DNS Character Set".
Note:
n1 or n2 MUST NOT be NULL.
Returns:
NIP_E_OK or NIP_E_NO_MATCH

Definition at line 189 of file mdns.c.

References nip_dns_string::len, NIP_E_NO_MATCH, NIP_E_OK, and nip_dns_string::s.

Referenced by nip_mdns_register_name().

Here is the caller graph for this function:

nip_error_t nip_mdns_notify ( nip_mdns_nfy_task_t  task,
nip_mdns_cache_id_t  c_id,
nip_mdns_query_id_t  q_id,
uint8_t  nfy 
)

Edit query notification list.

Parameters:
task whether to subscribe, unsubscribe or notify
c_id ID of changed cache item or NIP_MDNS_NO_CACHE_ID to notify all queries.
q_id ID of query item which is needed upon register.
nfy Flag, who is to be notified. NIP_MDNS_NFY_LOCAL, or -_REMOTE
Note:
for subscriptions, both c_id and q_id have to be set. No check will be performed on this, so you'll corrupt the list if you feed it wrongly.

Definition at line 816 of file mdns.c.

References NIP_E_LOCKED, NIP_E_OK, nip_mdns_cs, NIP_MDNS_NFYTASK_NOTIFIED, NIP_MDNS_NFYTASK_NOTIFY, NIP_MDNS_NFYTASK_SUBSCRIBE, NIP_MDNS_NFYTASK_UNSUBSCRIBE, NIP_MDNS_NO_CACHE_ID, NIP_MDNS_NO_QUERY, NIP_MDNS_QUERY_ID_MASK, nip_mem_buf_used(), nip_mem_obtain_ptr(), nip_mem_release_block(), nip_mem_set_used(), nip_mem_write(), nip_memmove, NULL, and nip_mdns_cache_subscription::q_id.

Here is the call graph for this function:

nip_error_t nip_mdns_parse_packet ( nip_udp_buf_type_t  udp_buffer,
nip_mdns_packet_task_t  task,
nip_mem_ptr_t p,
nip_mdns_qa_offset_t  section 
)

Perform several tasks on DNS packets.

For task NIP_MDNS_PTASK_NEXT_ITEM the return value may be NIP_E_EOF if there were no more items in the given section beyond the given pointer p.

Definition at line 1371 of file mdns.c.

References htons, nip_mem_ptr_t::id, NIP_DNS_TC_MASK, NIP_E_EOF, NIP_E_OK, nip_error, NIP_MDNS_PTASK_INC_COUNTER, NIP_MDNS_PTASK_NEXT_ITEM, NIP_MDNS_PTASK_SECTION_PTR, NIP_MDNS_PTASK_SET_TC, NIP_MDNS_QA_COUNTERS_NUMBER, NIP_MDNS_QDCOUNT_OFFSET, nip_mdns_sock, nip_mem_buf_used(), nip_mem_ptr(), nip_mem_release_ptr(), nip_udp_data_mem_ptr(), ntohs, NULL, nip_mem_ptr_t::ptr, nip_dns_header::qa_count, and nip_dns_header::qr_opcode_aa_tc_rd.

Referenced by nip_mdns_disp_check_cache(), and nip_mdns_disp_check_queries().

Here is the call graph for this function:

Here is the caller graph for this function:

Execute MDNS lookup query.

The query will be registered within the system and a query ID will be returned. That query has to be ultimately closed by calling nip_mdns_close(). Answers to the query can be polled by calling nip_mdns_fetch_results().

Parameters:
name pointer to DNS name
type DNS type
Returns:
query-ID or NIP_MDNS_NO_QUERY

Todo:
set timer correctly

Definition at line 440 of file mdns.c.

References nip_mdns_query::id, nip_mem_ptr_t::id, NIP_E_OK, NIP_MDNS_MAX_NAME_DEPTH, NIP_MDNS_MAX_QUERIES, NIP_MDNS_NAME_USE, NIP_MDNS_NO_QUERY, NIP_MDNS_QTYPE_LOCAL, NIP_MDNS_QTYPE_PROBE, NIP_MDNS_QTYPE_REMLOC, NIP_MDNS_QTYPE_REMOTE, NIP_MDNS_QUERY_ACTIVE, NIP_MDNS_QUERY_ID_MASK, nip_mem_buf_used(), nip_mem_obtain_ptr(), nip_mem_release_block(), nip_mem_write(), nip_memcmp, NULL, nip_mdns_query::rr_name, nip_mdns_query::rr_type, nip_mdns_query::timer, and nip_mdns_query::type.

Referenced by nip_mdns_disp_check_cache().

Here is the call graph for this function:

Here is the caller graph for this function:

nip_mdns_record_size_t nip_mdns_record_size ( struct nip_mdns_record r  ) 

Return size of cache record.

This function is used to ease usage of dynamically sized cache list items.

Definition at line 530 of file mdns.c.

References NIP_MDNS_A_RECORD_SIZE, NIP_MDNS_OTH_RECORD_SIZE, NIP_MDNS_PTR_RECORD_SIZE, NIP_MDNS_SRV_RECORD_SIZE, NIP_MDNS_TYPE_A, NIP_MDNS_TYPE_PTR, NIP_MDNS_TYPE_SRV, and nip_mdns_record::type.

Referenced by nip_mdns_cache_ptr(), nip_mdns_cache_task(), and nip_mdns_disp_check_cache().

Here is the caller graph for this function:

void nip_mdns_register_hostname ( struct nip_dns_string name  ) 

nip_mdns_namestring_id_t nip_mdns_register_name ( nip_mdns_namestring_id_t id,
uint8_t  cnt,
nip_mem_ptr_t name_ptr,
nip_mdns_namestring_usg_t  usg 
)

Registers new MDNS namestring or retrieves already registered entry for that name.

The namestring's usage counter will be increased for every call of nip_mdns_register_name(). This function may also be used to unregister a previously registered namestring by providing a negative usage count.

Parameters:
id if set, the usage counter for that namestring will be increased and name and len parameter will be ignored.
cnt if > 1, id will be treated as array of namestrings to be registered. Must be 0 if id is not set.
name_ptr pointer to buffer holding the name. If id is set, the found name(s) will be appended to that buffer, preceded by their length. The pointer has to point to a nip_dns_string structure.
len length of name
usg number of string usages to register (negative to unregister)
Returns:
ID of namestring or NIP_MDNS_NO_NAMESTRING on error.
Note:
If usg is 0 a simple lookup of the given namestring will be performed and -- if found -- it's Id be returned.

The function's result depends very much on the correct combination of the various parameters. Those are chosen to be as minimal as possible, which will most probably lead to erroneous usage of the function. You SHOULD NOT call this function directly but use the provided macros, which, depending on the provided function, require only a subset of the parameters to be set.

  • NIP_MDNS_REG_STRING
  • NIP_MDNS_REG_NAME
  • NIP_MDNS_NAME_USE
  • NIP_MDNS_UNREG_NAME
  • NIP_MDNS_CHECK_NAME
  • NIP_MDNS_WRITE_NAME

Definition at line 258 of file mdns.c.

References nip_mdns_namestring::id, nip_mem_ptr_t::id, nip_dns_string::len, NIP_E_OK, NIP_MDNS_MAX_NAME_DEPTH, NIP_MDNS_MAX_NAMESTRINGS, nip_mdns_name_cmp(), nip_mdns_names, NIP_MDNS_NO_NAMESTRING, NIP_MDNS_STRINGOFF, nip_mem_buf_used(), nip_mem_insert(), NIP_MEM_NULL, nip_mem_ptr(), nip_mem_release_block(), nip_mem_release_ptr(), nip_mem_set_used(), nip_mem_write(), nip_memcpy(), NULL, nip_mem_ptr_t::ptr, nip_dns_string::s, nip_mdns_namestring::str, and nip_mdns_namestring::usg.

Here is the call graph for this function:

void nip_mdns_transmit ( void   ) 

Definition at line 1347 of file mdns.c.

References nip_udp_sock_addr::ip, NIP_E_OK, nip_mdns, NIP_MDNS_ADDR0, NIP_MDNS_ADDR1, NIP_MDNS_ADDR2, NIP_MDNS_ADDR3, nip_mdns_if_id, NIP_MDNS_PTYPE_NONE, nip_mdns_sock, NIP_UDP_PORT_MDNS, nip_udp_transmit(), nip_udp_sock_addr::port, and nip_mdns_check::send.

Referenced by nip_mdns_disp_check_queries().

Here is the call graph for this function:

Here is the caller graph for this function:

nip_error_t nip_mdns_tx_init ( nip_mdns_packet_type_t  ptype  ) 

Initialize Sending of packet.

If successfull the global nip_mdns.send variable will be set to ptype. Only exception is, if that variable is NIP_MDNS_PTYPE_ANSWCONTINUED. In that case only ptypes == NIP_MDNS_PTYPE_QUERY will be accepted and nip_mdns.send will remain untouched to allow further special handling of that situation.

Definition at line 1280 of file mdns.c.

References NIP_DNS_AA_MASK, NIP_DNS_HSIZE, NIP_DNS_QR_MASK, NIP_E_AGAIN, NIP_E_OK, nip_mdns, NIP_MDNS_PTYPE_ANSWCONTINUED, NIP_MDNS_PTYPE_NONE, NIP_MDNS_PTYPE_QUERY, NIP_MDNS_PTYPE_RESPONSE, nip_mdns_sock, nip_udp_cancel_send(), nip_udp_data_ptr(), nip_udp_init_send(), nip_udp_ptr_release(), NIP_UDP_TX_BUF, nip_udp_write(), NULL, nip_dns_header::qr_opcode_aa_tc_rd, and nip_mdns_check::send.

Referenced by nip_mdns_disp_check_queries().

Here is the call graph for this function:

Here is the caller graph for this function:

nip_error_t nip_mdns_tx_name ( nip_mem_ptr_t dst,
struct nip_mdns_name rr_name,
nip_mdns_type_t  rr_type,
uint8_t  uclass_byte 
)

Add DNS Name/Type/Class to Buffer.

The dst-pointer will be forward to the end of the written name. That can serve as indication of the name length, given that the original pointer has been saved by the callee.

Todo:
Handle error cases. For that backup the original dst-pointer and remove all data inbetween the old and the new pointer.

Definition at line 1319 of file mdns.c.

References nip_mem_ptr_t::id, NIP_DNS_CLASS_IN, NIP_E_OK, NIP_MDNS_MAX_NAME_DEPTH, NIP_MDNS_WRITE_NAME, nip_mem_insert(), NIP_MEM_NULL, nip_mdns_name::part, and nip_mem_ptr_t::ptr.

Referenced by nip_mdns_disp_check_queries().

Here is the call graph for this function:

Here is the caller graph for this function:

nip_error_t nip_mdns_unregister ( nip_mdns_cache_id_t  id  ) 

Unregister previosly registered DNS record.

Todo:
implement

Definition at line 909 of file mdns.c.

References NIP_E_OK.

Referenced by nip_mdns_register_hostname().

Here is the caller graph for this function:


Variable Documentation

nip_mem_ptr_t nip_mdns_cache = {NIP_MEM_NULL,NULL}

MDNS cache.

Definition at line 50 of file mdns.c.

nip_mem_handle_t nip_mdns_cs = NIP_MEM_NULL

cache subscriptions

Definition at line 49 of file mdns.c.

Referenced by nip_mdns_disp_check_queries(), nip_mdns_init(), and nip_mdns_notify().

nip_mdns_namestring_id_t nip_mdns_domain = NIP_MDNS_NO_NAMESTRING

Definition at line 48 of file mdns.c.

Referenced by nip_mdns_init(), and nip_mdns_register_hostname().

nip_mdns_cache_id_t nip_mdns_host_ptr = NIP_MDNS_NO_CACHE_ID

Definition at line 47 of file mdns.c.

Referenced by nip_mdns_register_hostname().

nip_mdns_cache_id_t nip_mdns_hostname = NIP_MDNS_NO_CACHE_ID

Definition at line 46 of file mdns.c.

Referenced by nip_mdns_init(), and nip_mdns_register_hostname().

MDNS name strings.

Definition at line 51 of file mdns.c.

Referenced by nip_mdns_init(), and nip_mdns_register_name().

nip_mem_ptr_t nip_mdns_queries = {NIP_MEM_NULL,NULL}

MDNS queries.

Definition at line 52 of file mdns.c.

nip_udp_sock_id_t nip_mdns_sock = NIP_UDP_NO_SOCKET


Generated on Thu Jul 10 01:09:59 2008 for NIP by  doxygen 1.5.5