1// Copyright 2018 The Fuchsia Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file.t 4 5#pragma once 6 7#include <stdbool.h> 8 9#include "mdns/mdns.h" 10 11#ifdef __cplusplus 12extern "C" { 13#endif 14 15// Returns 0 iff type is one of the supported RR_TYPE* constants. 16bool is_valid_rr_type(uint16_t type); 17 18// Returns 0 iff type is one of the supported RR_CLASS* constants. 19bool is_valid_rr_class(uint16_t clazz); 20 21// Appends a resource record to the list starting at rrsptr and using the given 22// property values. Returns the number of records in the linked list after 23// insertion. If memory cannot be allocated for the new record, a negative 24// value is returned with errno set to ENOMEM. name is expected to be a NULL 25// terminated string. type and clazz must be one of the RR_TYPE and RR_CLASS 26// constants, respectively. Otherwise, a negative value is returned and errno is 27// set to EINVAL. 28// 29// Returns 0 on success. 30int mdns_add_rr(mdns_rr** rrsptr, 31 char* name, 32 uint16_t type, 33 uint16_t clazz, 34 uint8_t* rdata, 35 uint16_t rdlength, 36 uint32_t ttl); 37 38// Reads an mdns_message header. 39// 40// The header is a 12 byte chunk whose layout is as follows: 41// 42// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 43// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 44// | ID | 45// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 46// | Flags | 47// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 48// | Question Count | 49// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 50// | Answer Count | 51// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 52// | Authorities Count | 53// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 54// | Additionals Count | 55// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 56// 57// See RFC 1035 at https://www.ietf.org/rfc/rfc1035.txt for details on the 58// specific format header flags (bytes 16-31). 59// 60// Assumes the given buffer holds at least MDNS_HEADER_SIZE bytes. 61// 62// Always returns MDNS_HEADER_SIZE as the number of bytes read from buf, to be 63// consistent with the style of other unmarshal* functions. 64int unmarshal_header(const void* buf, mdns_header* container); 65 66#ifdef __cplusplus 67} // extern "C" 68#endif 69